@miller-tech/uap 1.0.0

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 (660) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +888 -0
  3. package/dist/analyzers/index.d.ts +3 -0
  4. package/dist/analyzers/index.d.ts.map +1 -0
  5. package/dist/analyzers/index.js +684 -0
  6. package/dist/analyzers/index.js.map +1 -0
  7. package/dist/benchmarks/agents/naive-agent.d.ts +60 -0
  8. package/dist/benchmarks/agents/naive-agent.d.ts.map +1 -0
  9. package/dist/benchmarks/agents/naive-agent.js +144 -0
  10. package/dist/benchmarks/agents/naive-agent.js.map +1 -0
  11. package/dist/benchmarks/agents/uap-agent.d.ts +167 -0
  12. package/dist/benchmarks/agents/uap-agent.d.ts.map +1 -0
  13. package/dist/benchmarks/agents/uap-agent.js +437 -0
  14. package/dist/benchmarks/agents/uap-agent.js.map +1 -0
  15. package/dist/benchmarks/benchmark.d.ts +328 -0
  16. package/dist/benchmarks/benchmark.d.ts.map +1 -0
  17. package/dist/benchmarks/benchmark.js +112 -0
  18. package/dist/benchmarks/benchmark.js.map +1 -0
  19. package/dist/benchmarks/execution-verifier.d.ts +41 -0
  20. package/dist/benchmarks/execution-verifier.d.ts.map +1 -0
  21. package/dist/benchmarks/execution-verifier.js +340 -0
  22. package/dist/benchmarks/execution-verifier.js.map +1 -0
  23. package/dist/benchmarks/hierarchical-prompting.d.ts +37 -0
  24. package/dist/benchmarks/hierarchical-prompting.d.ts.map +1 -0
  25. package/dist/benchmarks/hierarchical-prompting.js +246 -0
  26. package/dist/benchmarks/hierarchical-prompting.js.map +1 -0
  27. package/dist/benchmarks/improved-benchmark.d.ts +89 -0
  28. package/dist/benchmarks/improved-benchmark.d.ts.map +1 -0
  29. package/dist/benchmarks/improved-benchmark.js +585 -0
  30. package/dist/benchmarks/improved-benchmark.js.map +1 -0
  31. package/dist/benchmarks/index.d.ts +11 -0
  32. package/dist/benchmarks/index.d.ts.map +1 -0
  33. package/dist/benchmarks/index.js +11 -0
  34. package/dist/benchmarks/index.js.map +1 -0
  35. package/dist/benchmarks/model-integration.d.ts +111 -0
  36. package/dist/benchmarks/model-integration.d.ts.map +1 -0
  37. package/dist/benchmarks/model-integration.js +904 -0
  38. package/dist/benchmarks/model-integration.js.map +1 -0
  39. package/dist/benchmarks/multi-turn-agent.d.ts +44 -0
  40. package/dist/benchmarks/multi-turn-agent.d.ts.map +1 -0
  41. package/dist/benchmarks/multi-turn-agent.js +254 -0
  42. package/dist/benchmarks/multi-turn-agent.js.map +1 -0
  43. package/dist/benchmarks/multi-turn-loop.d.ts +57 -0
  44. package/dist/benchmarks/multi-turn-loop.d.ts.map +1 -0
  45. package/dist/benchmarks/multi-turn-loop.js +167 -0
  46. package/dist/benchmarks/multi-turn-loop.js.map +1 -0
  47. package/dist/benchmarks/tasks.d.ts +19 -0
  48. package/dist/benchmarks/tasks.d.ts.map +1 -0
  49. package/dist/benchmarks/tasks.js +435 -0
  50. package/dist/benchmarks/tasks.js.map +1 -0
  51. package/dist/bin/cli.d.ts +3 -0
  52. package/dist/bin/cli.d.ts.map +1 -0
  53. package/dist/bin/cli.js +546 -0
  54. package/dist/bin/cli.js.map +1 -0
  55. package/dist/bin/llama-server-optimize.d.ts +18 -0
  56. package/dist/bin/llama-server-optimize.d.ts.map +1 -0
  57. package/dist/bin/llama-server-optimize.js +708 -0
  58. package/dist/bin/llama-server-optimize.js.map +1 -0
  59. package/dist/bin/policy.d.ts +3 -0
  60. package/dist/bin/policy.d.ts.map +1 -0
  61. package/dist/bin/policy.js +143 -0
  62. package/dist/bin/policy.js.map +1 -0
  63. package/dist/bin/tool-calls.d.ts +3 -0
  64. package/dist/bin/tool-calls.d.ts.map +1 -0
  65. package/dist/bin/tool-calls.js +4 -0
  66. package/dist/bin/tool-calls.js.map +1 -0
  67. package/dist/browser/index.d.ts +2 -0
  68. package/dist/browser/index.d.ts.map +1 -0
  69. package/dist/browser/index.js +2 -0
  70. package/dist/browser/index.js.map +1 -0
  71. package/dist/browser/web-browser.d.ts +30 -0
  72. package/dist/browser/web-browser.d.ts.map +1 -0
  73. package/dist/browser/web-browser.js +93 -0
  74. package/dist/browser/web-browser.js.map +1 -0
  75. package/dist/cli/agent.d.ts +20 -0
  76. package/dist/cli/agent.d.ts.map +1 -0
  77. package/dist/cli/agent.js +474 -0
  78. package/dist/cli/agent.js.map +1 -0
  79. package/dist/cli/analyze.d.ts +7 -0
  80. package/dist/cli/analyze.d.ts.map +1 -0
  81. package/dist/cli/analyze.js +103 -0
  82. package/dist/cli/analyze.js.map +1 -0
  83. package/dist/cli/completion-gates.d.ts +51 -0
  84. package/dist/cli/completion-gates.d.ts.map +1 -0
  85. package/dist/cli/completion-gates.js +201 -0
  86. package/dist/cli/completion-gates.js.map +1 -0
  87. package/dist/cli/compliance.d.ts +8 -0
  88. package/dist/cli/compliance.d.ts.map +1 -0
  89. package/dist/cli/compliance.js +509 -0
  90. package/dist/cli/compliance.js.map +1 -0
  91. package/dist/cli/coord.d.ts +7 -0
  92. package/dist/cli/coord.d.ts.map +1 -0
  93. package/dist/cli/coord.js +138 -0
  94. package/dist/cli/coord.js.map +1 -0
  95. package/dist/cli/dashboard.d.ts +21 -0
  96. package/dist/cli/dashboard.d.ts.map +1 -0
  97. package/dist/cli/dashboard.js +1508 -0
  98. package/dist/cli/dashboard.js.map +1 -0
  99. package/dist/cli/deploy.d.ts +19 -0
  100. package/dist/cli/deploy.d.ts.map +1 -0
  101. package/dist/cli/deploy.js +387 -0
  102. package/dist/cli/deploy.js.map +1 -0
  103. package/dist/cli/droids.d.ts +9 -0
  104. package/dist/cli/droids.d.ts.map +1 -0
  105. package/dist/cli/droids.js +227 -0
  106. package/dist/cli/droids.js.map +1 -0
  107. package/dist/cli/generate.d.ts +17 -0
  108. package/dist/cli/generate.d.ts.map +1 -0
  109. package/dist/cli/generate.js +432 -0
  110. package/dist/cli/generate.js.map +1 -0
  111. package/dist/cli/hooks.d.ts +9 -0
  112. package/dist/cli/hooks.d.ts.map +1 -0
  113. package/dist/cli/hooks.js +464 -0
  114. package/dist/cli/hooks.js.map +1 -0
  115. package/dist/cli/init.d.ts +12 -0
  116. package/dist/cli/init.d.ts.map +1 -0
  117. package/dist/cli/init.js +364 -0
  118. package/dist/cli/init.js.map +1 -0
  119. package/dist/cli/mcp-router.d.ts +16 -0
  120. package/dist/cli/mcp-router.d.ts.map +1 -0
  121. package/dist/cli/mcp-router.js +143 -0
  122. package/dist/cli/mcp-router.js.map +1 -0
  123. package/dist/cli/memory.d.ts +24 -0
  124. package/dist/cli/memory.d.ts.map +1 -0
  125. package/dist/cli/memory.js +885 -0
  126. package/dist/cli/memory.js.map +1 -0
  127. package/dist/cli/model.d.ts +15 -0
  128. package/dist/cli/model.d.ts.map +1 -0
  129. package/dist/cli/model.js +290 -0
  130. package/dist/cli/model.js.map +1 -0
  131. package/dist/cli/patterns.d.ts +26 -0
  132. package/dist/cli/patterns.d.ts.map +1 -0
  133. package/dist/cli/patterns.js +862 -0
  134. package/dist/cli/patterns.js.map +1 -0
  135. package/dist/cli/rtk-validation.d.ts +9 -0
  136. package/dist/cli/rtk-validation.d.ts.map +1 -0
  137. package/dist/cli/rtk-validation.js +9 -0
  138. package/dist/cli/rtk-validation.js.map +1 -0
  139. package/dist/cli/rtk.d.ts +34 -0
  140. package/dist/cli/rtk.d.ts.map +1 -0
  141. package/dist/cli/rtk.js +401 -0
  142. package/dist/cli/rtk.js.map +1 -0
  143. package/dist/cli/schema-diff.d.ts +7 -0
  144. package/dist/cli/schema-diff.d.ts.map +1 -0
  145. package/dist/cli/schema-diff.js +11 -0
  146. package/dist/cli/schema-diff.js.map +1 -0
  147. package/dist/cli/setup-mcp-router.d.ts +8 -0
  148. package/dist/cli/setup-mcp-router.d.ts.map +1 -0
  149. package/dist/cli/setup-mcp-router.js +163 -0
  150. package/dist/cli/setup-mcp-router.js.map +1 -0
  151. package/dist/cli/setup-wizard.d.ts +2 -0
  152. package/dist/cli/setup-wizard.d.ts.map +1 -0
  153. package/dist/cli/setup-wizard.js +806 -0
  154. package/dist/cli/setup-wizard.js.map +1 -0
  155. package/dist/cli/setup.d.ts +15 -0
  156. package/dist/cli/setup.d.ts.map +1 -0
  157. package/dist/cli/setup.js +154 -0
  158. package/dist/cli/setup.js.map +1 -0
  159. package/dist/cli/sync.d.ts +8 -0
  160. package/dist/cli/sync.d.ts.map +1 -0
  161. package/dist/cli/sync.js +395 -0
  162. package/dist/cli/sync.js.map +1 -0
  163. package/dist/cli/task.d.ts +33 -0
  164. package/dist/cli/task.d.ts.map +1 -0
  165. package/dist/cli/task.js +672 -0
  166. package/dist/cli/task.js.map +1 -0
  167. package/dist/cli/tool-calls.d.ts +20 -0
  168. package/dist/cli/tool-calls.d.ts.map +1 -0
  169. package/dist/cli/tool-calls.js +605 -0
  170. package/dist/cli/tool-calls.js.map +1 -0
  171. package/dist/cli/uap.d.ts +10 -0
  172. package/dist/cli/uap.d.ts.map +1 -0
  173. package/dist/cli/uap.js +398 -0
  174. package/dist/cli/uap.js.map +1 -0
  175. package/dist/cli/update.d.ts +10 -0
  176. package/dist/cli/update.d.ts.map +1 -0
  177. package/dist/cli/update.js +300 -0
  178. package/dist/cli/update.js.map +1 -0
  179. package/dist/cli/visualize.d.ts +77 -0
  180. package/dist/cli/visualize.d.ts.map +1 -0
  181. package/dist/cli/visualize.js +287 -0
  182. package/dist/cli/visualize.js.map +1 -0
  183. package/dist/cli/worktree.d.ts +9 -0
  184. package/dist/cli/worktree.d.ts.map +1 -0
  185. package/dist/cli/worktree.js +213 -0
  186. package/dist/cli/worktree.js.map +1 -0
  187. package/dist/coordination/adaptive-patterns.d.ts +65 -0
  188. package/dist/coordination/adaptive-patterns.d.ts.map +1 -0
  189. package/dist/coordination/adaptive-patterns.js +108 -0
  190. package/dist/coordination/adaptive-patterns.js.map +1 -0
  191. package/dist/coordination/auto-agent.d.ts +82 -0
  192. package/dist/coordination/auto-agent.d.ts.map +1 -0
  193. package/dist/coordination/auto-agent.js +145 -0
  194. package/dist/coordination/auto-agent.js.map +1 -0
  195. package/dist/coordination/capability-router.d.ts +79 -0
  196. package/dist/coordination/capability-router.d.ts.map +1 -0
  197. package/dist/coordination/capability-router.js +334 -0
  198. package/dist/coordination/capability-router.js.map +1 -0
  199. package/dist/coordination/database.d.ts +13 -0
  200. package/dist/coordination/database.d.ts.map +1 -0
  201. package/dist/coordination/database.js +136 -0
  202. package/dist/coordination/database.js.map +1 -0
  203. package/dist/coordination/deploy-batcher.d.ts +122 -0
  204. package/dist/coordination/deploy-batcher.d.ts.map +1 -0
  205. package/dist/coordination/deploy-batcher.js +718 -0
  206. package/dist/coordination/deploy-batcher.js.map +1 -0
  207. package/dist/coordination/droid-validator.d.ts +59 -0
  208. package/dist/coordination/droid-validator.d.ts.map +1 -0
  209. package/dist/coordination/droid-validator.js +142 -0
  210. package/dist/coordination/droid-validator.js.map +1 -0
  211. package/dist/coordination/index.d.ts +10 -0
  212. package/dist/coordination/index.d.ts.map +1 -0
  213. package/dist/coordination/index.js +10 -0
  214. package/dist/coordination/index.js.map +1 -0
  215. package/dist/coordination/pattern-router.d.ts +50 -0
  216. package/dist/coordination/pattern-router.d.ts.map +1 -0
  217. package/dist/coordination/pattern-router.js +118 -0
  218. package/dist/coordination/pattern-router.js.map +1 -0
  219. package/dist/coordination/service.d.ts +81 -0
  220. package/dist/coordination/service.d.ts.map +1 -0
  221. package/dist/coordination/service.js +619 -0
  222. package/dist/coordination/service.js.map +1 -0
  223. package/dist/coordination/worktree-enforcer.d.ts +22 -0
  224. package/dist/coordination/worktree-enforcer.d.ts.map +1 -0
  225. package/dist/coordination/worktree-enforcer.js +71 -0
  226. package/dist/coordination/worktree-enforcer.js.map +1 -0
  227. package/dist/generators/claude-md.d.ts +3 -0
  228. package/dist/generators/claude-md.d.ts.map +1 -0
  229. package/dist/generators/claude-md.js +1020 -0
  230. package/dist/generators/claude-md.js.map +1 -0
  231. package/dist/generators/template-loader.d.ts +105 -0
  232. package/dist/generators/template-loader.d.ts.map +1 -0
  233. package/dist/generators/template-loader.js +291 -0
  234. package/dist/generators/template-loader.js.map +1 -0
  235. package/dist/index.d.ts +49 -0
  236. package/dist/index.d.ts.map +1 -0
  237. package/dist/index.js +63 -0
  238. package/dist/index.js.map +1 -0
  239. package/dist/mcp-router/config/parser.d.ts +9 -0
  240. package/dist/mcp-router/config/parser.d.ts.map +1 -0
  241. package/dist/mcp-router/config/parser.js +174 -0
  242. package/dist/mcp-router/config/parser.js.map +1 -0
  243. package/dist/mcp-router/executor/client.d.ts +31 -0
  244. package/dist/mcp-router/executor/client.d.ts.map +1 -0
  245. package/dist/mcp-router/executor/client.js +189 -0
  246. package/dist/mcp-router/executor/client.js.map +1 -0
  247. package/dist/mcp-router/index.d.ts +22 -0
  248. package/dist/mcp-router/index.d.ts.map +1 -0
  249. package/dist/mcp-router/index.js +18 -0
  250. package/dist/mcp-router/index.js.map +1 -0
  251. package/dist/mcp-router/output-compressor.d.ts +26 -0
  252. package/dist/mcp-router/output-compressor.d.ts.map +1 -0
  253. package/dist/mcp-router/output-compressor.js +236 -0
  254. package/dist/mcp-router/output-compressor.js.map +1 -0
  255. package/dist/mcp-router/search/fuzzy.d.ts +26 -0
  256. package/dist/mcp-router/search/fuzzy.d.ts.map +1 -0
  257. package/dist/mcp-router/search/fuzzy.js +94 -0
  258. package/dist/mcp-router/search/fuzzy.js.map +1 -0
  259. package/dist/mcp-router/server.d.ts +50 -0
  260. package/dist/mcp-router/server.d.ts.map +1 -0
  261. package/dist/mcp-router/server.js +229 -0
  262. package/dist/mcp-router/server.js.map +1 -0
  263. package/dist/mcp-router/session-stats.d.ts +37 -0
  264. package/dist/mcp-router/session-stats.d.ts.map +1 -0
  265. package/dist/mcp-router/session-stats.js +56 -0
  266. package/dist/mcp-router/session-stats.js.map +1 -0
  267. package/dist/mcp-router/tools/discover.d.ts +37 -0
  268. package/dist/mcp-router/tools/discover.d.ts.map +1 -0
  269. package/dist/mcp-router/tools/discover.js +65 -0
  270. package/dist/mcp-router/tools/discover.js.map +1 -0
  271. package/dist/mcp-router/tools/execute.d.ts +43 -0
  272. package/dist/mcp-router/tools/execute.d.ts.map +1 -0
  273. package/dist/mcp-router/tools/execute.js +144 -0
  274. package/dist/mcp-router/tools/execute.js.map +1 -0
  275. package/dist/mcp-router/types.d.ts +62 -0
  276. package/dist/mcp-router/types.d.ts.map +1 -0
  277. package/dist/mcp-router/types.js +6 -0
  278. package/dist/mcp-router/types.js.map +1 -0
  279. package/dist/memory/adaptive-context.d.ts +149 -0
  280. package/dist/memory/adaptive-context.d.ts.map +1 -0
  281. package/dist/memory/adaptive-context.js +1095 -0
  282. package/dist/memory/adaptive-context.js.map +1 -0
  283. package/dist/memory/agent-scoped-memory.d.ts +67 -0
  284. package/dist/memory/agent-scoped-memory.d.ts.map +1 -0
  285. package/dist/memory/agent-scoped-memory.js +126 -0
  286. package/dist/memory/agent-scoped-memory.js.map +1 -0
  287. package/dist/memory/ambiguity-detector.d.ts +54 -0
  288. package/dist/memory/ambiguity-detector.d.ts.map +1 -0
  289. package/dist/memory/ambiguity-detector.js +401 -0
  290. package/dist/memory/ambiguity-detector.js.map +1 -0
  291. package/dist/memory/backends/base.d.ts +18 -0
  292. package/dist/memory/backends/base.d.ts.map +1 -0
  293. package/dist/memory/backends/base.js +2 -0
  294. package/dist/memory/backends/base.js.map +1 -0
  295. package/dist/memory/backends/factory.d.ts +4 -0
  296. package/dist/memory/backends/factory.d.ts.map +1 -0
  297. package/dist/memory/backends/factory.js +53 -0
  298. package/dist/memory/backends/factory.js.map +1 -0
  299. package/dist/memory/backends/github.d.ts +27 -0
  300. package/dist/memory/backends/github.d.ts.map +1 -0
  301. package/dist/memory/backends/github.js +134 -0
  302. package/dist/memory/backends/github.js.map +1 -0
  303. package/dist/memory/backends/qdrant-cloud.d.ts +32 -0
  304. package/dist/memory/backends/qdrant-cloud.d.ts.map +1 -0
  305. package/dist/memory/backends/qdrant-cloud.js +167 -0
  306. package/dist/memory/backends/qdrant-cloud.js.map +1 -0
  307. package/dist/memory/context-compressor.d.ts +116 -0
  308. package/dist/memory/context-compressor.d.ts.map +1 -0
  309. package/dist/memory/context-compressor.js +430 -0
  310. package/dist/memory/context-compressor.js.map +1 -0
  311. package/dist/memory/context-pruner.d.ts +55 -0
  312. package/dist/memory/context-pruner.d.ts.map +1 -0
  313. package/dist/memory/context-pruner.js +85 -0
  314. package/dist/memory/context-pruner.js.map +1 -0
  315. package/dist/memory/correction-propagator.d.ts +44 -0
  316. package/dist/memory/correction-propagator.d.ts.map +1 -0
  317. package/dist/memory/correction-propagator.js +156 -0
  318. package/dist/memory/correction-propagator.js.map +1 -0
  319. package/dist/memory/daily-log.d.ts +67 -0
  320. package/dist/memory/daily-log.d.ts.map +1 -0
  321. package/dist/memory/daily-log.js +143 -0
  322. package/dist/memory/daily-log.js.map +1 -0
  323. package/dist/memory/dynamic-retrieval.d.ts +112 -0
  324. package/dist/memory/dynamic-retrieval.d.ts.map +1 -0
  325. package/dist/memory/dynamic-retrieval.js +908 -0
  326. package/dist/memory/dynamic-retrieval.js.map +1 -0
  327. package/dist/memory/embeddings.d.ts +172 -0
  328. package/dist/memory/embeddings.d.ts.map +1 -0
  329. package/dist/memory/embeddings.js +780 -0
  330. package/dist/memory/embeddings.js.map +1 -0
  331. package/dist/memory/generic-uap-patterns.d.ts +7 -0
  332. package/dist/memory/generic-uap-patterns.d.ts.map +1 -0
  333. package/dist/memory/generic-uap-patterns.js +43 -0
  334. package/dist/memory/generic-uap-patterns.js.map +1 -0
  335. package/dist/memory/hierarchical-memory.d.ts +141 -0
  336. package/dist/memory/hierarchical-memory.d.ts.map +1 -0
  337. package/dist/memory/hierarchical-memory.js +485 -0
  338. package/dist/memory/hierarchical-memory.js.map +1 -0
  339. package/dist/memory/knowledge-graph.d.ts +98 -0
  340. package/dist/memory/knowledge-graph.d.ts.map +1 -0
  341. package/dist/memory/knowledge-graph.js +275 -0
  342. package/dist/memory/knowledge-graph.js.map +1 -0
  343. package/dist/memory/memory-consolidator.d.ts +124 -0
  344. package/dist/memory/memory-consolidator.d.ts.map +1 -0
  345. package/dist/memory/memory-consolidator.js +514 -0
  346. package/dist/memory/memory-consolidator.js.map +1 -0
  347. package/dist/memory/memory-maintenance.d.ts +39 -0
  348. package/dist/memory/memory-maintenance.d.ts.map +1 -0
  349. package/dist/memory/memory-maintenance.js +336 -0
  350. package/dist/memory/memory-maintenance.js.map +1 -0
  351. package/dist/memory/model-router.d.ts +105 -0
  352. package/dist/memory/model-router.d.ts.map +1 -0
  353. package/dist/memory/model-router.js +474 -0
  354. package/dist/memory/model-router.js.map +1 -0
  355. package/dist/memory/multi-view-memory.d.ts +134 -0
  356. package/dist/memory/multi-view-memory.d.ts.map +1 -0
  357. package/dist/memory/multi-view-memory.js +430 -0
  358. package/dist/memory/multi-view-memory.js.map +1 -0
  359. package/dist/memory/predictive-memory.d.ts +79 -0
  360. package/dist/memory/predictive-memory.d.ts.map +1 -0
  361. package/dist/memory/predictive-memory.js +294 -0
  362. package/dist/memory/predictive-memory.js.map +1 -0
  363. package/dist/memory/prepopulate.d.ts +76 -0
  364. package/dist/memory/prepopulate.d.ts.map +1 -0
  365. package/dist/memory/prepopulate.js +832 -0
  366. package/dist/memory/prepopulate.js.map +1 -0
  367. package/dist/memory/semantic-compression.d.ts +77 -0
  368. package/dist/memory/semantic-compression.d.ts.map +1 -0
  369. package/dist/memory/semantic-compression.js +359 -0
  370. package/dist/memory/semantic-compression.js.map +1 -0
  371. package/dist/memory/serverless-qdrant.d.ts +102 -0
  372. package/dist/memory/serverless-qdrant.d.ts.map +1 -0
  373. package/dist/memory/serverless-qdrant.js +369 -0
  374. package/dist/memory/serverless-qdrant.js.map +1 -0
  375. package/dist/memory/short-term/factory.d.ts +26 -0
  376. package/dist/memory/short-term/factory.d.ts.map +1 -0
  377. package/dist/memory/short-term/factory.js +28 -0
  378. package/dist/memory/short-term/factory.js.map +1 -0
  379. package/dist/memory/short-term/indexeddb.d.ts +25 -0
  380. package/dist/memory/short-term/indexeddb.d.ts.map +1 -0
  381. package/dist/memory/short-term/indexeddb.js +64 -0
  382. package/dist/memory/short-term/indexeddb.js.map +1 -0
  383. package/dist/memory/short-term/schema.d.ts +6 -0
  384. package/dist/memory/short-term/schema.d.ts.map +1 -0
  385. package/dist/memory/short-term/schema.js +141 -0
  386. package/dist/memory/short-term/schema.js.map +1 -0
  387. package/dist/memory/short-term/sqlite.d.ts +64 -0
  388. package/dist/memory/short-term/sqlite.d.ts.map +1 -0
  389. package/dist/memory/short-term/sqlite.js +274 -0
  390. package/dist/memory/short-term/sqlite.js.map +1 -0
  391. package/dist/memory/speculative-cache.d.ts +111 -0
  392. package/dist/memory/speculative-cache.d.ts.map +1 -0
  393. package/dist/memory/speculative-cache.js +457 -0
  394. package/dist/memory/speculative-cache.js.map +1 -0
  395. package/dist/memory/task-classifier.d.ts +40 -0
  396. package/dist/memory/task-classifier.d.ts.map +1 -0
  397. package/dist/memory/task-classifier.js +342 -0
  398. package/dist/memory/task-classifier.js.map +1 -0
  399. package/dist/memory/terminal-bench-knowledge.d.ts +48 -0
  400. package/dist/memory/terminal-bench-knowledge.d.ts.map +1 -0
  401. package/dist/memory/terminal-bench-knowledge.js +622 -0
  402. package/dist/memory/terminal-bench-knowledge.js.map +1 -0
  403. package/dist/memory/write-gate.d.ts +39 -0
  404. package/dist/memory/write-gate.d.ts.map +1 -0
  405. package/dist/memory/write-gate.js +190 -0
  406. package/dist/memory/write-gate.js.map +1 -0
  407. package/dist/models/api-client.d.ts +46 -0
  408. package/dist/models/api-client.d.ts.map +1 -0
  409. package/dist/models/api-client.js +182 -0
  410. package/dist/models/api-client.js.map +1 -0
  411. package/dist/models/execution-profiles.d.ts +64 -0
  412. package/dist/models/execution-profiles.d.ts.map +1 -0
  413. package/dist/models/execution-profiles.js +403 -0
  414. package/dist/models/execution-profiles.js.map +1 -0
  415. package/dist/models/executor.d.ts +130 -0
  416. package/dist/models/executor.d.ts.map +1 -0
  417. package/dist/models/executor.js +382 -0
  418. package/dist/models/executor.js.map +1 -0
  419. package/dist/models/index.d.ts +19 -0
  420. package/dist/models/index.d.ts.map +1 -0
  421. package/dist/models/index.js +23 -0
  422. package/dist/models/index.js.map +1 -0
  423. package/dist/models/plan-validator.d.ts +37 -0
  424. package/dist/models/plan-validator.d.ts.map +1 -0
  425. package/dist/models/plan-validator.js +179 -0
  426. package/dist/models/plan-validator.js.map +1 -0
  427. package/dist/models/planner.d.ts +73 -0
  428. package/dist/models/planner.d.ts.map +1 -0
  429. package/dist/models/planner.js +375 -0
  430. package/dist/models/planner.js.map +1 -0
  431. package/dist/models/router.d.ts +96 -0
  432. package/dist/models/router.d.ts.map +1 -0
  433. package/dist/models/router.js +523 -0
  434. package/dist/models/router.js.map +1 -0
  435. package/dist/models/types.d.ts +370 -0
  436. package/dist/models/types.d.ts.map +1 -0
  437. package/dist/models/types.js +232 -0
  438. package/dist/models/types.js.map +1 -0
  439. package/dist/models/unified-router.d.ts +152 -0
  440. package/dist/models/unified-router.d.ts.map +1 -0
  441. package/dist/models/unified-router.js +313 -0
  442. package/dist/models/unified-router.js.map +1 -0
  443. package/dist/policies/convert-policy-to-claude.d.ts +3 -0
  444. package/dist/policies/convert-policy-to-claude.d.ts.map +1 -0
  445. package/dist/policies/convert-policy-to-claude.js +87 -0
  446. package/dist/policies/convert-policy-to-claude.js.map +1 -0
  447. package/dist/policies/database-manager.d.ts +27 -0
  448. package/dist/policies/database-manager.d.ts.map +1 -0
  449. package/dist/policies/database-manager.js +198 -0
  450. package/dist/policies/database-manager.js.map +1 -0
  451. package/dist/policies/enforced-tool-router.d.ts +53 -0
  452. package/dist/policies/enforced-tool-router.d.ts.map +1 -0
  453. package/dist/policies/enforced-tool-router.js +80 -0
  454. package/dist/policies/enforced-tool-router.js.map +1 -0
  455. package/dist/policies/index.d.ts +10 -0
  456. package/dist/policies/index.d.ts.map +1 -0
  457. package/dist/policies/index.js +8 -0
  458. package/dist/policies/index.js.map +1 -0
  459. package/dist/policies/policy-gate.d.ts +59 -0
  460. package/dist/policies/policy-gate.d.ts.map +1 -0
  461. package/dist/policies/policy-gate.js +171 -0
  462. package/dist/policies/policy-gate.js.map +1 -0
  463. package/dist/policies/policy-memory.d.ts +18 -0
  464. package/dist/policies/policy-memory.d.ts.map +1 -0
  465. package/dist/policies/policy-memory.js +126 -0
  466. package/dist/policies/policy-memory.js.map +1 -0
  467. package/dist/policies/policy-tools.d.ts +11 -0
  468. package/dist/policies/policy-tools.d.ts.map +1 -0
  469. package/dist/policies/policy-tools.js +66 -0
  470. package/dist/policies/policy-tools.js.map +1 -0
  471. package/dist/policies/schemas/policy.d.ts +69 -0
  472. package/dist/policies/schemas/policy.d.ts.map +1 -0
  473. package/dist/policies/schemas/policy.js +31 -0
  474. package/dist/policies/schemas/policy.js.map +1 -0
  475. package/dist/tasks/coordination.d.ts +83 -0
  476. package/dist/tasks/coordination.d.ts.map +1 -0
  477. package/dist/tasks/coordination.js +291 -0
  478. package/dist/tasks/coordination.js.map +1 -0
  479. package/dist/tasks/database.d.ts +19 -0
  480. package/dist/tasks/database.d.ts.map +1 -0
  481. package/dist/tasks/database.js +149 -0
  482. package/dist/tasks/database.js.map +1 -0
  483. package/dist/tasks/decoder-gate.d.ts +64 -0
  484. package/dist/tasks/decoder-gate.d.ts.map +1 -0
  485. package/dist/tasks/decoder-gate.js +268 -0
  486. package/dist/tasks/decoder-gate.js.map +1 -0
  487. package/dist/tasks/index.d.ts +6 -0
  488. package/dist/tasks/index.d.ts.map +1 -0
  489. package/dist/tasks/index.js +6 -0
  490. package/dist/tasks/index.js.map +1 -0
  491. package/dist/tasks/service.d.ts +40 -0
  492. package/dist/tasks/service.d.ts.map +1 -0
  493. package/dist/tasks/service.js +671 -0
  494. package/dist/tasks/service.js.map +1 -0
  495. package/dist/tasks/types.d.ts +238 -0
  496. package/dist/tasks/types.d.ts.map +1 -0
  497. package/dist/tasks/types.js +74 -0
  498. package/dist/tasks/types.js.map +1 -0
  499. package/dist/telemetry/index.d.ts +2 -0
  500. package/dist/telemetry/index.d.ts.map +1 -0
  501. package/dist/telemetry/index.js +2 -0
  502. package/dist/telemetry/index.js.map +1 -0
  503. package/dist/telemetry/session-telemetry.d.ts +56 -0
  504. package/dist/telemetry/session-telemetry.d.ts.map +1 -0
  505. package/dist/telemetry/session-telemetry.js +807 -0
  506. package/dist/telemetry/session-telemetry.js.map +1 -0
  507. package/dist/types/analysis.d.ts +82 -0
  508. package/dist/types/analysis.d.ts.map +1 -0
  509. package/dist/types/analysis.js +2 -0
  510. package/dist/types/analysis.js.map +1 -0
  511. package/dist/types/config.d.ts +3324 -0
  512. package/dist/types/config.d.ts.map +1 -0
  513. package/dist/types/config.js +418 -0
  514. package/dist/types/config.js.map +1 -0
  515. package/dist/types/coordination.d.ts +240 -0
  516. package/dist/types/coordination.d.ts.map +1 -0
  517. package/dist/types/coordination.js +43 -0
  518. package/dist/types/coordination.js.map +1 -0
  519. package/dist/types/index.d.ts +4 -0
  520. package/dist/types/index.d.ts.map +1 -0
  521. package/dist/types/index.js +4 -0
  522. package/dist/types/index.js.map +1 -0
  523. package/dist/uap-droids-strict.d.ts +59 -0
  524. package/dist/uap-droids-strict.d.ts.map +1 -0
  525. package/dist/uap-droids-strict.js +200 -0
  526. package/dist/uap-droids-strict.js.map +1 -0
  527. package/dist/utils/config-manager.d.ts +30 -0
  528. package/dist/utils/config-manager.d.ts.map +1 -0
  529. package/dist/utils/config-manager.js +41 -0
  530. package/dist/utils/config-manager.js.map +1 -0
  531. package/dist/utils/fetch-with-retry.d.ts +5 -0
  532. package/dist/utils/fetch-with-retry.d.ts.map +1 -0
  533. package/dist/utils/fetch-with-retry.js +61 -0
  534. package/dist/utils/fetch-with-retry.js.map +1 -0
  535. package/dist/utils/merge-claude-md.d.ts +28 -0
  536. package/dist/utils/merge-claude-md.d.ts.map +1 -0
  537. package/dist/utils/merge-claude-md.js +342 -0
  538. package/dist/utils/merge-claude-md.js.map +1 -0
  539. package/dist/utils/rate-limiter.d.ts +58 -0
  540. package/dist/utils/rate-limiter.d.ts.map +1 -0
  541. package/dist/utils/rate-limiter.js +100 -0
  542. package/dist/utils/rate-limiter.js.map +1 -0
  543. package/dist/utils/string-similarity.d.ts +37 -0
  544. package/dist/utils/string-similarity.d.ts.map +1 -0
  545. package/dist/utils/string-similarity.js +114 -0
  546. package/dist/utils/string-similarity.js.map +1 -0
  547. package/dist/utils/validate-json.d.ts +51 -0
  548. package/dist/utils/validate-json.d.ts.map +1 -0
  549. package/dist/utils/validate-json.js +94 -0
  550. package/dist/utils/validate-json.js.map +1 -0
  551. package/docs/INDEX.md +66 -0
  552. package/docs/architecture/MULTI_MODEL.md +224 -0
  553. package/docs/architecture/SYSTEM_ANALYSIS.md +1117 -0
  554. package/docs/architecture/UAP_COMPLIANCE.md +217 -0
  555. package/docs/architecture/UAP_PROTOCOL.md +339 -0
  556. package/docs/architecture/UAP_STRICT_DROIDS.md +172 -0
  557. package/docs/archive/BALLS_MODE_SELF_ANALYSIS.md +260 -0
  558. package/docs/archive/FAILING_TASKS_SOLUTION_PLAN.md +668 -0
  559. package/docs/archive/JINJA2-SYSTEM-MESSAGE-FIX.md +209 -0
  560. package/docs/archive/NPM-PUBLISH-V0.9.1.md +240 -0
  561. package/docs/archive/OPTIMIZATION_OPTIONS.md +334 -0
  562. package/docs/archive/SETUP_IMPROVEMENTS.md +213 -0
  563. package/docs/archive/UAP_GENERIC_OPTIMIZATION_PLAN.md +270 -0
  564. package/docs/archive/UAP_V103_PATTERN_DESIGN.md +315 -0
  565. package/docs/archive/UAP_V104_COMPLIANCE_DESIGN.md +223 -0
  566. package/docs/archive/changelog/2026-03-10_uap-100-compliance.md +77 -0
  567. package/docs/archive/changelog/2026-03-10_uap-full-system-verification.md +109 -0
  568. package/docs/benchmarks/ACCURACY_ANALYSIS.md +471 -0
  569. package/docs/benchmarks/TOKEN_OPTIMIZATION.md +572 -0
  570. package/docs/benchmarks/VALIDATION_PLAN.md +568 -0
  571. package/docs/benchmarks/VALIDATION_RESULTS.md +161 -0
  572. package/docs/deployment/DEPLOYMENT.md +895 -0
  573. package/docs/deployment/DEPLOYMENT_STRATEGIES.md +518 -0
  574. package/docs/deployment/DEPLOY_BATCHER_ANALYSIS.md +856 -0
  575. package/docs/deployment/DEPLOY_BATCHING.md +273 -0
  576. package/docs/deployment/DEPLOY_BUCKETING_ANALYSIS.md +420 -0
  577. package/docs/deployment/QWEN35_LLAMA_CPP.md +265 -0
  578. package/docs/getting-started/INTEGRATION.md +449 -0
  579. package/docs/getting-started/OVERVIEW.md +344 -0
  580. package/docs/getting-started/SETUP.md +203 -0
  581. package/docs/integrations/MCP_ROUTER_SETUP.md +445 -0
  582. package/docs/integrations/RTK_INTEGRATION.md +468 -0
  583. package/docs/operations/TROUBLESHOOTING.md +660 -0
  584. package/docs/reference/API_REFERENCE.md +903 -0
  585. package/docs/reference/FEATURES.md +472 -0
  586. package/docs/reference/HARNESS-MATRIX.md +318 -0
  587. package/docs/reference/UAP_CLI_REFERENCE.md +600 -0
  588. package/docs/research/BEHAVIORAL_PATTERNS.md +228 -0
  589. package/docs/research/DOMAIN_STRATEGIES.md +316 -0
  590. package/docs/research/MEMORY_SYSTEMS_COMPARISON.md +812 -0
  591. package/docs/research/PATTERN_ANALYSIS_2026-01-18.md +436 -0
  592. package/docs/research/PERFORMANCE_ANALYSIS_2026-01-18.md +209 -0
  593. package/docs/research/PERFORMANCE_TEST_PLAN.md +383 -0
  594. package/docs/research/TERMINAL_BENCH_LEARNINGS.md +217 -0
  595. package/package.json +113 -0
  596. package/scripts/README.md +161 -0
  597. package/templates/CLAUDE.template.md +10 -0
  598. package/templates/CLAUDE_ARCHITECTURE.template.md +103 -0
  599. package/templates/CLAUDE_CODING.template.md +127 -0
  600. package/templates/CLAUDE_DROIDS.template.md +109 -0
  601. package/templates/CLAUDE_MEMORY.template.md +131 -0
  602. package/templates/CLAUDE_WORKFLOWS.template.md +139 -0
  603. package/templates/PROJECT.template.md +209 -0
  604. package/templates/SCHEMA.md +57 -0
  605. package/templates/archive/CLAUDE.template.root-v6.md +534 -0
  606. package/templates/archive/CLAUDE.template.v6.md +534 -0
  607. package/templates/hooks/forgecode/pre-compact.sh +68 -0
  608. package/templates/hooks/forgecode/session-start.sh +169 -0
  609. package/templates/hooks/forgecode.plugin.sh +128 -0
  610. package/templates/hooks/pre-compact.sh +74 -0
  611. package/templates/hooks/session-start.sh +366 -0
  612. package/tools/agents/README.md +224 -0
  613. package/tools/agents/UAP/README.md +386 -0
  614. package/tools/agents/UAP/__init__.py +9 -0
  615. package/tools/agents/UAP/cli.py +901 -0
  616. package/tools/agents/UAP/compliance_verify.sh +108 -0
  617. package/tools/agents/UAP/full_verification.sh +126 -0
  618. package/tools/agents/UAP/version.py +32 -0
  619. package/tools/agents/benchmarks/benchmark_memory_systems.py +730 -0
  620. package/tools/agents/benchmarks/results/benchmark_20260106_064817.json +170 -0
  621. package/tools/agents/benchmarks/results/benchmark_20260106_064817.md +51 -0
  622. package/tools/agents/config/chat_template.jinja +77 -0
  623. package/tools/agents/config/tool-call-schema.json +19 -0
  624. package/tools/agents/config/tool-call.gbnf +58 -0
  625. package/tools/agents/docker/Dockerfile.python +52 -0
  626. package/tools/agents/docker/Dockerfile.ubuntu +55 -0
  627. package/tools/agents/docker-compose.qdrant.yml +24 -0
  628. package/tools/agents/install-opencode-local.sh.j2 +135 -0
  629. package/tools/agents/migrations/apply.py +256 -0
  630. package/tools/agents/opencode_uap_agent.py +1505 -0
  631. package/tools/agents/plugin/README.md +91 -0
  632. package/tools/agents/plugin/index.ts +46 -0
  633. package/tools/agents/plugin/pre-compact.sh +68 -0
  634. package/tools/agents/plugin/session-start.sh +175 -0
  635. package/tools/agents/plugin/uap-commands.ts +45 -0
  636. package/tools/agents/plugin/uap-droids.ts +54 -0
  637. package/tools/agents/plugin/uap-patterns.ts +54 -0
  638. package/tools/agents/plugin/uap-skills.ts +52 -0
  639. package/tools/agents/plugins/uap-enforce.ts +314 -0
  640. package/tools/agents/scripts/__pycache__/tool_call_wrapper.cpython-313.pyc +0 -0
  641. package/tools/agents/scripts/chat_template_verifier.py +343 -0
  642. package/tools/agents/scripts/fix-qwen-template.js +38 -0
  643. package/tools/agents/scripts/fix_qwen_chat_template.py +316 -0
  644. package/tools/agents/scripts/generate_lora_training_data.py +412 -0
  645. package/tools/agents/scripts/init_qdrant.py +151 -0
  646. package/tools/agents/scripts/memory_migration.py +560 -0
  647. package/tools/agents/scripts/migrate_memory_to_qdrant.py +110 -0
  648. package/tools/agents/scripts/prepare_lora.sh +512 -0
  649. package/tools/agents/scripts/query_memory.py +200 -0
  650. package/tools/agents/scripts/qwen-tool-call-test.js +38 -0
  651. package/tools/agents/scripts/qwen-tool-call-wrapper.js +38 -0
  652. package/tools/agents/scripts/qwen_tool_call_test.py +464 -0
  653. package/tools/agents/scripts/qwen_tool_call_wrapper.py +686 -0
  654. package/tools/agents/scripts/start-services.sh +96 -0
  655. package/tools/agents/scripts/tool-choice-proxy.cjs +296 -0
  656. package/tools/agents/scripts/tool_call_test.py +656 -0
  657. package/tools/agents/scripts/tool_call_wrapper.py +799 -0
  658. package/tools/agents/tests/test_uap_compliance.py +257 -0
  659. package/tools/agents/uap_agent.py +122 -0
  660. package/tools/agents/uap_agent_install.sh +12 -0
@@ -0,0 +1,1020 @@
1
+ import Handlebars from 'handlebars';
2
+ import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
3
+ import { join, dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { prepopulateMemory } from '../memory/prepopulate.js';
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+ export async function generateClaudeMd(analysis, config) {
9
+ // Determine platform mode
10
+ const hasWebDatabase = !!config.memory?.shortTerm?.webDatabase;
11
+ const forceDesktop = config.memory?.shortTerm?.forceDesktop;
12
+ const isWebPlatform = hasWebDatabase && !forceDesktop;
13
+ // Use appropriate template
14
+ const template = isWebPlatform ? getWebTemplate() : getDesktopTemplate();
15
+ // Register PROJECT partial if PROJECT.md exists
16
+ const projectContent = getProjectTemplate();
17
+ if (projectContent) {
18
+ Handlebars.registerPartial('PROJECT', projectContent);
19
+ }
20
+ const compiled = Handlebars.compile(template);
21
+ // Build comprehensive context from analysis + auto-population
22
+ const context = await buildContext(analysis, config);
23
+ return compiled(context);
24
+ }
25
+ /**
26
+ * Get project-specific template content.
27
+ *
28
+ * PROJECT.md contains all project-specific configuration, making template
29
+ * upgrades seamless - no merge conflicts between universal patterns and
30
+ * project-specific content.
31
+ *
32
+ * Search order:
33
+ * 1. .factory/PROJECT.md (preferred location)
34
+ * 2. templates/PROJECT.md (fallback)
35
+ * 3. PROJECT.md (root fallback)
36
+ */
37
+ function getProjectTemplate() {
38
+ const cwd = process.cwd();
39
+ const locations = [
40
+ join(cwd, '.factory/PROJECT.md'), // Preferred: Factory config dir
41
+ join(cwd, 'templates/PROJECT.md'), // Fallback: templates dir
42
+ join(cwd, 'templates/PROJECT.template.md'), // Template version
43
+ join(cwd, 'PROJECT.md'), // Root fallback
44
+ ];
45
+ for (const path of locations) {
46
+ if (existsSync(path)) {
47
+ try {
48
+ return readFileSync(path, 'utf-8');
49
+ }
50
+ catch (e) {
51
+ console.warn(`Warning: Found PROJECT.md at ${path} but couldn't read it: ${e}`);
52
+ }
53
+ }
54
+ }
55
+ return null;
56
+ }
57
+ async function buildContext(analysis, config) {
58
+ const cwd = process.cwd();
59
+ // Detect web vs desktop
60
+ const hasWebDatabase = !!config.memory?.shortTerm?.webDatabase;
61
+ const forceDesktop = config.memory?.shortTerm?.forceDesktop;
62
+ const isWebPlatform = hasWebDatabase && !forceDesktop;
63
+ // Long-term memory config
64
+ let longTermBackend = 'Qdrant';
65
+ let longTermEndpoint = config.memory?.longTerm?.endpoint || 'localhost:6333';
66
+ const longTermCollection = config.memory?.longTerm?.collection || 'agent_memory';
67
+ if (config.memory?.longTerm?.provider === 'github') {
68
+ longTermBackend = 'GitHub';
69
+ longTermEndpoint = `${config.memory?.longTerm?.github?.repo || 'owner/repo'}/${config.memory?.longTerm?.github?.path || '.uap/memory'}`;
70
+ }
71
+ else if (config.memory?.longTerm?.provider === 'qdrant-cloud') {
72
+ longTermBackend = 'Qdrant Cloud';
73
+ longTermEndpoint =
74
+ config.memory?.longTerm?.qdrantCloud?.url || 'https://xxxxxx.aws.cloud.qdrant.io:6333';
75
+ }
76
+ // Prepopulate memory from project
77
+ let prepopulated = null;
78
+ try {
79
+ prepopulated = await prepopulateMemory(cwd, {
80
+ docs: true,
81
+ git: true,
82
+ skills: true,
83
+ limit: 200,
84
+ });
85
+ }
86
+ catch (e) {
87
+ console.warn('Failed to prepopulate memory:', e);
88
+ }
89
+ // Build repository structure
90
+ const repoStructure = buildRepositoryStructure(cwd, analysis);
91
+ // Discover skills, droids, commands
92
+ const discoveredSkills = prepopulated?.skills || [];
93
+ const skills = discoveredSkills.filter((s) => s.type === 'skill');
94
+ const droids = discoveredSkills.filter((s) => s.type === 'droid');
95
+ // Commands discovered from prepopulate (unused currently but kept for reference)
96
+ // const commands = discoveredSkills.filter(s => s.type === 'command');
97
+ // Build skill mappings table
98
+ const skillMappings = buildSkillMappings(skills);
99
+ // Build language droids table
100
+ const languageDroids = buildLanguageDroidsTable(droids, analysis.languages);
101
+ // Build file type routing
102
+ const fileTypeRouting = buildFileTypeRouting(analysis.languages);
103
+ // Build discovered skills table
104
+ const discoveredSkillsTable = buildDiscoveredSkillsTable(skills);
105
+ // Extract troubleshooting from git history
106
+ const troubleshooting = buildTroubleshootingSection(prepopulated?.longTerm || []);
107
+ // Build architecture overview
108
+ const architectureOverview = buildArchitectureOverview(analysis);
109
+ // Build core components section
110
+ const coreComponents = buildCoreComponentsSection(analysis);
111
+ // Build key config files
112
+ const keyConfigFiles = buildKeyConfigFiles(analysis);
113
+ // Build essential commands
114
+ const essentialCommands = buildEssentialCommands(analysis);
115
+ // Build prepopulated knowledge section
116
+ const prepopulatedKnowledge = buildPrepopulatedKnowledge(prepopulated);
117
+ // Build cluster contexts
118
+ const clusterContexts = buildClusterContexts(analysis);
119
+ // Build project URLs
120
+ const projectUrls = buildProjectUrls(analysis);
121
+ // Build key workflows
122
+ const keyWorkflows = buildKeyWorkflows(analysis);
123
+ // Build infrastructure workflow
124
+ const infraWorkflow = buildInfraWorkflow(analysis);
125
+ // Build MCP plugins
126
+ const mcpPlugins = buildMcpPlugins(cwd);
127
+ // Build primary skills for decision loop
128
+ const primarySkills = buildPrimarySkills(skills);
129
+ // Build language examples
130
+ const languageExamples = buildLanguageExamples(analysis.languages);
131
+ // Build relevant patterns (pruned by project type to save tokens)
132
+ const relevantPatterns = buildRelevantPatterns(analysis);
133
+ // Template version for reproducibility
134
+ const TEMPLATE_VERSION = '10.16-opt';
135
+ return {
136
+ // Project basics
137
+ PROJECT_NAME: analysis.projectName || config.project.name,
138
+ DESCRIPTION: analysis.description || config.project.description || '',
139
+ DEFAULT_BRANCH: analysis.defaultBranch || config.project.defaultBranch || 'main',
140
+ TEMPLATE_VERSION,
141
+ // Issue tracker
142
+ ISSUE_TRACKER: analysis.issueTracker
143
+ ? `Use [${analysis.issueTracker.name}](${analysis.issueTracker.url || '#'}) for issue tracking.`
144
+ : null,
145
+ // Memory config
146
+ MEMORY_DB_PATH: config.memory?.shortTerm?.path || 'agents/data/memory/short_term.db',
147
+ MEMORY_QUERY_CMD: 'uap memory query',
148
+ MEMORY_STORE_CMD: 'uap memory store',
149
+ MEMORY_START_CMD: 'uap memory start',
150
+ MEMORY_STATUS_CMD: 'uap memory status',
151
+ MEMORY_STOP_CMD: 'uap memory stop',
152
+ SHORT_TERM_LIMIT: config.memory?.shortTerm?.maxEntries || 50,
153
+ LONG_TERM_BACKEND: longTermBackend,
154
+ LONG_TERM_ENDPOINT: longTermEndpoint,
155
+ LONG_TERM_COLLECTION: longTermCollection,
156
+ SCREENSHOTS_PATH: 'agents/data/screenshots',
157
+ DOCKER_COMPOSE_PATH: existsSync(join(cwd, 'agents/docker-compose.yml'))
158
+ ? 'agents/docker-compose.yml'
159
+ : existsSync(join(cwd, 'docker-compose.yml'))
160
+ ? 'docker-compose.yml'
161
+ : null,
162
+ // Worktree config
163
+ WORKTREE_DIR: config.worktrees?.directory || '.worktrees',
164
+ WORKTREE_CREATE_CMD: 'uap worktree create',
165
+ WORKTREE_PR_CMD: 'uap worktree pr',
166
+ WORKTREE_CLEANUP_CMD: 'uap worktree cleanup',
167
+ WORKTREE_APPLIES_TO: 'Application code, configs, workflows, documentation, CLAUDE.md itself',
168
+ BRANCH_PREFIX: config.worktrees?.branchPrefix || 'feature/',
169
+ // Paths
170
+ SKILLS_PATH: '.factory/skills/',
171
+ DROIDS_PATH: '.factory/droids/',
172
+ COMMANDS_PATH: '.factory/commands/',
173
+ DOCS_PATH: analysis.directories.docs[0] || 'docs',
174
+ FIXES_PATH: existsSync(join(cwd, 'docs/fixes')) ? 'docs/fixes/' : null,
175
+ CHANGELOG_PATH: existsSync(join(cwd, 'docs/changelog')) ? 'docs/changelog' : null,
176
+ CHANGELOG_TEMPLATE: existsSync(join(cwd, 'docs/changelog/CHANGELOG_TEMPLATE.md'))
177
+ ? 'docs/changelog/CHANGELOG_TEMPLATE.md'
178
+ : null,
179
+ WORKFLOW_DOCS_PATH: existsSync(join(cwd, 'docs/workflows/GIT_WORKTREE_WORKFLOW.md'))
180
+ ? 'docs/workflows/GIT_WORKTREE_WORKFLOW.md'
181
+ : null,
182
+ // Commands
183
+ TEST_COMMAND: analysis.commands.test || 'npm test',
184
+ LINT_COMMAND: analysis.commands.lint || 'npm run lint',
185
+ BUILD_COMMAND: analysis.commands.build || 'npm run build',
186
+ HOOKS_INSTALL_CMD: existsSync(join(cwd, '.factory/scripts/install-hooks.sh'))
187
+ ? '.factory/scripts/install-hooks.sh'
188
+ : null,
189
+ // Skills and droids
190
+ PRIMARY_SKILLS: primarySkills,
191
+ SKILL_MAPPINGS: skillMappings,
192
+ DISCOVERED_SKILLS: discoveredSkillsTable,
193
+ LANGUAGE_DROIDS: languageDroids,
194
+ LANGUAGE_EXAMPLES: languageExamples,
195
+ FILE_TYPE_ROUTING: fileTypeRouting,
196
+ // Repository structure (support both old @REPOSITORY_STRUCTURE and new REPOSITORY_STRUCTURE)
197
+ '@REPOSITORY_STRUCTURE': repoStructure,
198
+ REPOSITORY_STRUCTURE: repoStructure,
199
+ STRUCTURE_DATE: new Date().toLocaleString('en-US', { month: 'long', year: 'numeric' }),
200
+ // Path migrations (if detected from git history)
201
+ PATH_MIGRATIONS: null,
202
+ // Clusters and URLs
203
+ CLUSTER_CONTEXTS: clusterContexts,
204
+ PROJECT_URLS: projectUrls,
205
+ KEY_WORKFLOWS: keyWorkflows,
206
+ ESSENTIAL_COMMANDS: essentialCommands,
207
+ // Architecture
208
+ ARCHITECTURE_OVERVIEW: architectureOverview,
209
+ DATABASE_ARCHITECTURE: analysis.databases.length > 0 ? buildDatabaseArchitecture(analysis) : null,
210
+ // Core components
211
+ CORE_COMPONENTS: coreComponents,
212
+ // Auth flow
213
+ AUTH_FLOW: analysis.authentication ? buildAuthFlow(analysis) : null,
214
+ // Gateway knowledge
215
+ GATEWAY_KNOWLEDGE: null, // Project-specific, detected from k8s/istio files
216
+ // Multi-environment
217
+ MULTI_ENV_CONFIG: null, // Project-specific
218
+ // Infrastructure
219
+ HAS_INFRA: analysis.directories.infrastructure.length > 0 || config.template?.sections?.pipelineOnly,
220
+ HAS_PIPELINE_POLICY: config.template?.sections?.pipelineOnly || false,
221
+ INFRA_WORKFLOW: infraWorkflow,
222
+ CLUSTER_IDENTIFY: analysis.clusters?.enabled ? 'Identify which cluster(s) affected' : null,
223
+ // Troubleshooting
224
+ TROUBLESHOOTING: troubleshooting,
225
+ // Key config files
226
+ KEY_CONFIG_FILES: keyConfigFiles,
227
+ // MCP plugins
228
+ MCP_PLUGINS: mcpPlugins,
229
+ // Prepopulated knowledge
230
+ PREPOPULATED_KNOWLEDGE: prepopulatedKnowledge ? true : null,
231
+ RECENT_ACTIVITY: prepopulatedKnowledge?.recentActivity || null,
232
+ LEARNED_LESSONS: prepopulatedKnowledge?.learnedLessons || null,
233
+ KNOWN_GOTCHAS: prepopulatedKnowledge?.knownGotchas || null,
234
+ HOT_SPOTS: prepopulatedKnowledge?.hotSpots || null,
235
+ // Platform detection
236
+ IS_WEB_PLATFORM: isWebPlatform,
237
+ IS_DESKTOP_PLATFORM: !isWebPlatform,
238
+ // Benchmark mode detection (#34) - conditional domain knowledge
239
+ // Enable for terminal-bench tasks to include domain-specific patterns
240
+ // Disable for production to save ~300 tokens
241
+ IS_BENCHMARK: config.template?.sections?.benchmark ||
242
+ existsSync(join(cwd, '.tbench')) ||
243
+ existsSync(join(cwd, 'verifier.sh')) ||
244
+ process.env.UAP_BENCHMARK_MODE === 'true',
245
+ // PROJECT.md separation support
246
+ HAS_PROJECT_MD: existsSync(join(cwd, '.factory/PROJECT.md')) ||
247
+ existsSync(join(cwd, 'templates/PROJECT.md')) ||
248
+ existsSync(join(cwd, 'PROJECT.md')),
249
+ // Relevant patterns (pruned by project type to save ~800 tokens)
250
+ RELEVANT_PATTERNS: relevantPatterns,
251
+ };
252
+ }
253
+ function buildRepositoryStructure(cwd, analysis) {
254
+ const lines = [];
255
+ const visited = new Set();
256
+ // Standard directories to look for
257
+ const standardDirs = [
258
+ { path: 'apps', comment: 'Deployable applications' },
259
+ { path: 'services', comment: 'Backend microservices' },
260
+ { path: 'packages', comment: 'Shared packages' },
261
+ { path: 'libs', comment: 'Shared libraries' },
262
+ { path: 'src', comment: 'Source code' },
263
+ { path: 'infra', comment: 'Infrastructure as Code' },
264
+ { path: 'infrastructure', comment: 'Infrastructure as Code' },
265
+ { path: 'terraform', comment: 'Terraform configurations' },
266
+ { path: 'k8s', comment: 'Kubernetes manifests' },
267
+ { path: 'helm', comment: 'Helm charts' },
268
+ { path: 'tools', comment: 'Development tools' },
269
+ { path: 'scripts', comment: 'Automation scripts' },
270
+ { path: 'tests', comment: 'Test suites' },
271
+ { path: 'test', comment: 'Test suites' },
272
+ { path: 'docs', comment: 'Documentation' },
273
+ { path: '.factory', comment: 'Factory AI configuration' },
274
+ { path: '.github', comment: 'GitHub configuration' },
275
+ { path: '.gitlab', comment: 'GitLab configuration' },
276
+ ];
277
+ for (const { path, comment } of standardDirs) {
278
+ const fullPath = join(cwd, path);
279
+ if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
280
+ visited.add(path);
281
+ lines.push(`├── ${path}/`.padEnd(35) + `# ${comment}`);
282
+ // List subdirectories
283
+ try {
284
+ const subdirs = readdirSync(fullPath, { withFileTypes: true })
285
+ .filter((d) => d.isDirectory() && !d.name.startsWith('.'))
286
+ .slice(0, 8);
287
+ for (let i = 0; i < subdirs.length; i++) {
288
+ const prefix = i === subdirs.length - 1 ? '│ └── ' : '│ ├── ';
289
+ const subComment = getSubdirComment(path, subdirs[i].name, join(fullPath, subdirs[i].name));
290
+ lines.push(`${prefix}${subdirs[i].name}/`.padEnd(35) + (subComment ? `# ${subComment}` : ''));
291
+ }
292
+ }
293
+ catch {
294
+ // Ignore permission errors
295
+ }
296
+ lines.push('│');
297
+ }
298
+ }
299
+ // Add component directories from analysis
300
+ for (const comp of analysis.components) {
301
+ const dirPath = comp.path.split('/')[0];
302
+ if (!visited.has(dirPath) && existsSync(join(cwd, dirPath))) {
303
+ visited.add(dirPath);
304
+ lines.push(`├── ${dirPath}/`.padEnd(35) + `# ${comp.description || comp.name}`);
305
+ }
306
+ }
307
+ // Remove trailing separator
308
+ if (lines.length > 0 && lines[lines.length - 1] === '│') {
309
+ lines.pop();
310
+ }
311
+ return lines.join('\n');
312
+ }
313
+ function getSubdirComment(parentDir, subdir, fullPath) {
314
+ // Check for package.json, README, etc. to get description
315
+ const packageJsonPath = join(fullPath, 'package.json');
316
+ if (existsSync(packageJsonPath)) {
317
+ try {
318
+ const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
319
+ if (pkg.description)
320
+ return pkg.description.slice(0, 40);
321
+ }
322
+ catch {
323
+ // Ignore
324
+ }
325
+ }
326
+ // Default comments based on common patterns
327
+ const patterns = {
328
+ apps: {
329
+ api: 'REST API',
330
+ web: 'Web frontend',
331
+ mobile: 'Mobile app',
332
+ admin: 'Admin dashboard',
333
+ cms: 'CMS',
334
+ },
335
+ services: {
336
+ auth: 'Authentication service',
337
+ gateway: 'API Gateway',
338
+ },
339
+ '.factory': {
340
+ droids: 'Custom AI agents',
341
+ skills: 'Reusable skills',
342
+ commands: 'CLI commands',
343
+ scripts: 'Automation scripts',
344
+ },
345
+ '.github': {
346
+ workflows: 'CI/CD pipelines',
347
+ },
348
+ };
349
+ return patterns[parentDir]?.[subdir] || '';
350
+ }
351
+ function buildSkillMappings(skills) {
352
+ if (skills.length === 0)
353
+ return null;
354
+ const lines = [];
355
+ for (const skill of skills) {
356
+ if (skill.name.includes('design') || skill.name.includes('ui')) {
357
+ lines.push(`| UI/Design work (buttons, modals, colors, layouts) | \`${skill.name}\` |`);
358
+ }
359
+ else if (skill.name.includes('frontend') || skill.name.includes('react')) {
360
+ lines.push(`| React/TypeScript/Frontend | \`${skill.name}\` |`);
361
+ }
362
+ else if (skill.name.includes('backend') || skill.name.includes('api')) {
363
+ lines.push(`| Backend/API development | \`${skill.name}\` |`);
364
+ }
365
+ }
366
+ return lines.length > 0 ? lines.join('\n') : null;
367
+ }
368
+ function buildLanguageDroidsTable(droids, languages) {
369
+ const languageDroids = droids.filter((d) => d.name.includes('-pro') ||
370
+ d.name.includes('specialist') ||
371
+ languages.some((l) => d.name.toLowerCase().includes(l.toLowerCase())));
372
+ if (languageDroids.length === 0 && languages.length > 0) {
373
+ // Generate suggested droids based on detected languages
374
+ const suggestions = [];
375
+ for (const lang of languages.slice(0, 5)) {
376
+ const langLower = lang.toLowerCase();
377
+ if (langLower.includes('typescript') || langLower.includes('javascript')) {
378
+ suggestions.push('| `javascript-pro` | ES6+, async patterns, Node.js, promises, event loops |');
379
+ }
380
+ else if (langLower.includes('python')) {
381
+ suggestions.push('| `python-pro` | Async/await, decorators, generators, pytest, type hints |');
382
+ }
383
+ else if (langLower.includes('c++') || langLower.includes('cpp')) {
384
+ suggestions.push('| `cpp-pro` | C++20 with RAII, smart pointers, STL, templates, move semantics |');
385
+ }
386
+ else if (langLower.includes('rust')) {
387
+ suggestions.push('| `rust-pro` | Ownership, lifetimes, async, error handling, macros |');
388
+ }
389
+ else if (langLower.includes('go')) {
390
+ suggestions.push('| `go-pro` | Concurrency, channels, interfaces, error handling |');
391
+ }
392
+ }
393
+ return suggestions.length > 0 ? [...new Set(suggestions)].join('\n') : null;
394
+ }
395
+ return (languageDroids
396
+ .map((d) => `| \`${d.name}\` | ${d.description || `${d.platform} language specialist`} |`)
397
+ .join('\n') || null);
398
+ }
399
+ function buildDiscoveredSkillsTable(skills) {
400
+ if (skills.length === 0)
401
+ return null;
402
+ return skills
403
+ .slice(0, 10)
404
+ .map((s) => {
405
+ const purpose = s.description || `${s.platform} skill`;
406
+ const useWhen = s.name.includes('design')
407
+ ? 'UI/design work'
408
+ : s.name.includes('test')
409
+ ? 'Testing and QA'
410
+ : s.name.includes('review')
411
+ ? 'Code review'
412
+ : 'Specialized tasks';
413
+ return `| \`${s.name}\` | ${purpose} | ${useWhen} |`;
414
+ })
415
+ .join('\n');
416
+ }
417
+ function buildTroubleshootingSection(memories) {
418
+ // Extract fix-related memories
419
+ const fixes = memories
420
+ .filter((m) => m.tags?.includes('bug-fix') ||
421
+ m.tags?.includes('revert') ||
422
+ m.content.toLowerCase().includes('fix') ||
423
+ m.content.toLowerCase().includes('resolved'))
424
+ .slice(0, 15);
425
+ if (fixes.length === 0)
426
+ return null;
427
+ const lines = [];
428
+ for (const fix of fixes) {
429
+ // Extract symptom and solution from content
430
+ const content = fix.content;
431
+ let symptom = '';
432
+ let solution = '';
433
+ if (content.includes('Bug fixed:')) {
434
+ symptom = content.replace('Bug fixed:', '').split('.')[0].trim();
435
+ solution = content.split('.').slice(1).join('.').trim() || 'See commit for details';
436
+ }
437
+ else if (content.includes('Failed approach')) {
438
+ symptom = content.split(':')[1]?.split('.')[0]?.trim() || content.slice(0, 50);
439
+ solution = 'Avoid this approach';
440
+ }
441
+ else {
442
+ symptom = content.slice(0, 60) + (content.length > 60 ? '...' : '');
443
+ solution = 'See memory for details';
444
+ }
445
+ if (symptom) {
446
+ lines.push(`| ${symptom} | ${solution.slice(0, 60)} |`);
447
+ }
448
+ }
449
+ if (lines.length === 0)
450
+ return null;
451
+ return `| Symptom | Solution |\n|---------|----------|\n${lines.join('\n')}`;
452
+ }
453
+ function buildArchitectureOverview(analysis) {
454
+ const sections = [];
455
+ // Infrastructure overview
456
+ if (analysis.infrastructure.iac || analysis.infrastructure.containerOrchestration) {
457
+ sections.push('### Infrastructure\n');
458
+ if (analysis.infrastructure.iac) {
459
+ sections.push(`- **IaC**: ${analysis.infrastructure.iac}`);
460
+ }
461
+ if (analysis.infrastructure.containerOrchestration) {
462
+ sections.push(`- **Orchestration**: ${analysis.infrastructure.containerOrchestration}`);
463
+ }
464
+ if (analysis.infrastructure.cloud && analysis.infrastructure.cloud.length > 0) {
465
+ sections.push(`- **Cloud**: ${analysis.infrastructure.cloud.join(', ')}`);
466
+ }
467
+ sections.push('');
468
+ }
469
+ // Component overview
470
+ if (analysis.components.length > 0) {
471
+ sections.push('### Components\n');
472
+ for (const comp of analysis.components.slice(0, 8)) {
473
+ sections.push(`- **${comp.name}** (\`${comp.path}\`): ${comp.description || `${comp.language} ${comp.framework || 'application'}`}`);
474
+ }
475
+ sections.push('');
476
+ }
477
+ return sections.length > 0 ? sections.join('\n') : null;
478
+ }
479
+ function buildCoreComponentsSection(analysis) {
480
+ if (analysis.components.length === 0)
481
+ return null;
482
+ const sections = [];
483
+ for (const comp of analysis.components.slice(0, 6)) {
484
+ sections.push(`### ${comp.name} (\`${comp.path}\`)\n`);
485
+ sections.push(`- **Language**: ${comp.language}`);
486
+ if (comp.framework) {
487
+ sections.push(`- **Framework**: ${comp.framework}`);
488
+ }
489
+ if (comp.description) {
490
+ sections.push(`- ${comp.description}`);
491
+ }
492
+ sections.push('');
493
+ }
494
+ return sections.join('\n');
495
+ }
496
+ function buildDatabaseArchitecture(analysis) {
497
+ const lines = [];
498
+ for (const db of analysis.databases) {
499
+ lines.push(`- **${db.type}**: ${db.purpose || 'Primary database'}`);
500
+ }
501
+ return lines.join('\n');
502
+ }
503
+ function buildAuthFlow(analysis) {
504
+ if (!analysis.authentication)
505
+ return '';
506
+ const sections = [];
507
+ sections.push(`**Provider**: ${analysis.authentication.provider}\n`);
508
+ if (analysis.authentication.description) {
509
+ sections.push(analysis.authentication.description);
510
+ }
511
+ return sections.join('\n');
512
+ }
513
+ function buildKeyConfigFiles(analysis) {
514
+ const files = [];
515
+ // Add key files from analysis
516
+ for (const kf of analysis.keyFiles.slice(0, 15)) {
517
+ files.push({ file: kf.file, purpose: kf.purpose });
518
+ }
519
+ if (files.length === 0)
520
+ return null;
521
+ return files.map((f) => `| \`${f.file}\` | ${f.purpose} |`).join('\n');
522
+ }
523
+ function buildEssentialCommands(analysis) {
524
+ const commands = [];
525
+ // Test command
526
+ if (analysis.commands.test && analysis.commands.test !== 'npm test') {
527
+ commands.push(`# Tests\n${analysis.commands.test}`);
528
+ }
529
+ // Lint command
530
+ if (analysis.commands.lint) {
531
+ commands.push(`# Linting\n${analysis.commands.lint}`);
532
+ }
533
+ // Build command
534
+ if (analysis.commands.build) {
535
+ commands.push(`# Build\n${analysis.commands.build}`);
536
+ }
537
+ // Infrastructure command
538
+ if (analysis.infrastructure.iac === 'Terraform') {
539
+ const infraPath = analysis.directories.infrastructure[0] || 'infra/terraform';
540
+ commands.push(`# Terraform\ncd ${infraPath} && terraform plan`);
541
+ }
542
+ return commands.length > 0 ? commands.join('\n\n') : null;
543
+ }
544
+ function buildClusterContexts(analysis) {
545
+ if (!analysis.clusters?.enabled || !analysis.clusters.contexts)
546
+ return null;
547
+ return analysis.clusters.contexts
548
+ .map((c) => `kubectl config use-context ${c.context} # ${c.name} (${c.purpose})`)
549
+ .join('\n');
550
+ }
551
+ function buildProjectUrls(analysis) {
552
+ if (analysis.urls.length === 0)
553
+ return null;
554
+ return analysis.urls.map((u) => `- **${u.name}**: ${u.value}`).join('\n');
555
+ }
556
+ function buildKeyWorkflows(analysis) {
557
+ if (!analysis.ciCd?.workflows || analysis.ciCd.workflows.length === 0)
558
+ return null;
559
+ return analysis.ciCd.workflows
560
+ .slice(0, 10)
561
+ .map((w) => `├── ${w.file}`.padEnd(35) + `# ${w.purpose}`)
562
+ .join('\n');
563
+ }
564
+ function buildInfraWorkflow(analysis) {
565
+ if (analysis.directories.infrastructure.length === 0)
566
+ return null;
567
+ const infraPath = analysis.directories.infrastructure[0];
568
+ const planCmd = analysis.infrastructure.iac === 'Terraform'
569
+ ? 'terraform plan'
570
+ : analysis.infrastructure.iac === 'Pulumi'
571
+ ? 'pulumi preview'
572
+ : 'infrastructure plan';
573
+ return `1. **Create worktree** for infrastructure changes
574
+ 2. Update infrastructure in \`${infraPath}/\`
575
+ 3. Update CI/CD workflows in \`.github/workflows/\`
576
+ 4. Run \`${planCmd}\`
577
+ 5. Update secrets via GitHub Actions (not locally)
578
+ 6. **Create PR** with automated review`;
579
+ }
580
+ function buildMcpPlugins(cwd) {
581
+ const mcpPath = join(cwd, '.mcp.json');
582
+ if (!existsSync(mcpPath))
583
+ return null;
584
+ try {
585
+ const mcp = JSON.parse(readFileSync(mcpPath, 'utf-8'));
586
+ if (!mcp.mcpServers && !mcp.plugins)
587
+ return null;
588
+ const plugins = mcp.mcpServers || mcp.plugins || {};
589
+ const lines = [];
590
+ for (const [name, config] of Object.entries(plugins)) {
591
+ const desc = config.description ||
592
+ config.purpose ||
593
+ 'MCP plugin';
594
+ lines.push(`| \`${name}\` | ${desc} |`);
595
+ }
596
+ return lines.length > 0 ? lines.join('\n') : null;
597
+ }
598
+ catch {
599
+ return null;
600
+ }
601
+ }
602
+ function buildPrimarySkills(skills) {
603
+ const primary = skills
604
+ .filter((s) => s.name.includes('design') || s.name.includes('frontend') || s.name.includes('ui'))
605
+ .slice(0, 3);
606
+ if (primary.length === 0)
607
+ return null;
608
+ return primary
609
+ .map((s) => `│ ├─ Use ${s.name} for ${s.description || 'specialized work'} │`)
610
+ .join('\n');
611
+ }
612
+ function buildLanguageExamples(languages) {
613
+ const examples = [];
614
+ for (const lang of languages.slice(0, 3)) {
615
+ const langLower = lang.toLowerCase();
616
+ if (langLower.includes('c++') || langLower.includes('cpp')) {
617
+ examples.push(`# For C++ work\nTask(subagent_type: "cpp-pro", prompt: "Refactor X using RAII...")`);
618
+ }
619
+ else if (langLower.includes('python')) {
620
+ examples.push(`# For Python work\nTask(subagent_type: "python-pro", prompt: "Optimize async handlers...")`);
621
+ }
622
+ else if (langLower.includes('rust')) {
623
+ examples.push(`# For Rust work\nTask(subagent_type: "rust-pro", prompt: "Implement with proper lifetimes...")`);
624
+ }
625
+ }
626
+ return examples.length > 0 ? examples.join('\n\n') : null;
627
+ }
628
+ function buildFileTypeRouting(languages) {
629
+ const routing = [];
630
+ const added = new Set();
631
+ for (const lang of languages) {
632
+ const langLower = lang.toLowerCase();
633
+ if ((langLower.includes('typescript') || langLower.includes('javascript')) &&
634
+ !added.has('ts')) {
635
+ routing.push('| `.ts`, `.tsx`, `.js`, `.jsx` | TypeScript/JavaScript | `typescript-node-expert` |');
636
+ added.add('ts');
637
+ }
638
+ if (langLower.includes('python') && !added.has('py')) {
639
+ routing.push('| `.py` | Python | `python-pro` |');
640
+ added.add('py');
641
+ }
642
+ if ((langLower.includes('c++') || langLower.includes('cpp')) && !added.has('cpp')) {
643
+ routing.push('| `.cpp`, `.h`, `.hpp` | C++ | `cpp-pro` |');
644
+ added.add('cpp');
645
+ }
646
+ if (langLower.includes('rust') && !added.has('rs')) {
647
+ routing.push('| `.rs` | Rust | `rust-pro` |');
648
+ added.add('rs');
649
+ }
650
+ if (langLower.includes('go') && !added.has('go')) {
651
+ routing.push('| `.go` | Go | `go-pro` |');
652
+ added.add('go');
653
+ }
654
+ if (langLower.includes('java') && !added.has('java')) {
655
+ routing.push('| `.java` | Java | `java-pro` |');
656
+ added.add('java');
657
+ }
658
+ }
659
+ // Always add Terraform and YAML for infrastructure projects
660
+ if (!added.has('tf')) {
661
+ routing.push('| `.tf` | Terraform | Direct handling |');
662
+ }
663
+ if (!added.has('yaml')) {
664
+ routing.push('| `.yaml`, `.yml` | Kubernetes/Config | Direct handling |');
665
+ }
666
+ return routing.length > 0 ? routing.join('\n') : null;
667
+ }
668
+ /**
669
+ * OPTIMIZATION 9: More aggressive pattern pruning based on project type.
670
+ * Prunes domain-specific patterns (Chess, Compression impossible, Polyglot, etc.)
671
+ * that don't apply to the project, saving ~800 tokens of context window.
672
+ *
673
+ * Now also categorizes patterns by priority for clearer guidance.
674
+ */
675
+ function buildRelevantPatterns(analysis) {
676
+ const languages = analysis.languages.map((l) => l.toLowerCase());
677
+ const hasInfra = analysis.directories.infrastructure.length > 0;
678
+ const hasSecurity = languages.some((l) => l.includes('python') || l.includes('javascript') || l.includes('typescript'));
679
+ const hasGit = true; // All projects use git
680
+ const hasCLI = analysis.components.some((c) => c.name.toLowerCase().includes('cli') ||
681
+ c.description?.toLowerCase().includes('command') ||
682
+ c.description?.toLowerCase().includes('script'));
683
+ // CRITICAL patterns - always included, proven high-impact
684
+ const critical = [
685
+ 'P12 (OEV)', // Output Existence - 37% of failures
686
+ 'P26 (NMI)', // Near-Miss Iteration - converted 2 tasks
687
+ 'P35 (DFA)', // Decoder-First - compression failures
688
+ ];
689
+ // HIGH priority - usually relevant
690
+ const high = ['P3 (StateProtect)', 'P17 (CE)', 'P32 (CEV)'];
691
+ // Standard patterns - based on project type
692
+ const standard = [
693
+ 'P1 (EnvIsolation)',
694
+ 'P2 (Recipe)',
695
+ 'P8 (CLIoverLib)',
696
+ 'P13 (IRL)',
697
+ 'P15 (ER)',
698
+ 'P16 (TFE)',
699
+ ];
700
+ // Conditionally add domain patterns
701
+ if (hasSecurity)
702
+ high.push('P10 (Whitelist)', 'P20 (AT)');
703
+ if (hasGit)
704
+ standard.push('P22 (GRF)');
705
+ if (hasInfra)
706
+ standard.push('P25 (SCP)', 'P28 (SST)');
707
+ if (hasCLI)
708
+ critical.push('P32 (CEV)'); // CLI Execution Verification
709
+ if (languages.some((l) => l.includes('rust') || l.includes('c++') || l.includes('python'))) {
710
+ standard.push('P33 (NST)');
711
+ }
712
+ // Domain-specific (only add if detected)
713
+ const domain = [];
714
+ if (analysis.components.some((c) => c.name.toLowerCase().includes('chess') || c.description?.toLowerCase().includes('chess'))) {
715
+ domain.push('P21 (CEI)');
716
+ }
717
+ if (analysis.components.some((c) => c.name.toLowerCase().includes('compress') ||
718
+ c.description?.toLowerCase().includes('compress'))) {
719
+ domain.push('P23 (CID)', 'P31 (RTV)');
720
+ }
721
+ // OPTIMIZATION 9: Format with priority levels for clarity
722
+ const lines = [];
723
+ lines.push(`**CRITICAL** (check every task): ${critical.join(', ')}`);
724
+ lines.push(`**HIGH**: ${high.join(', ')}`);
725
+ if (standard.length > 0)
726
+ lines.push(`**Standard**: ${standard.slice(0, 8).join(', ')}`);
727
+ if (domain.length > 0)
728
+ lines.push(`**Domain**: ${domain.join(', ')}`);
729
+ return lines.join('\n');
730
+ }
731
+ /**
732
+ * Filter out noisy/fragmented content from prepopulated knowledge.
733
+ * Removes: table fragments, badge/image references, testimonials, README marketing content.
734
+ */
735
+ function isNoisyContent(content) {
736
+ // Filter out table fragments
737
+ if (content.startsWith('|') || content.includes('|---|'))
738
+ return true;
739
+ // Filter out badge/image references
740
+ if (content.includes('[image:') || content.includes('!['))
741
+ return true;
742
+ // Filter out HTML fragments
743
+ if (content.includes('<div') || content.includes('</div>'))
744
+ return true;
745
+ // Filter out very short content (likely fragments)
746
+ if (content.length < 30)
747
+ return true;
748
+ // Filter out content that's mostly symbols/punctuation
749
+ const alphaCount = (content.match(/[a-zA-Z]/g) || []).length;
750
+ if (alphaCount < content.length * 0.5)
751
+ return true;
752
+ // Filter out testimonials and marketing quotes
753
+ if (content.includes('*"') || content.includes('"*') || content.includes('> *"'))
754
+ return true;
755
+ // Filter out README-style content (installation instructions, promo text)
756
+ if (content.includes('npm install') && content.includes('global'))
757
+ return true;
758
+ if (content.includes('conversation') && content.includes('assistant'))
759
+ return true;
760
+ if (content.includes('After') && content.includes('months'))
761
+ return true;
762
+ // Filter out command examples that are documentation, not lessons
763
+ if (content.startsWith('$ uap') || content.startsWith('$uap'))
764
+ return true;
765
+ if (content.startsWith('bash <(curl'))
766
+ return true;
767
+ // Filter out generic promotional phrases
768
+ if (content.includes('NOT limited') || content.includes('automatically route'))
769
+ return true;
770
+ // Filter out README content patterns (setup instructions, feature descriptions)
771
+ if (content.includes('Install & Init') || content.includes('npm i -g'))
772
+ return true;
773
+ if (content.includes('CLAUDE.md Generated') || content.includes('Auto-populated'))
774
+ return true;
775
+ if (content.includes('Close-Out') || content.includes('Merge → Deploy'))
776
+ return true;
777
+ if (content.includes('context-field research') || content.includes('Results from'))
778
+ return true;
779
+ // Filter out gate/checklist content already in template
780
+ if (content.includes('Three gates must pass') || content.includes('Gate 1'))
781
+ return true;
782
+ // Filter out content that's clearly documentation excerpts, not learned lessons
783
+ if (content.includes('never commits directly to main') ||
784
+ content.includes('All changes use worktrees'))
785
+ return true;
786
+ if (content.includes("Work isn't") && content.includes('deployed'))
787
+ return true;
788
+ if (content.includes('36 patterns discovered'))
789
+ return true;
790
+ return false;
791
+ }
792
+ function buildPrepopulatedKnowledge(prepopulated) {
793
+ if (!prepopulated)
794
+ return null;
795
+ const { shortTerm, longTerm } = prepopulated;
796
+ // Recent activity from short-term (skip noisy content)
797
+ const recentActivity = shortTerm
798
+ .filter((m) => (m.type === 'action' || m.type === 'observation') && !isNoisyContent(m.content))
799
+ .slice(0, 10)
800
+ .map((m) => `- ${m.content.slice(0, 100)}${m.content.length > 100 ? '...' : ''}`)
801
+ .join('\n');
802
+ // Learned lessons from long-term - filter noise and use sentence-aware truncation
803
+ const learnedLessons = longTerm
804
+ .filter((m) => (m.tags?.includes('bug-fix') ||
805
+ m.tags?.includes('lesson') ||
806
+ (m.importance && m.importance >= 7)) &&
807
+ !isNoisyContent(m.content))
808
+ .slice(0, 10)
809
+ .map((m) => {
810
+ const content = m.content;
811
+ // Truncate at sentence boundary rather than mid-word
812
+ const truncated = content.length > 200
813
+ ? content.slice(0, 200).replace(/[^.!?]*$/, '') || content.slice(0, 200)
814
+ : content;
815
+ const suffix = content.length > truncated.length ? '...' : '';
816
+ return `- **${m.tags?.slice(0, 2).join(', ') || 'general'}**: ${truncated}${suffix}`;
817
+ })
818
+ .join('\n');
819
+ // Known gotchas (from reverts and high-importance fixes) - filter noise
820
+ const knownGotchas = longTerm
821
+ .filter((m) => (m.tags?.includes('revert') ||
822
+ m.tags?.includes('failed-approach') ||
823
+ m.content.includes('avoid')) &&
824
+ !isNoisyContent(m.content))
825
+ .slice(0, 5)
826
+ .map((m) => {
827
+ const content = m.content;
828
+ const truncated = content.length > 200
829
+ ? content.slice(0, 200).replace(/[^.!?]*$/, '') || content.slice(0, 200)
830
+ : content;
831
+ const suffix = content.length > truncated.length ? '...' : '';
832
+ return `- ⚠️ ${truncated}${suffix}`;
833
+ })
834
+ .join('\n');
835
+ // Hot spots
836
+ const hotSpotMemory = longTerm.find((m) => m.id === 'git-hotspots');
837
+ const hotSpots = hotSpotMemory?.content || 'No hot spots detected yet.';
838
+ if (!recentActivity && !learnedLessons && !knownGotchas) {
839
+ return null;
840
+ }
841
+ return {
842
+ recentActivity: recentActivity || 'No recent activity recorded.',
843
+ learnedLessons: learnedLessons || 'No lessons recorded yet.',
844
+ knownGotchas: knownGotchas || 'No gotchas recorded yet.',
845
+ hotSpots,
846
+ };
847
+ }
848
+ function getDesktopTemplate() {
849
+ // Check locations in order:
850
+ // 1. User's project templates directory
851
+ // 2. Package's templates directory (for npm installed version)
852
+ // 3. Node modules (when installed as dependency)
853
+ // 4. Fallback inline template
854
+ const userTemplatePath = join(process.cwd(), 'templates/CLAUDE.template.md');
855
+ const packageTemplatePath = join(__dirname, '../../templates/CLAUDE.template.md');
856
+ const nodeModulesPath = join(process.cwd(), 'node_modules/universal-agent-protocol/templates/CLAUDE.template.md');
857
+ const templatePaths = [
858
+ { path: userTemplatePath, name: 'project templates' },
859
+ { path: packageTemplatePath, name: 'package templates' },
860
+ { path: nodeModulesPath, name: 'node_modules' },
861
+ ];
862
+ for (const { path, name } of templatePaths) {
863
+ if (existsSync(path)) {
864
+ try {
865
+ return readFileSync(path, 'utf-8');
866
+ }
867
+ catch (e) {
868
+ console.warn(`Warning: Found template at ${name} but couldn't read it: ${e}`);
869
+ }
870
+ }
871
+ }
872
+ console.info('Using built-in fallback template. For full features, ensure templates/CLAUDE.template.md exists.');
873
+ // Fallback inline template for desktop
874
+ return `<coding_guidelines>
875
+
876
+ # CLAUDE.md - {{PROJECT_NAME}} Development Guide
877
+
878
+ You are Autonomous Claude, a self-directed AI agent with full control over this virtual machine. You operate continuously, making your own decisions.
879
+
880
+ {{#if ISSUE_TRACKER}}
881
+ **Note**: {{{ISSUE_TRACKER}}}
882
+ {{/if}}
883
+
884
+ ---
885
+
886
+ ## ⚠️⚠️⚠️ CRITICAL: MANDATORY DECISION LOOP ⚠️⚠️⚠️
887
+
888
+ **FOLLOW THIS FOR EVERY ACTION. NO EXCEPTIONS.**
889
+
890
+ 1. **READ MEMORY FIRST**
891
+ - Query short-term: \`sqlite3 {{MEMORY_DB_PATH}} "SELECT * FROM memories ORDER BY id DESC LIMIT 20;"\`
892
+ - Query long-term: \`{{MEMORY_QUERY_CMD}} "<keywords>"\`
893
+
894
+ 2. **CHECK SKILLS** before implementing (see \`{{SKILLS_PATH}}\`)
895
+
896
+ 3. **CREATE WORKTREE** for ANY code changes
897
+ - \`{{WORKTREE_CREATE_CMD}} <slug>\`
898
+ - NEVER commit directly to {{DEFAULT_BRANCH}}
899
+
900
+ 4. **UPDATE MEMORY** after significant actions
901
+ - \`{{MEMORY_STORE_CMD}} lesson "What you learned" --tags tag1,tag2 --importance 7\`
902
+
903
+ ---
904
+
905
+ ## Memory System
906
+
907
+ - **Short-term**: \`{{MEMORY_DB_PATH}}\` (SQLite, last {{SHORT_TERM_LIMIT}} entries)
908
+ - **Long-term**: {{LONG_TERM_BACKEND}} at \`{{LONG_TERM_ENDPOINT}}\`
909
+
910
+ ---
911
+
912
+ ## Repository Structure
913
+
914
+ \`\`\`
915
+ {{PROJECT_NAME}}/
916
+ {{{@REPOSITORY_STRUCTURE}}}
917
+ \`\`\`
918
+
919
+ {{#if ARCHITECTURE_OVERVIEW}}
920
+ ## Architecture
921
+
922
+ {{{ARCHITECTURE_OVERVIEW}}}
923
+ {{/if}}
924
+
925
+ {{#if CORE_COMPONENTS}}
926
+ ## Components
927
+
928
+ {{{CORE_COMPONENTS}}}
929
+ {{/if}}
930
+
931
+ {{#if TROUBLESHOOTING}}
932
+ ## Troubleshooting
933
+
934
+ {{{TROUBLESHOOTING}}}
935
+ {{/if}}
936
+
937
+ ---
938
+
939
+ ## Completion Checklist
940
+
941
+ - [ ] Tests pass
942
+ - [ ] Worktree used
943
+ - [ ] Memory updated
944
+ - [ ] PR created (not direct commit)
945
+
946
+ </coding_guidelines>
947
+ `;
948
+ }
949
+ function getWebTemplate() {
950
+ return `<coding_guidelines>
951
+
952
+ # AGENT.md - {{PROJECT_NAME}} Development Guide
953
+
954
+ You are an AI agent helping with this project. Follow best practices and maintain context.
955
+
956
+ {{#if DESCRIPTION}}
957
+ > {{DESCRIPTION}}
958
+ {{/if}}
959
+
960
+ ---
961
+
962
+ ## ⛔ MANDATORY RULES
963
+
964
+ 1. **BRANCH REQUIREMENT**: Never commit directly to {{DEFAULT_BRANCH}}. Use feature branches.
965
+ 2. **MEMORY**: Store significant learnings to \`.uap/memory/\`
966
+ 3. **TODO LIST**: Create todo list for multi-step tasks (3+ steps)
967
+
968
+ ---
969
+
970
+ ## Memory System
971
+
972
+ ### Short-term (localStorage)
973
+
974
+ Key: \`agent_context_{{PROJECT_NAME}}\`
975
+
976
+ ### Long-term (GitHub: \`.uap/memory/\`)
977
+
978
+ Store memories as JSON files for persistent knowledge.
979
+
980
+ ---
981
+
982
+ ## Repository Structure
983
+
984
+ \`\`\`
985
+ {{PROJECT_NAME}}/
986
+ {{{@REPOSITORY_STRUCTURE}}}
987
+ \`\`\`
988
+
989
+ {{#if ARCHITECTURE_OVERVIEW}}
990
+ ## Architecture
991
+
992
+ {{{ARCHITECTURE_OVERVIEW}}}
993
+ {{/if}}
994
+
995
+ {{#if CORE_COMPONENTS}}
996
+ ## Components
997
+
998
+ {{{CORE_COMPONENTS}}}
999
+ {{/if}}
1000
+
1001
+ ---
1002
+
1003
+ ## Workflow
1004
+
1005
+ 1. Create feature branch: \`git checkout -b {{BRANCH_PREFIX}}<description>\`
1006
+ 2. Make changes, commit, push
1007
+ 3. Create PR via GitHub UI
1008
+
1009
+ ---
1010
+
1011
+ ## Quick Reference
1012
+
1013
+ - **Test**: \`{{TEST_COMMAND}}\`
1014
+ - **Build**: \`{{BUILD_COMMAND}}\`
1015
+ - **Lint**: \`{{LINT_COMMAND}}\`
1016
+
1017
+ </coding_guidelines>
1018
+ `;
1019
+ }
1020
+ //# sourceMappingURL=claude-md.js.map