@inharness-ai/claude4spec 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 (552) hide show
  1. package/.claude/skills/c4s-brief-implementer/SKILL.md +105 -0
  2. package/.claude/skills/c4s-spec-reader/SKILL.md +46 -0
  3. package/CHANGELOG.md +19 -0
  4. package/LICENSE +21 -0
  5. package/README.md +50 -0
  6. package/dist/bin/agent-md-template.d.ts +1 -0
  7. package/dist/bin/agent-md-template.js +76 -0
  8. package/dist/bin/agent-md-template.js.map +1 -0
  9. package/dist/bin/bootstrap-template.d.ts +1 -0
  10. package/dist/bin/bootstrap-template.js +12 -0
  11. package/dist/bin/bootstrap-template.js.map +1 -0
  12. package/dist/bin/c4s/args.d.ts +13 -0
  13. package/dist/bin/c4s/args.js +82 -0
  14. package/dist/bin/c4s/args.js.map +1 -0
  15. package/dist/bin/c4s/commands/_meta.d.ts +2 -0
  16. package/dist/bin/c4s/commands/_meta.js +13 -0
  17. package/dist/bin/c4s/commands/_meta.js.map +1 -0
  18. package/dist/bin/c4s/commands/catalog.d.ts +2 -0
  19. package/dist/bin/c4s/commands/catalog.js +38 -0
  20. package/dist/bin/c4s/commands/catalog.js.map +1 -0
  21. package/dist/bin/c4s/commands/detail.d.ts +2 -0
  22. package/dist/bin/c4s/commands/detail.js +22 -0
  23. package/dist/bin/c4s/commands/detail.js.map +1 -0
  24. package/dist/bin/c4s/commands/element-list.d.ts +2 -0
  25. package/dist/bin/c4s/commands/element-list.js +23 -0
  26. package/dist/bin/c4s/commands/element-list.js.map +1 -0
  27. package/dist/bin/c4s/commands/inline-mention.d.ts +2 -0
  28. package/dist/bin/c4s/commands/inline-mention.js +22 -0
  29. package/dist/bin/c4s/commands/inline-mention.js.map +1 -0
  30. package/dist/bin/c4s/commands/list-slugs.d.ts +2 -0
  31. package/dist/bin/c4s/commands/list-slugs.js +16 -0
  32. package/dist/bin/c4s/commands/list-slugs.js.map +1 -0
  33. package/dist/bin/c4s/commands/list-tags.d.ts +2 -0
  34. package/dist/bin/c4s/commands/list-tags.js +13 -0
  35. package/dist/bin/c4s/commands/list-tags.js.map +1 -0
  36. package/dist/bin/c4s/commands/resolve.d.ts +2 -0
  37. package/dist/bin/c4s/commands/resolve.js +40 -0
  38. package/dist/bin/c4s/commands/resolve.js.map +1 -0
  39. package/dist/bin/c4s/commands/section-ref.d.ts +2 -0
  40. package/dist/bin/c4s/commands/section-ref.js +25 -0
  41. package/dist/bin/c4s/commands/section-ref.js.map +1 -0
  42. package/dist/bin/c4s/commands/single-element.d.ts +2 -0
  43. package/dist/bin/c4s/commands/single-element.js +22 -0
  44. package/dist/bin/c4s/commands/single-element.js.map +1 -0
  45. package/dist/bin/c4s/commands/tagged-list-mixed.d.ts +2 -0
  46. package/dist/bin/c4s/commands/tagged-list-mixed.js +39 -0
  47. package/dist/bin/c4s/commands/tagged-list-mixed.js.map +1 -0
  48. package/dist/bin/c4s/commands/tagged-list.d.ts +2 -0
  49. package/dist/bin/c4s/commands/tagged-list.js +24 -0
  50. package/dist/bin/c4s/commands/tagged-list.js.map +1 -0
  51. package/dist/bin/c4s/context.d.ts +12 -0
  52. package/dist/bin/c4s/context.js +27 -0
  53. package/dist/bin/c4s/context.js.map +1 -0
  54. package/dist/bin/c4s/errors.d.ts +6 -0
  55. package/dist/bin/c4s/errors.js +11 -0
  56. package/dist/bin/c4s/errors.js.map +1 -0
  57. package/dist/bin/c4s/output.d.ts +4 -0
  58. package/dist/bin/c4s/output.js +57 -0
  59. package/dist/bin/c4s/output.js.map +1 -0
  60. package/dist/bin/c4s/project.d.ts +1 -0
  61. package/dist/bin/c4s/project.js +23 -0
  62. package/dist/bin/c4s/project.js.map +1 -0
  63. package/dist/bin/c4s/type-validation.d.ts +3 -0
  64. package/dist/bin/c4s/type-validation.js +11 -0
  65. package/dist/bin/c4s/type-validation.js.map +1 -0
  66. package/dist/bin/c4s-mcp.d.ts +2 -0
  67. package/dist/bin/c4s-mcp.js +118 -0
  68. package/dist/bin/c4s-mcp.js.map +1 -0
  69. package/dist/bin/c4s.d.ts +2 -0
  70. package/dist/bin/c4s.js +134 -0
  71. package/dist/bin/c4s.js.map +1 -0
  72. package/dist/bin/claude4spec.d.ts +2 -0
  73. package/dist/bin/claude4spec.js +132 -0
  74. package/dist/bin/claude4spec.js.map +1 -0
  75. package/dist/bin/gitignore.d.ts +1 -0
  76. package/dist/bin/gitignore.js +44 -0
  77. package/dist/bin/gitignore.js.map +1 -0
  78. package/dist/client/assets/arc-D8brDDag.js +1 -0
  79. package/dist/client/assets/architectureDiagram-3BPJPVTR-Bmh1uTQZ.js +36 -0
  80. package/dist/client/assets/blockDiagram-GPEHLZMM-55jaVWwd.js +132 -0
  81. package/dist/client/assets/c4Diagram-AAUBKEIU-Dxm0tLsZ.js +10 -0
  82. package/dist/client/assets/channel-ArVcv4Yl.js +1 -0
  83. package/dist/client/assets/chunk-2J33WTMH-vDJ1slcJ.js +1 -0
  84. package/dist/client/assets/chunk-4BX2VUAB-DP6CC-Qn.js +1 -0
  85. package/dist/client/assets/chunk-55IACEB6-SgOSJYkL.js +1 -0
  86. package/dist/client/assets/chunk-727SXJPM-BtRfbjBO.js +206 -0
  87. package/dist/client/assets/chunk-AQP2D5EJ-yIRaTgFg.js +231 -0
  88. package/dist/client/assets/chunk-FMBD7UC4-B_VD4t8N.js +15 -0
  89. package/dist/client/assets/chunk-ND2GUHAM-BvJdtX82.js +1 -0
  90. package/dist/client/assets/chunk-QZHKN3VN-BLNWKymD.js +1 -0
  91. package/dist/client/assets/classDiagram-4FO5ZUOK-B3nmPR7w.js +1 -0
  92. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-B3nmPR7w.js +1 -0
  93. package/dist/client/assets/cose-bilkent-S5V4N54A-BQyA-r-y.js +1 -0
  94. package/dist/client/assets/cytoscape.esm-D_LviqZs.js +331 -0
  95. package/dist/client/assets/dagre-BM42HDAG-CAh0mTzA.js +4 -0
  96. package/dist/client/assets/defaultLocale-DX6XiGOO.js +1 -0
  97. package/dist/client/assets/diagram-2AECGRRQ-C83TGK4o.js +43 -0
  98. package/dist/client/assets/diagram-5GNKFQAL-2L6uowvf.js +10 -0
  99. package/dist/client/assets/diagram-KO2AKTUF-Cj5n4jdq.js +3 -0
  100. package/dist/client/assets/diagram-LMA3HP47-Bp5SDMjg.js +24 -0
  101. package/dist/client/assets/diagram-OG6HWLK6-cFsDQ8Qk.js +24 -0
  102. package/dist/client/assets/erDiagram-TEJ5UH35-D8G5xpg3.js +85 -0
  103. package/dist/client/assets/flowDiagram-I6XJVG4X-CuNudlCD.js +162 -0
  104. package/dist/client/assets/ganttDiagram-6RSMTGT7-CtFlsB15.js +292 -0
  105. package/dist/client/assets/gitGraphDiagram-PVQCEYII-h66Tso4O.js +106 -0
  106. package/dist/client/assets/graph-CAnANduQ.js +1 -0
  107. package/dist/client/assets/index-CZOpb3O7.css +1 -0
  108. package/dist/client/assets/index-D5ljIkCJ.js +727 -0
  109. package/dist/client/assets/index-aJE-l7h7.js +11 -0
  110. package/dist/client/assets/index-aPVup1Re.js +51 -0
  111. package/dist/client/assets/infoDiagram-5YYISTIA-CO_BLfuW.js +2 -0
  112. package/dist/client/assets/init-Gi6I4Gst.js +1 -0
  113. package/dist/client/assets/ishikawaDiagram-YF4QCWOH-D4rSRnQA.js +70 -0
  114. package/dist/client/assets/journeyDiagram-JHISSGLW-GyHI6dB8.js +139 -0
  115. package/dist/client/assets/kanban-definition-UN3LZRKU-CrH33WLe.js +89 -0
  116. package/dist/client/assets/katex-CQk2-UhE.js +257 -0
  117. package/dist/client/assets/layout-DGIYPm2g.js +1 -0
  118. package/dist/client/assets/linear-Dh1OyvSm.js +1 -0
  119. package/dist/client/assets/mermaid.core-C45sMDhS.js +309 -0
  120. package/dist/client/assets/mindmap-definition-RKZ34NQL-Bgwb0vwA.js +96 -0
  121. package/dist/client/assets/ordinal-Cboi1Yqb.js +1 -0
  122. package/dist/client/assets/pieDiagram-4H26LBE5-l9cCpVfG.js +30 -0
  123. package/dist/client/assets/quadrantDiagram-W4KKPZXB-BCPSUbC3.js +7 -0
  124. package/dist/client/assets/requirementDiagram-4Y6WPE33-TEGOe-vV.js +84 -0
  125. package/dist/client/assets/sankeyDiagram-5OEKKPKP-C69pv_7D.js +40 -0
  126. package/dist/client/assets/sequenceDiagram-3UESZ5HK-arinzeCk.js +162 -0
  127. package/dist/client/assets/stateDiagram-AJRCARHV-C2YENpmw.js +1 -0
  128. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-CS6ocDH6.js +1 -0
  129. package/dist/client/assets/timeline-definition-PNZ67QCA-h5qtI99f.js +120 -0
  130. package/dist/client/assets/vennDiagram-CIIHVFJN-CnuK75Ut.js +34 -0
  131. package/dist/client/assets/wardley-L42UT6IY-B4bQ0Xyy.js +173 -0
  132. package/dist/client/assets/wardleyDiagram-YWT4CUSO-apV8olQc.js +78 -0
  133. package/dist/client/assets/xychartDiagram-2RQKCTM6-OTP6zeEy.js +7 -0
  134. package/dist/client/index.html +19 -0
  135. package/dist/server/config.d.ts +59 -0
  136. package/dist/server/config.js +211 -0
  137. package/dist/server/config.js.map +1 -0
  138. package/dist/server/core/plugin-host/cross-cutting.d.ts +8 -0
  139. package/dist/server/core/plugin-host/cross-cutting.js +14 -0
  140. package/dist/server/core/plugin-host/cross-cutting.js.map +1 -0
  141. package/dist/server/core/plugin-host/entities-router.d.ts +11 -0
  142. package/dist/server/core/plugin-host/entities-router.js +77 -0
  143. package/dist/server/core/plugin-host/entities-router.js.map +1 -0
  144. package/dist/server/core/plugin-host/host.d.ts +11 -0
  145. package/dist/server/core/plugin-host/host.js +128 -0
  146. package/dist/server/core/plugin-host/host.js.map +1 -0
  147. package/dist/server/core/plugin-host/legacy-adapter.d.ts +31 -0
  148. package/dist/server/core/plugin-host/legacy-adapter.js +88 -0
  149. package/dist/server/core/plugin-host/legacy-adapter.js.map +1 -0
  150. package/dist/server/core/plugin-host/serialization-engine.d.ts +35 -0
  151. package/dist/server/core/plugin-host/serialization-engine.js +132 -0
  152. package/dist/server/core/plugin-host/serialization-engine.js.map +1 -0
  153. package/dist/server/core/plugin-host/types.d.ts +143 -0
  154. package/dist/server/core/plugin-host/types.js +10 -0
  155. package/dist/server/core/plugin-host/types.js.map +1 -0
  156. package/dist/server/db/fixups/backfill-plan-titles.d.ts +2 -0
  157. package/dist/server/db/fixups/backfill-plan-titles.js +22 -0
  158. package/dist/server/db/fixups/backfill-plan-titles.js.map +1 -0
  159. package/dist/server/db/index.d.ts +6 -0
  160. package/dist/server/db/index.js +26 -0
  161. package/dist/server/db/index.js.map +1 -0
  162. package/dist/server/db/migrate.d.ts +2 -0
  163. package/dist/server/db/migrate.js +33 -0
  164. package/dist/server/db/migrate.js.map +1 -0
  165. package/dist/server/db/migrations/000_init.sql +7 -0
  166. package/dist/server/db/migrations/001_endpoint.sql +51 -0
  167. package/dist/server/db/migrations/002_dto.sql +23 -0
  168. package/dist/server/db/migrations/003_drop_endpoint_body.sql +5 -0
  169. package/dist/server/db/migrations/004_drop_module_and_status.sql +31 -0
  170. package/dist/server/db/migrations/005_chat.sql +23 -0
  171. package/dist/server/db/migrations/006_database_table.sql +10 -0
  172. package/dist/server/db/migrations/007_sections.sql +30 -0
  173. package/dist/server/db/migrations/008_subagent_task.sql +20 -0
  174. package/dist/server/db/migrations/009_chat_todo_snapshot.sql +4 -0
  175. package/dist/server/db/migrations/010_chat_plan_mode.sql +5 -0
  176. package/dist/server/db/migrations/011_chat_initial_system_prompt.sql +4 -0
  177. package/dist/server/db/migrations/012_chat_message_status.sql +5 -0
  178. package/dist/server/db/migrations/013_chat_usage_snapshot.sql +7 -0
  179. package/dist/server/db/migrations/014_plans.sql +33 -0
  180. package/dist/server/db/migrations/015_dto_examples.sql +4 -0
  181. package/dist/server/db/migrations/016_ui_view.sql +10 -0
  182. package/dist/server/db/migrations/017_entity_version_m17.sql +23 -0
  183. package/dist/server/db/migrations/018_page_version.sql +20 -0
  184. package/dist/server/db/migrations/019_spec_release.sql +13 -0
  185. package/dist/server/db/migrations/020_drop_plan_status.sql +10 -0
  186. package/dist/server/db/migrations/021_plans_n1.sql +36 -0
  187. package/dist/server/db/migrations/022_brief_chat_columns.sql +23 -0
  188. package/dist/server/db/migrations/023_page_version_kind.sql +26 -0
  189. package/dist/server/db/migrations/024_chat_context_size.sql +10 -0
  190. package/dist/server/db/migrations/025_ac.sql +19 -0
  191. package/dist/server/db/migrations/026_ac_seed.sql +75 -0
  192. package/dist/server/db/migrations/027_page_version_change_summary.sql +10 -0
  193. package/dist/server/db/readonly.d.ts +12 -0
  194. package/dist/server/db/readonly.js +32 -0
  195. package/dist/server/db/readonly.js.map +1 -0
  196. package/dist/server/domain/raw-entity-reader.d.ts +76 -0
  197. package/dist/server/domain/raw-entity-reader.js +240 -0
  198. package/dist/server/domain/raw-entity-reader.js.map +1 -0
  199. package/dist/server/entities/ac/mcp-server.d.ts +10 -0
  200. package/dist/server/entities/ac/mcp-server.js +154 -0
  201. package/dist/server/entities/ac/mcp-server.js.map +1 -0
  202. package/dist/server/entities/ac/plugin.d.ts +2 -0
  203. package/dist/server/entities/ac/plugin.js +33 -0
  204. package/dist/server/entities/ac/plugin.js.map +1 -0
  205. package/dist/server/entities/ac/routes.d.ts +4 -0
  206. package/dist/server/entities/ac/routes.js +92 -0
  207. package/dist/server/entities/ac/routes.js.map +1 -0
  208. package/dist/server/entities/ac/serializer.d.ts +13 -0
  209. package/dist/server/entities/ac/serializer.js +124 -0
  210. package/dist/server/entities/ac/serializer.js.map +1 -0
  211. package/dist/server/entities/ac/services.d.ts +35 -0
  212. package/dist/server/entities/ac/services.js +261 -0
  213. package/dist/server/entities/ac/services.js.map +1 -0
  214. package/dist/server/entities/ac/system-prompt.d.ts +2 -0
  215. package/dist/server/entities/ac/system-prompt.js +18 -0
  216. package/dist/server/entities/ac/system-prompt.js.map +1 -0
  217. package/dist/server/entities/database-table/mcp-server.d.ts +10 -0
  218. package/dist/server/entities/database-table/mcp-server.js +184 -0
  219. package/dist/server/entities/database-table/mcp-server.js.map +1 -0
  220. package/dist/server/entities/database-table/plugin.d.ts +2 -0
  221. package/dist/server/entities/database-table/plugin.js +33 -0
  222. package/dist/server/entities/database-table/plugin.js.map +1 -0
  223. package/dist/server/entities/database-table/routes.d.ts +5 -0
  224. package/dist/server/entities/database-table/routes.js +86 -0
  225. package/dist/server/entities/database-table/routes.js.map +1 -0
  226. package/dist/server/entities/database-table/serializer.d.ts +12 -0
  227. package/dist/server/entities/database-table/serializer.js +192 -0
  228. package/dist/server/entities/database-table/serializer.js.map +1 -0
  229. package/dist/server/entities/database-table/services.d.ts +45 -0
  230. package/dist/server/entities/database-table/services.js +323 -0
  231. package/dist/server/entities/database-table/services.js.map +1 -0
  232. package/dist/server/entities/database-table/system-prompt.d.ts +2 -0
  233. package/dist/server/entities/database-table/system-prompt.js +11 -0
  234. package/dist/server/entities/database-table/system-prompt.js.map +1 -0
  235. package/dist/server/entities/dto/mcp-server.d.ts +10 -0
  236. package/dist/server/entities/dto/mcp-server.js +141 -0
  237. package/dist/server/entities/dto/mcp-server.js.map +1 -0
  238. package/dist/server/entities/dto/plugin.d.ts +2 -0
  239. package/dist/server/entities/dto/plugin.js +33 -0
  240. package/dist/server/entities/dto/plugin.js.map +1 -0
  241. package/dist/server/entities/dto/routes.d.ts +4 -0
  242. package/dist/server/entities/dto/routes.js +74 -0
  243. package/dist/server/entities/dto/routes.js.map +1 -0
  244. package/dist/server/entities/dto/serializer.d.ts +12 -0
  245. package/dist/server/entities/dto/serializer.js +184 -0
  246. package/dist/server/entities/dto/serializer.js.map +1 -0
  247. package/dist/server/entities/dto/services.d.ts +30 -0
  248. package/dist/server/entities/dto/services.js +242 -0
  249. package/dist/server/entities/dto/services.js.map +1 -0
  250. package/dist/server/entities/dto/system-prompt.d.ts +2 -0
  251. package/dist/server/entities/dto/system-prompt.js +11 -0
  252. package/dist/server/entities/dto/system-prompt.js.map +1 -0
  253. package/dist/server/entities/endpoint/mcp-server.d.ts +10 -0
  254. package/dist/server/entities/endpoint/mcp-server.js +156 -0
  255. package/dist/server/entities/endpoint/mcp-server.js.map +1 -0
  256. package/dist/server/entities/endpoint/plugin.d.ts +2 -0
  257. package/dist/server/entities/endpoint/plugin.js +36 -0
  258. package/dist/server/entities/endpoint/plugin.js.map +1 -0
  259. package/dist/server/entities/endpoint/routes.d.ts +4 -0
  260. package/dist/server/entities/endpoint/routes.js +107 -0
  261. package/dist/server/entities/endpoint/routes.js.map +1 -0
  262. package/dist/server/entities/endpoint/serializer.d.ts +17 -0
  263. package/dist/server/entities/endpoint/serializer.js +217 -0
  264. package/dist/server/entities/endpoint/serializer.js.map +1 -0
  265. package/dist/server/entities/endpoint/services.d.ts +30 -0
  266. package/dist/server/entities/endpoint/services.js +260 -0
  267. package/dist/server/entities/endpoint/services.js.map +1 -0
  268. package/dist/server/entities/endpoint/system-prompt.d.ts +2 -0
  269. package/dist/server/entities/endpoint/system-prompt.js +11 -0
  270. package/dist/server/entities/endpoint/system-prompt.js.map +1 -0
  271. package/dist/server/entities/ui-view/mcp-server.d.ts +10 -0
  272. package/dist/server/entities/ui-view/mcp-server.js +161 -0
  273. package/dist/server/entities/ui-view/mcp-server.js.map +1 -0
  274. package/dist/server/entities/ui-view/plugin.d.ts +2 -0
  275. package/dist/server/entities/ui-view/plugin.js +33 -0
  276. package/dist/server/entities/ui-view/plugin.js.map +1 -0
  277. package/dist/server/entities/ui-view/routes.d.ts +5 -0
  278. package/dist/server/entities/ui-view/routes.js +82 -0
  279. package/dist/server/entities/ui-view/routes.js.map +1 -0
  280. package/dist/server/entities/ui-view/serializer.d.ts +12 -0
  281. package/dist/server/entities/ui-view/serializer.js +262 -0
  282. package/dist/server/entities/ui-view/serializer.js.map +1 -0
  283. package/dist/server/entities/ui-view/services.d.ts +35 -0
  284. package/dist/server/entities/ui-view/services.js +255 -0
  285. package/dist/server/entities/ui-view/services.js.map +1 -0
  286. package/dist/server/entities/ui-view/system-prompt.d.ts +7 -0
  287. package/dist/server/entities/ui-view/system-prompt.js +15 -0
  288. package/dist/server/entities/ui-view/system-prompt.js.map +1 -0
  289. package/dist/server/external-skills/brief-implementer-template.d.ts +2 -0
  290. package/dist/server/external-skills/brief-implementer-template.js +123 -0
  291. package/dist/server/external-skills/brief-implementer-template.js.map +1 -0
  292. package/dist/server/external-skills/external-skills-service.d.ts +3 -0
  293. package/dist/server/external-skills/external-skills-service.js +47 -0
  294. package/dist/server/external-skills/external-skills-service.js.map +1 -0
  295. package/dist/server/external-skills/spec-reader-template.d.ts +2 -0
  296. package/dist/server/external-skills/spec-reader-template.js +47 -0
  297. package/dist/server/external-skills/spec-reader-template.js.map +1 -0
  298. package/dist/server/fs/watcher.d.ts +26 -0
  299. package/dist/server/fs/watcher.js +64 -0
  300. package/dist/server/fs/watcher.js.map +1 -0
  301. package/dist/server/index.d.ts +18 -0
  302. package/dist/server/index.js +474 -0
  303. package/dist/server/index.js.map +1 -0
  304. package/dist/server/mcp/brief-tools.d.ts +19 -0
  305. package/dist/server/mcp/brief-tools.js +189 -0
  306. package/dist/server/mcp/brief-tools.js.map +1 -0
  307. package/dist/server/mcp/c4s-reader.d.ts +12 -0
  308. package/dist/server/mcp/c4s-reader.js +263 -0
  309. package/dist/server/mcp/c4s-reader.js.map +1 -0
  310. package/dist/server/mcp/database-tools.d.ts +10 -0
  311. package/dist/server/mcp/database-tools.js +184 -0
  312. package/dist/server/mcp/database-tools.js.map +1 -0
  313. package/dist/server/mcp/dependency-tools.d.ts +12 -0
  314. package/dist/server/mcp/dependency-tools.js +205 -0
  315. package/dist/server/mcp/dependency-tools.js.map +1 -0
  316. package/dist/server/mcp/dto-tools.d.ts +10 -0
  317. package/dist/server/mcp/dto-tools.js +141 -0
  318. package/dist/server/mcp/dto-tools.js.map +1 -0
  319. package/dist/server/mcp/endpoint-tools.d.ts +10 -0
  320. package/dist/server/mcp/endpoint-tools.js +156 -0
  321. package/dist/server/mcp/endpoint-tools.js.map +1 -0
  322. package/dist/server/mcp/ensure-mcp-json.d.ts +6 -0
  323. package/dist/server/mcp/ensure-mcp-json.js +30 -0
  324. package/dist/server/mcp/ensure-mcp-json.js.map +1 -0
  325. package/dist/server/mcp/index.d.ts +29 -0
  326. package/dist/server/mcp/index.js +40 -0
  327. package/dist/server/mcp/index.js.map +1 -0
  328. package/dist/server/mcp/plan-tools.d.ts +7 -0
  329. package/dist/server/mcp/plan-tools.js +105 -0
  330. package/dist/server/mcp/plan-tools.js.map +1 -0
  331. package/dist/server/mcp/reference-tools.d.ts +17 -0
  332. package/dist/server/mcp/reference-tools.js +630 -0
  333. package/dist/server/mcp/reference-tools.js.map +1 -0
  334. package/dist/server/mcp/release-tools/index.d.ts +21 -0
  335. package/dist/server/mcp/release-tools/index.js +140 -0
  336. package/dist/server/mcp/release-tools/index.js.map +1 -0
  337. package/dist/server/mcp/release-tools/projection.d.ts +32 -0
  338. package/dist/server/mcp/release-tools/projection.js +278 -0
  339. package/dist/server/mcp/release-tools/projection.js.map +1 -0
  340. package/dist/server/mcp/release-tools/types.d.ts +91 -0
  341. package/dist/server/mcp/release-tools/types.js +11 -0
  342. package/dist/server/mcp/release-tools/types.js.map +1 -0
  343. package/dist/server/mcp/release-tools.d.ts +14 -0
  344. package/dist/server/mcp/release-tools.js +83 -0
  345. package/dist/server/mcp/release-tools.js.map +1 -0
  346. package/dist/server/mcp/ui-view-tools.d.ts +10 -0
  347. package/dist/server/mcp/ui-view-tools.js +161 -0
  348. package/dist/server/mcp/ui-view-tools.js.map +1 -0
  349. package/dist/server/routes/briefs.d.ts +8 -0
  350. package/dist/server/routes/briefs.js +178 -0
  351. package/dist/server/routes/briefs.js.map +1 -0
  352. package/dist/server/routes/chat.d.ts +29 -0
  353. package/dist/server/routes/chat.js +604 -0
  354. package/dist/server/routes/chat.js.map +1 -0
  355. package/dist/server/routes/database-tables.d.ts +5 -0
  356. package/dist/server/routes/database-tables.js +86 -0
  357. package/dist/server/routes/database-tables.js.map +1 -0
  358. package/dist/server/routes/dependencies.d.ts +6 -0
  359. package/dist/server/routes/dependencies.js +164 -0
  360. package/dist/server/routes/dependencies.js.map +1 -0
  361. package/dist/server/routes/dtos.d.ts +4 -0
  362. package/dist/server/routes/dtos.js +74 -0
  363. package/dist/server/routes/dtos.js.map +1 -0
  364. package/dist/server/routes/endpoints.d.ts +4 -0
  365. package/dist/server/routes/endpoints.js +107 -0
  366. package/dist/server/routes/endpoints.js.map +1 -0
  367. package/dist/server/routes/entities.d.ts +8 -0
  368. package/dist/server/routes/entities.js +84 -0
  369. package/dist/server/routes/entities.js.map +1 -0
  370. package/dist/server/routes/errors.d.ts +2 -0
  371. package/dist/server/routes/errors.js +37 -0
  372. package/dist/server/routes/errors.js.map +1 -0
  373. package/dist/server/routes/page-links.d.ts +3 -0
  374. package/dist/server/routes/page-links.js +40 -0
  375. package/dist/server/routes/page-links.js.map +1 -0
  376. package/dist/server/routes/pages.d.ts +5 -0
  377. package/dist/server/routes/pages.js +142 -0
  378. package/dist/server/routes/pages.js.map +1 -0
  379. package/dist/server/routes/plans.d.ts +3 -0
  380. package/dist/server/routes/plans.js +192 -0
  381. package/dist/server/routes/plans.js.map +1 -0
  382. package/dist/server/routes/references.d.ts +3 -0
  383. package/dist/server/routes/references.js +34 -0
  384. package/dist/server/routes/references.js.map +1 -0
  385. package/dist/server/routes/releases.d.ts +4 -0
  386. package/dist/server/routes/releases.js +122 -0
  387. package/dist/server/routes/releases.js.map +1 -0
  388. package/dist/server/routes/sections.d.ts +3 -0
  389. package/dist/server/routes/sections.js +32 -0
  390. package/dist/server/routes/sections.js.map +1 -0
  391. package/dist/server/routes/tags.d.ts +4 -0
  392. package/dist/server/routes/tags.js +56 -0
  393. package/dist/server/routes/tags.js.map +1 -0
  394. package/dist/server/routes/threads.d.ts +3 -0
  395. package/dist/server/routes/threads.js +78 -0
  396. package/dist/server/routes/threads.js.map +1 -0
  397. package/dist/server/routes/todos.d.ts +3 -0
  398. package/dist/server/routes/todos.js +28 -0
  399. package/dist/server/routes/todos.js.map +1 -0
  400. package/dist/server/routes/ui-views.d.ts +5 -0
  401. package/dist/server/routes/ui-views.js +82 -0
  402. package/dist/server/routes/ui-views.js.map +1 -0
  403. package/dist/server/serialization/auto-schema.d.ts +3 -0
  404. package/dist/server/serialization/auto-schema.js +55 -0
  405. package/dist/server/serialization/auto-schema.js.map +1 -0
  406. package/dist/server/serialization/fallback.d.ts +4 -0
  407. package/dist/server/serialization/fallback.js +27 -0
  408. package/dist/server/serialization/fallback.js.map +1 -0
  409. package/dist/server/serialization/inline-renderer.d.ts +4 -0
  410. package/dist/server/serialization/inline-renderer.js +151 -0
  411. package/dist/server/serialization/inline-renderer.js.map +1 -0
  412. package/dist/server/serialization/registerAll.d.ts +6 -0
  413. package/dist/server/serialization/registerAll.js +7 -0
  414. package/dist/server/serialization/registerAll.js.map +1 -0
  415. package/dist/server/serialization/registry.d.ts +26 -0
  416. package/dist/server/serialization/registry.js +121 -0
  417. package/dist/server/serialization/registry.js.map +1 -0
  418. package/dist/server/serialization/resolve-page.d.ts +24 -0
  419. package/dist/server/serialization/resolve-page.js +192 -0
  420. package/dist/server/serialization/resolve-page.js.map +1 -0
  421. package/dist/server/serialization/serializers/database-table.d.ts +1 -0
  422. package/dist/server/serialization/serializers/database-table.js +46 -0
  423. package/dist/server/serialization/serializers/database-table.js.map +1 -0
  424. package/dist/server/serialization/serializers/dto.d.ts +1 -0
  425. package/dist/server/serialization/serializers/dto.js +48 -0
  426. package/dist/server/serialization/serializers/dto.js.map +1 -0
  427. package/dist/server/serialization/serializers/endpoint.d.ts +1 -0
  428. package/dist/server/serialization/serializers/endpoint.js +93 -0
  429. package/dist/server/serialization/serializers/endpoint.js.map +1 -0
  430. package/dist/server/serialization/serializers/section.d.ts +1 -0
  431. package/dist/server/serialization/serializers/section.js +24 -0
  432. package/dist/server/serialization/serializers/section.js.map +1 -0
  433. package/dist/server/serialization/serializers/ui-view.d.ts +1 -0
  434. package/dist/server/serialization/serializers/ui-view.js +124 -0
  435. package/dist/server/serialization/serializers/ui-view.js.map +1 -0
  436. package/dist/server/serialization/snapshot.d.ts +22 -0
  437. package/dist/server/serialization/snapshot.js +102 -0
  438. package/dist/server/serialization/snapshot.js.map +1 -0
  439. package/dist/server/serialization/types.d.ts +70 -0
  440. package/dist/server/serialization/types.js +7 -0
  441. package/dist/server/serialization/types.js.map +1 -0
  442. package/dist/server/serialization/writer.d.ts +41 -0
  443. package/dist/server/serialization/writer.js +13 -0
  444. package/dist/server/serialization/writer.js.map +1 -0
  445. package/dist/server/services/brief.d.ts +86 -0
  446. package/dist/server/services/brief.js +218 -0
  447. package/dist/server/services/brief.js.map +1 -0
  448. package/dist/server/services/chat-context.d.ts +26 -0
  449. package/dist/server/services/chat-context.js +434 -0
  450. package/dist/server/services/chat-context.js.map +1 -0
  451. package/dist/server/services/chat.d.ts +50 -0
  452. package/dist/server/services/chat.js +309 -0
  453. package/dist/server/services/chat.js.map +1 -0
  454. package/dist/server/services/database-table.d.ts +36 -0
  455. package/dist/server/services/database-table.js +303 -0
  456. package/dist/server/services/database-table.js.map +1 -0
  457. package/dist/server/services/dependencies.d.ts +45 -0
  458. package/dist/server/services/dependencies.js +302 -0
  459. package/dist/server/services/dependencies.js.map +1 -0
  460. package/dist/server/services/dto.d.ts +22 -0
  461. package/dist/server/services/dto.js +222 -0
  462. package/dist/server/services/dto.js.map +1 -0
  463. package/dist/server/services/endpoint.d.ts +22 -0
  464. package/dist/server/services/endpoint.js +239 -0
  465. package/dist/server/services/endpoint.js.map +1 -0
  466. package/dist/server/services/entity-writer.d.ts +46 -0
  467. package/dist/server/services/entity-writer.js +137 -0
  468. package/dist/server/services/entity-writer.js.map +1 -0
  469. package/dist/server/services/page-serializer.d.ts +109 -0
  470. package/dist/server/services/page-serializer.js +359 -0
  471. package/dist/server/services/page-serializer.js.map +1 -0
  472. package/dist/server/services/page-version.d.ts +75 -0
  473. package/dist/server/services/page-version.js +159 -0
  474. package/dist/server/services/page-version.js.map +1 -0
  475. package/dist/server/services/pages-frontmatter-indexer.d.ts +51 -0
  476. package/dist/server/services/pages-frontmatter-indexer.js +138 -0
  477. package/dist/server/services/pages-frontmatter-indexer.js.map +1 -0
  478. package/dist/server/services/pages-link-indexer.d.ts +36 -0
  479. package/dist/server/services/pages-link-indexer.js +474 -0
  480. package/dist/server/services/pages-link-indexer.js.map +1 -0
  481. package/dist/server/services/pages.d.ts +16 -0
  482. package/dist/server/services/pages.js +149 -0
  483. package/dist/server/services/pages.js.map +1 -0
  484. package/dist/server/services/plan.d.ts +59 -0
  485. package/dist/server/services/plan.js +459 -0
  486. package/dist/server/services/plan.js.map +1 -0
  487. package/dist/server/services/references.d.ts +17 -0
  488. package/dist/server/services/references.js +175 -0
  489. package/dist/server/services/references.js.map +1 -0
  490. package/dist/server/services/release.d.ts +146 -0
  491. package/dist/server/services/release.js +602 -0
  492. package/dist/server/services/release.js.map +1 -0
  493. package/dist/server/services/section-indexer.d.ts +20 -0
  494. package/dist/server/services/section-indexer.js +276 -0
  495. package/dist/server/services/section-indexer.js.map +1 -0
  496. package/dist/server/services/sections.d.ts +34 -0
  497. package/dist/server/services/sections.js +136 -0
  498. package/dist/server/services/sections.js.map +1 -0
  499. package/dist/server/services/skill-registry.d.ts +38 -0
  500. package/dist/server/services/skill-registry.js +171 -0
  501. package/dist/server/services/skill-registry.js.map +1 -0
  502. package/dist/server/services/slug.d.ts +7 -0
  503. package/dist/server/services/slug.js +41 -0
  504. package/dist/server/services/slug.js.map +1 -0
  505. package/dist/server/services/tags.d.ts +27 -0
  506. package/dist/server/services/tags.js +153 -0
  507. package/dist/server/services/tags.js.map +1 -0
  508. package/dist/server/services/todos-indexer.d.ts +21 -0
  509. package/dist/server/services/todos-indexer.js +123 -0
  510. package/dist/server/services/todos-indexer.js.map +1 -0
  511. package/dist/server/services/ui-view.d.ts +26 -0
  512. package/dist/server/services/ui-view.js +235 -0
  513. package/dist/server/services/ui-view.js.map +1 -0
  514. package/dist/server/services/versions.d.ts +59 -0
  515. package/dist/server/services/versions.js +181 -0
  516. package/dist/server/services/versions.js.map +1 -0
  517. package/dist/server/skills/brief-author/SKILL.md +117 -0
  518. package/dist/server/skills/layered-vertical-slices/SKILL.md +135 -0
  519. package/dist/server/skills/layered-vertical-slices/templates/index.md +97 -0
  520. package/dist/server/skills/layered-vertical-slices/templates/layer.md +42 -0
  521. package/dist/server/skills/layered-vertical-slices/templates/module.md +52 -0
  522. package/dist/server/skills/layered-vertical-slices/workflows/bootstrap.md +116 -0
  523. package/dist/server/skills/layered-vertical-slices/workflows/brief.md +154 -0
  524. package/dist/server/skills/layered-vertical-slices/workflows/daily.md +77 -0
  525. package/dist/server/ws/gateway.d.ts +10 -0
  526. package/dist/server/ws/gateway.js +35 -0
  527. package/dist/server/ws/gateway.js.map +1 -0
  528. package/dist/shared/anchor-pattern.d.ts +15 -0
  529. package/dist/shared/anchor-pattern.js +16 -0
  530. package/dist/shared/anchor-pattern.js.map +1 -0
  531. package/dist/shared/diagram-source-escape.d.ts +2 -0
  532. package/dist/shared/diagram-source-escape.js +19 -0
  533. package/dist/shared/diagram-source-escape.js.map +1 -0
  534. package/dist/shared/entities.d.ts +622 -0
  535. package/dist/shared/entities.js +9 -0
  536. package/dist/shared/entities.js.map +1 -0
  537. package/dist/shared/page-links.d.ts +40 -0
  538. package/dist/shared/page-links.js +2 -0
  539. package/dist/shared/page-links.js.map +1 -0
  540. package/dist/shared/plugin-host/types.d.ts +66 -0
  541. package/dist/shared/plugin-host/types.js +11 -0
  542. package/dist/shared/plugin-host/types.js.map +1 -0
  543. package/dist/shared/reference-extensions.d.ts +13 -0
  544. package/dist/shared/reference-extensions.js +17 -0
  545. package/dist/shared/reference-extensions.js.map +1 -0
  546. package/dist/shared/types.d.ts +86 -0
  547. package/dist/shared/types.js +2 -0
  548. package/dist/shared/types.js.map +1 -0
  549. package/dist/shared/xml-tags.d.ts +16 -0
  550. package/dist/shared/xml-tags.js +101 -0
  551. package/dist/shared/xml-tags.js.map +1 -0
  552. package/package.json +110 -0
@@ -0,0 +1,434 @@
1
+ import { pluginHost } from '../core/plugin-host/host.js';
2
+ function escapeAttr(v) {
3
+ return v.replace(/&/g, '&').replace(/"/g, '"');
4
+ }
5
+ function attrs(o) {
6
+ return Object.entries(o)
7
+ .filter(([, v]) => v !== undefined && v !== null && v !== '')
8
+ .map(([k, v]) => `${k}="${escapeAttr(String(v))}"`)
9
+ .join(' ');
10
+ }
11
+ function selfClose(name, attrsStr) {
12
+ return attrsStr ? `<${name} ${attrsStr}/>` : `<${name}/>`;
13
+ }
14
+ function buildEntityRows() {
15
+ // Each active plugin contributes one <entity> row; empty roleNoun = opt-out
16
+ // (legacy ui-view behaviour). Row body uses narrativeBlock when present,
17
+ // otherwise falls back to the plural roleNoun.
18
+ const rows = [];
19
+ for (const m of pluginHost.listEntities()) {
20
+ if (!m.systemPrompt.roleNoun)
21
+ continue;
22
+ const body = m.systemPrompt.narrativeBlock ?? m.systemPrompt.roleNoun;
23
+ rows.push(` <entity type="${m.type}">${body}</entity>`);
24
+ }
25
+ // rows.push(' <entity name="tag">Cross-cutting categorization (color, slug)</entity>');
26
+ return rows.join('\n');
27
+ }
28
+ function buildEntityEmbedTypeUnion() {
29
+ // Used inside the entity_embeds section, e.g. "endpoint|dto|database-table".
30
+ // Falls back to a sensible default when no plugins are active.
31
+ const types = pluginHost
32
+ .listEntities()
33
+ .filter((m) => m.systemPrompt.roleNoun)
34
+ .map((m) => m.type);
35
+ return types.length > 0 ? types.join('|') : 'entity';
36
+ }
37
+ function buildIdentity(projectName) {
38
+ const entityRows = buildEntityRows();
39
+ const embedTypeUnion = buildEntityEmbedTypeUnion();
40
+ return `<claude4spec_identity>
41
+ You are a specification writing assistant for project "${projectName}". The user is editing a specification that consists of markdown pages (in pages/) and structured entities stored in SQLite. You operate via built-in file tools and MCP servers exposed in \`<tooling/>\`.
42
+
43
+ <entities>
44
+ ${entityRows}
45
+ </entities>
46
+
47
+ <entity_embeds>
48
+ Pages can embed live entity views as self-closing XML tags. The Tiptap editor renders each tag as a rich UI widget that fetches fresh data from SQLite — the embed stays in sync as the entity changes; you do not duplicate field/column lists into prose.
49
+
50
+ Pick the tag that matches the rendering you need:
51
+
52
+ <inline_mention type="${embedTypeUnion}" slug="..."/>
53
+ Inline chip inside a sentence (small pill with type icon + name). Use when referring to an entity in flowing prose. Also valid inside DTO/endpoint descriptions.
54
+
55
+ <single_element type="..." slug="..."/>
56
+ Block card with the entity's full detail view (fields/columns, validation, relations). Use when this page documents that specific entity.
57
+
58
+ <element_list type="..." slugs="a,b,c"/>
59
+ Static block list of hand-picked entities, fixed order. Use when the reader should see exactly these N items.
60
+
61
+ <tagged_list type="..." tags="x,y" filter="and|or"/>
62
+ Dynamic block list filtered by tag — auto-updates as entities are tagged/untagged. Use to surface e.g. "all DTOs tagged auth" without maintaining the list manually.
63
+
64
+ <tagged_list_mixed tags="x" filter="and|or"/>
65
+ Like tagged_list, but spans all entity types (endpoints + DTOs + tables) sharing the tag(s). Use to show a cross-cutting feature slice.
66
+
67
+ Slugs are kebab-case. Prefer MCP tools (create_*, link_*, tag_entity) over hand-editing inline JSON in markdown.
68
+ </entity_embeds>
69
+
70
+ <entity_linking_rule severity="mandatory">
71
+ When an entity that exists in SQLite is named in prose, you MUST link it via an XML tag — never type the bare name. The link is the connective tissue M19 reads; prose-named entities are invisible to \`find_references\` / \`check_consistency\` and rot silently as slugs / paths change.
72
+
73
+ Banned in prose for SQLite-resident entities:
74
+ - Endpoint paths: \`\`\`GET /api/...\`\`\`, \`\`\`POST /api/...\`\`\`, etc. (any verb + path that resolves to an active endpoint slug).
75
+ - DTO class names: \`\`\`XyzRequest\`\`\`, \`\`\`XyzResponse\`\`\`, \`\`\`XyzDto\`\`\` (anything matching a DTO slug).
76
+ - Database table names referenced as live entities (e.g. \`\`\`chat_thread\`\`\` when discussing M05 storage — link the entity, not the identifier).
77
+ - AC slugs and any other active entity type registered with the plugin host.
78
+
79
+ Decision tree (pick the smallest tag that fits):
80
+ 1. Naming the entity inside a sentence → \`<inline_mention type slug/>\`.
81
+ 2. The current page documents this entity → \`<single_element type slug/>\`.
82
+ 3. Hand-picked fixed-order list of N entities → \`<element_list type slugs="a,b,c"/>\`.
83
+ 4. "All entities of one type tagged X" (auto-updating) → \`<tagged_list type tags="x"/>\`.
84
+ 5. Cross-type slice tagged X → \`<tagged_list_mixed tags="x"/>\`.
85
+
86
+ Exceptions (bare prose IS allowed):
87
+ - The path / class name itself is the SUBJECT of the sentence — discussing naming conventions, escape syntax, regex examples, the XML tag grammar.
88
+ - Documenting a NON-active entity (slug not registered, plugin disabled, or value is purely illustrative — e.g. example HTTP paths inside an L4 conventions section).
89
+ - Code fences showing literal source/SQL fragments where mid-fence XML embeds would be visual noise.
90
+
91
+ Pre-edit self-check (run BEFORE every \`Edit\` / \`Write\` on \`pages/\` or \`entities/\` content):
92
+ 1. Sweep your draft with regex \`(GET|POST|PATCH|PUT|DELETE)\\s+/\\S+\` and \`\\b[A-Z][a-zA-Z]+(Request|Response|Dto)\\b\`.
93
+ 2. For each hit: verify in SQLite (\`get_endpoint\` / \`get_dto\` / \`list_*\`). If the slug resolves → rewrite as the appropriate XML tag. If not → leave as prose AND state the exemption to yourself ("not a registered entity — bare prose intentional").
94
+ 3. Same sweep applies to your replies in chat — \`<inline_mention/>\` and \`<section_ref/>\` both render in react-markdown, so chip out the entity refs there too.
95
+
96
+ Severity is mandatory because the cost of compliance is low (one tag), the cost of drift is high (M19 blindness compounding across hundreds of pages).
97
+ </entity_linking_rule>
98
+
99
+ <entity_discovery severity="recommended">
100
+ Before answering a question, sketching a plan, or orienting yourself in a new area that touches a specific entity or tag, query the graph instead of reasoning from memory. The graph is the source of truth for "who uses X"; the model's pattern-matching is not. This is the general discipline; the stricter mutation variant is in \`<entity_change_protocol/>\`.
101
+
102
+ Four use-cases that should trigger discovery:
103
+ 1. **Question answering** — user asks "what uses X?" / "where does tag Y appear?" / "which AC verify auth endpoints?". Query graph first, then prose.
104
+ 2. **Planning** — before proposing a change in a plan (especially edits to M19 / core entities), enumerate current consumers. Plans drafted without discovery are blind to impact.
105
+ 3. **Orientation** — entering a new module / new tag for the first time: enumerate the entities in scope, which pages consume them, which dynamic lists surface them.
106
+ 4. **Mutation impact** — handled by the stricter \`<entity_change_protocol/>\` below; mandatory pre-mutation rather than recommended.
107
+
108
+ Four channels to use (cover all four when the question demands completeness; pick the relevant subset for narrower questions):
109
+ 1. \`find_references(type, slug)\` — direct XML refs (inline_mention / single_element / element_list, plus AC.verifies via consistency rule 9, plus structured endpoint↔dto SQLite links).
110
+ 2. **Dynamic tag refs** — \`tagged_list\` / \`tagged_list_mixed\` consumers, joined via entity tags. Until \`find_references\` supports \`{ includeTagMatches: true }\`, grep pages for \`tags="[^"]*{tag}[^"]*"\` per tag attached to the entity.
111
+ 3. **Structured links in SQLite** — \`get_endpoint(slug).dtos\` / \`get_dto(slug).endpoints\` / \`check_consistency\` rule 9 for \`ac.verifies\`.
112
+ 4. **Prose-drift sweep** — grep pages for the entity's HTTP path / DTO class name / table identifier to catch authors who skipped \`<entity_linking_rule/>\`.
113
+
114
+ Ground your answer / plan section / orientation summary on the returned set, not on what you remember. If you skipped discovery — say so explicitly ("not querying graph — answering from thread context"). Silent skipping looks identical to forgetting.
115
+
116
+ Four traps to avoid (each one has cost a real answer in this codebase):
117
+ 1. **Reflex on \`find_references\` when the topic is (type, slug) in SQLite.** No deliberation, no "maybe grep is enough". \`find_references\` is the first move; fallback channels are for when it doesn't apply.
118
+ 2. **Verbalize the fallback.** If the target is NOT a registered entity type (MCP tool name, conceptual domain term, file path) → explicit sentence: "X is not a registered entity → falling back to prose grep". Without verbalization it looks like rule-skipping.
119
+ 3. **Verify the slug before calling \`find_references\`.** Kebab-case vs snake_case vs PascalCase is a frequent trap (e.g. the table \`chat_thread\` has slug \`chat-thread\`). First \`list_*\` / \`get_*\`, then \`find_references\`. Otherwise you get a false \`[]\` and wrongly conclude "unused entity".
120
+ 4. **Empty result ≠ no consumers.** \`references: []\` only means "no direct XML refs". It does not close discovery — finish with channels 2 (dynamic tags), 3 (structured links), 4 (prose drift). Once \`find_references(..., { includeTagMatches: true })\` ships, channels 1+2 collapse into one call.
121
+ </entity_discovery>
122
+
123
+ <entity_change_protocol severity="mandatory">
124
+ Before any \`update_*\` / \`delete_*\` / slug rename / re-tag on an active entity, run the four-channel discovery from \`<entity_discovery/>\` AND present the impact list to the user BEFORE mutating. Strict-mode inherits the channel mechanics from the general discipline — the difference is obligatoriness and the user-facing report.
125
+
126
+ Protocol:
127
+ 1. Resolve the target slug — \`list_*\` / \`get_*\` first; never call \`find_references\` on an unverified slug (see trap 3 in \`<entity_discovery/>\`).
128
+ 2. Union the four channels into one set: direct refs + dynamic tag consumers + structured links + prose drift.
129
+ 3. Present an impact report to the user: which pages link this entity, which dynamic lists surface it, which other entities link to it structurally, where the prose mentions it. List counts AND specific anchors / file paths.
130
+ 4. For renames — propose propagation (M19 sync sweep) as part of the report. For deletes — show what will break (broken refs, AC.verifies pointing into the void). For re-tag — show which \`tagged_list\` / \`tagged_list_mixed\` consumers gain or lose this entity.
131
+ 5. Only mutate after the user has the report. "Just renaming a slug" is exactly the case where silent mutation breaks the most pages.
132
+
133
+ Stop-rule: do NOT mutate blind. The graph is the only source of truth about impact; your memory is not. Skipping the report for a "simple" change is the failure mode this rule exists to prevent.
134
+ </entity_change_protocol>
135
+
136
+ <tags>
137
+ Tags are cross-cutting buckets — not entities. A tag is a slug (kebab-case) + color, defined once globally and attached to any number of entities of any type. No FK, no owned data — purely a labeling layer that bundles entities into shared "feature slices" (e.g. "auth", "billing-v2") spanning endpoints + DTOs + tables.
138
+
139
+ Workflow:
140
+ 1. \`create_tag(slug, color)\` — define once globally.
141
+ 2. \`tag_entity(type, slug, tagSlug)\` — attach per-entity, any active type.
142
+ 3. Consume on a page via \`<tagged_list type="endpoint" tags="auth"/>\` (single-type) or \`<tagged_list_mixed tags="auth"/>\` (mixed) — embed auto-updates as entities are tagged/untagged.
143
+
144
+ Use tags for **dynamic, cross-cutting groupings** (feature slices). Use FK columns / DTO field references for **structural relationships** between specific entities.
145
+ </tags>
146
+
147
+ <todo_markers>
148
+ <todo comment="..."/>
149
+ Lightweight inline TODO marker. Lives only in markdown — never persisted to SQLite, never an entity. To survey open TODOs, Grep pages/ for \`<todo comment=\`.
150
+ </todo_markers>
151
+
152
+ <diagram_blocks>
153
+ <diagram format="mermaid" caption="...">
154
+ ...mermaid DSL...
155
+ </diagram>
156
+ Block-level Mermaid diagram. The body between the opening and closing tag is raw Mermaid source — NOT escaped in markdown (escaping only applies to the HTML \`source\` attribute roundtrip). \`format\` defaults to \`mermaid\`; \`caption\` is optional. Tiptap renders this as a live diagram with a fallback \`<pre>\` block on parse error. Use when a flow, sequence, or architecture diagram materially clarifies the prose; do not paste a diagram in lieu of explanation.
157
+
158
+ Example:
159
+ <diagram format="mermaid" caption="Auth flow">
160
+ flowchart TD
161
+ A[User] --> B[Login form]
162
+ B --> C{Valid creds?}
163
+ C -- yes --> D[Issue JWT]
164
+ C -- no --> E[Show error]
165
+ </diagram>
166
+
167
+ Insertable via slash command \`/diagram\` in page and plan editors.
168
+ </diagram_blocks>
169
+
170
+ <sections_and_anchors>
171
+ Sections (counted in \`<project sections=...>\`) are identified by an immutable 8-char anchor injected on the line before each markdown heading: \`<!-- anchor: xxxxxxxx -->\`. The indexer assigns anchors automatically — do not invent, edit, or strip them. When you rename a heading or move a section (within a page or to another file), keep the heading + anchor + body glued together; the indexer recognizes the move and the page-versioning subsystem records it. Never leave "(moved to MXX)" / "(see MNN)" breadcrumb prose behind — move history is owned by the versioning system, not by spec text.
172
+
173
+ To LINK to a section, embed \`<section_ref anchor="xxxxxxxx"/>\` inline. It renders as a clickable chip (heading text + smooth scroll / cross-page nav) in **both** rendering pipelines — Tiptap (the page editor) and react-markdown (your chat replies to the user, plus plan blame and annotation popups). So \`<section_ref/>\` is the right tool whether you are editing a markdown page in \`pages/\` or answering the user inline in this chat. Anchors are globally unique across \`pages/\`, so the anchor alone is sufficient — no page path needed. **Prefer \`<section_ref/>\` over prose like "see section X in pages/foo.md"** in markdown edits AND in chat replies — the ref survives heading rewrites and cross-file moves; plain prose does not, and stale "see X" pointers are exactly the kind of breadcrumb that the versioning system is supposed to make unnecessary. For whole-page links: in markdown pages use \`@pages/foo.md\` (page-only) or \`@pages/foo.md#xxxxxxxx\` (page + section context); in chat replies the \`@pages/...\` form does NOT render as a chip (only user messages and Tiptap parse it) — use a plain markdown link with a readable label, or point at a specific section via \`<section_ref/>\`. To discover an anchor, Read the page and grab the \`<!-- anchor: ... -->\` line under the heading you want to target.
174
+ </sections_and_anchors>
175
+
176
+ <current_page_handling>
177
+ The \`<current_page>\` tag shows what the user is currently viewing. For pages longer than ${CURRENT_PAGE_PREVIEW_LINES} lines, only the first ${CURRENT_PAGE_PREVIEW_LINES} are inlined as a preview (see preview_lines/total_lines attributes). When you need content beyond the preview, Read the page from disk.
178
+ </current_page_handling>
179
+
180
+ <annotation_handling>
181
+ When the request includes \`<annotations>\`, treat them as the primary context for the user's message. Address each annotation specifically in your response. If an annotation references a page different from \`<current_page>\`, Read that page first before responding.
182
+ </annotation_handling>
183
+ </claude4spec_identity>`;
184
+ }
185
+ const PLAN_TOOLS_USAGE = `<plan_tools_usage>
186
+ plan-tools MCP server is scoped automatically to this thread (no threadId param):
187
+ - get_plan — read current plan state
188
+ - update_plan (action: replace | append | insert_after_section) — edit the plan
189
+ - list_plan_versions, get_plan_version — inspect history
190
+ Inside plan_mode: persist the plan via update_plan instead of writing it as prose.
191
+ Outside plan_mode: use update_plan when the user explicitly requests a deployment plan or architectural proposal.
192
+ plan-tools are NOT subject to plan_mode read-only restrictions — the plan is a separate entity from spec content.
193
+ </plan_tools_usage>`;
194
+ /**
195
+ * M21: usage contract for `brief-tools` MCP server (analog `PLAN_TOOLS_USAGE`).
196
+ * Mounted only when this chat thread has `context_type='brief'`. The full
197
+ * editorial doctrine lives in the bundled skill `brief-author` (loaded as
198
+ * project_skill); this block describes the tool surface so the agent knows
199
+ * what is callable in this thread.
200
+ */
201
+ const BRIEF_TOOLS_USAGE = `<brief_tools_usage>
202
+ brief-tools MCP server is scoped automatically to this brief (no path param):
203
+ - get_brief — read current brief { frontmatter, body, content, hash }
204
+ - update_brief (action: replace | append | insert_after_section) — edit the body
205
+ * frontmatter is IMMUTABLE for the agent (type, from_release, to_release, generated_at, generator_version)
206
+ * pass expectedHash from get_brief for optimistic concurrency (mismatch → BRIEF_CONFLICT)
207
+ * unknown anchor → fallback append-at-end with warning
208
+ - list_brief_versions, get_brief_version — inspect history (page_version, M17)
209
+ You also have read-only release-tools (get_release, get_release_diff, list_releases) for grounding the narrative.
210
+ You do NOT have filesystem access (no Read/Write/Edit/Glob/Grep/Bash). Brief content flows through get_brief / update_brief only.
211
+ </brief_tools_usage>`;
212
+ const PLAN_MODE = `<claude4spec_plan_mode>
213
+ Plan Mode is ACTIVE. Investigate and propose — do not modify.
214
+
215
+ The plan you draft must conform to the project skill referenced in <project_skill/>. Before drafting or updating the plan, ensure Skill(slug) has been called this turn — its conventions (module/layer structure, naming, file layout, quality rules) constrain every line of the plan. If the user's request appears to violate those conventions, surface the conflict in the plan rather than silently working around it.
216
+
217
+ Forbidden (mutating):
218
+ - Built-in: Edit, Write, MultiEdit, Bash (writing), NotebookEdit
219
+ - MCP: any create_*, update_*, delete_*, link_*, unlink_*, tag_entity, untag_entity
220
+
221
+ Allowed (read-only):
222
+ - Built-in: Read, Grep, Glob, WebFetch, WebSearch, Task, TodoWrite
223
+ - MCP: list_*, get_*, find_*, check_consistency
224
+
225
+ plan-tools (get_plan, update_plan, list_plan_versions, get_plan_version) are EXEMPT — use update_plan to persist the plan rather than writing it as prose in your reply.
226
+
227
+ End your response with a concrete, numbered plan the user can review and approve before execution. If a request clearly requires mutation, acknowledge and describe what you would do — do not execute.
228
+ </claude4spec_plan_mode>`;
229
+ function buildTooling(planToolsAvailable) {
230
+ const lines = [
231
+ `<tooling>`,
232
+ ` <builtin>Read, Write, Edit, MultiEdit, Glob, Grep, Bash, WebFetch, WebSearch, Task, TodoWrite, Skill</builtin>`,
233
+ ];
234
+ for (const m of pluginHost.listEntities()) {
235
+ if (!m.systemPrompt.mcpToolsLine)
236
+ continue;
237
+ // mcpToolsLine format: "{server-name}: {tool, tool, ...}"
238
+ const colonIdx = m.systemPrompt.mcpToolsLine.indexOf(':');
239
+ if (colonIdx === -1)
240
+ continue;
241
+ const serverName = m.systemPrompt.mcpToolsLine.slice(0, colonIdx).trim();
242
+ const toolList = m.systemPrompt.mcpToolsLine.slice(colonIdx + 1).trim();
243
+ lines.push(` <mcp name="${serverName}">${toolList}</mcp>`);
244
+ }
245
+ lines.push(` <mcp name="reference-tools">create_tag, update_tag, delete_tag, list_tags, tag_entity, untag_entity, find_references, check_consistency</mcp>`);
246
+ if (planToolsAvailable) {
247
+ lines.push(` <mcp name="plan-tools">get_plan, update_plan, list_plan_versions, get_plan_version</mcp>`);
248
+ }
249
+ lines.push(`</tooling>`);
250
+ return lines.join('\n');
251
+ }
252
+ function buildProjectSkill(ws) {
253
+ return [
254
+ `<project_skill ${attrs({ slug: ws.slug, title: ws.title })}>`,
255
+ `Skill "${ws.title}" (slug "${ws.slug}") contains the BINDING project specification — module/layer structure, file layout, naming, workflow, and quality rules. Every page edit, plan, entity/module change, and structural answer must conform to it.`,
256
+ ``,
257
+ `Required behavior:`,
258
+ ` 1. Before your first tool call in this thread, call Skill("${ws.slug}").`,
259
+ ` 2. Re-call Skill("${ws.slug}") whenever you transition from plan mode into execution, even if loaded earlier.`,
260
+ ` 3. Treat its content as authoritative — if a user request seems to contradict it, surface the conflict rather than silently overriding the convention.`,
261
+ `</project_skill>`,
262
+ ].join('\n');
263
+ }
264
+ /**
265
+ * M21 brief-context system prompt. Minimal frame: identity, brief-tools usage,
266
+ * brief-author skill (genre — bundled), writing-style skill (methodology —
267
+ * supplies workflows/brief.md), brief snapshot, optional annotations.
268
+ * Excludes pluginHost tooling, plan tools, entity counters — agent operates
269
+ * on a single artifact with a reduced surface.
270
+ */
271
+ function buildBriefSystemPrompt(input) {
272
+ const parts = [];
273
+ parts.push([
274
+ `<claude4spec_brief_identity>`,
275
+ `You are operating in BRIEF mode for project "${input.projectName}".`,
276
+ `cwd: ${input.cwd}`,
277
+ `Your sole task is editorial work on a single brief artifact (markdown narrative summarising what changed between two releases).`,
278
+ `Use brief-tools (get_brief / update_brief / list_brief_versions / get_brief_version) and read-only release-tools.`,
279
+ `You have NO filesystem access (no Read/Write/Edit/Glob/Grep/Bash) and NO plan/entity tools.`,
280
+ `</claude4spec_brief_identity>`,
281
+ ].join('\n'));
282
+ parts.push([
283
+ `<self_contained_invariant>`,
284
+ `The brief file is consumed by TWO audiences with very different capabilities:`,
285
+ ``,
286
+ ` 1. Human reader in the claude4spec web UI: can click references, view rendered Tiptap, navigate to source entities/pages.`,
287
+ ` 2. Coding agent in some OTHER terminal (Claude Code, Cursor, plain \`cat brief.md | llm\`, agent in another repo, CI bot reading the file).`,
288
+ ` Has ONLY the raw bytes of this file. NO database, NO MCP server, NO claude4spec UI, NO claude4spec CLI assumed.`,
289
+ ``,
290
+ `The second audience is load-bearing — it is what justifies storing the brief on disk instead of in a DB. If the brief is unintelligible without claude4spec running, the artifact has failed its primary purpose.`,
291
+ ``,
292
+ `Therefore the brief MUST be self-contained. The output of update_brief is binding regardless of audience:`,
293
+ ``,
294
+ ` - INLINE the actual content of every change. Show field names, types, before/after fragments verbatim. Never write "the User DTO got a new field" without showing the field. Never write "see release diff" — quote the diff fragment.`,
295
+ ` - DO NOT use claude4spec-internal reference grammar (\`<single_element>\`, \`<inline_mention>\`, \`<element_list>\`, \`<tagged_list>\`, \`<tagged_list_mixed>\`, \`@page.md\` mentions). Those resolve ONLY inside the claude4spec UI; in a second-audience terminal they are literal XML/markdown noise that confuses, not helps.`,
296
+ ` - Use plain prose when naming things: "the \`auth/login\` endpoint (POST)", "the \`User\` DTO field \`email: string\`", "page \`pages/auth/flow.md\`".`,
297
+ ` - Write file paths, function signatures, SQL fragments, and code snippets verbatim where relevant. The reader cannot fetch them on demand.`,
298
+ ` - The "For implementers" section must list CONCRETE edit targets: file paths, function names, SQL/migration snippets — actionable without further investigation.`,
299
+ ``,
300
+ `**Describe the SYSTEM, not the spec edits.** The brief is about how the specified system behaves now vs. before — not about which markdown files gained/lost sections. Editorial mechanics belong in version history, not in the brief:`,
301
+ ``,
302
+ ` - GOOD: "Brief threads whitelist their toolset — only \`brief-tools\` and \`release-tools\` are mounted; plan/entity MCPs are silently omitted to keep the editorial agent on its lane."`,
303
+ ` - BAD: "Section 'Tool whitelist' was added to \`m05-chat-agent.md\` between 'Context registry' and 'System prompt builder'."`,
304
+ ``,
305
+ ` - GOOD: "New \`chat_thread.context_type\` column (\`CHECK chat|brief\`, default \`'chat'\`). Existing threads backfill to \`'chat'\` on migration."`,
306
+ ` - BAD: "Migration 022 was added under \`db/migrations/\`."`,
307
+ ``,
308
+ `If a diff is purely editorial — anchor added, section reordered without content change, typo fix, formatting, prose smoothing, comment moved, heading renamed without semantic shift — DROP it from the brief. It does not earn space. The reader does not care that page X gained a \`<!-- anchor -->\` line; they care what the system now does differently.`,
309
+ ``,
310
+ `When this invariant conflicts with brevity, choose self-containment. A longer brief that stands alone beats a terse brief that requires claude4spec to interpret.`,
311
+ `</self_contained_invariant>`,
312
+ ].join('\n'));
313
+ parts.push([
314
+ `<tooling>`,
315
+ ` <mcp name="brief-tools">get_brief, update_brief, list_brief_versions, get_brief_version</mcp>`,
316
+ ` <mcp name="release-tools">get_release, get_release_diff, list_releases</mcp>`,
317
+ `</tooling>`,
318
+ ].join('\n'));
319
+ parts.push(BRIEF_TOOLS_USAGE);
320
+ parts.push(buildProjectSkill({ slug: 'brief-author', title: 'Brief Author' }));
321
+ // Writing-style skill supplies methodology-specific brief guidance
322
+ // (filter rules, inlining patterns, "For implementers" structure)
323
+ // via its `workflows/brief.md`. Without it, agent uses brief-author
324
+ // genre rules alone — generic but free of writing-style-specific leakage.
325
+ if (input.writingStyle) {
326
+ parts.push(buildProjectSkill({ slug: input.writingStyle.slug, title: input.writingStyle.title }));
327
+ parts.push([
328
+ `<writing_style_brief_workflow ${attrs({ slug: input.writingStyle.slug })}>`,
329
+ `For brief generation in this writing style, read \`workflows/brief.md\` within Skill("${input.writingStyle.slug}") if present. It defines which RawDelta entries are spec-format conventions (drop), how to inline this style's entity types, and the "For implementers" structure for this style. Read it after Skill("brief-author").`,
330
+ `</writing_style_brief_workflow>`,
331
+ ].join('\n'));
332
+ }
333
+ if (input.brief) {
334
+ const fm = input.brief.frontmatter;
335
+ parts.push([
336
+ `<current_brief ${attrs({
337
+ path: input.brief.path,
338
+ from_release: fm.from_release ?? '(initial)',
339
+ to_release: fm.to_release,
340
+ implemented: fm.implemented ? 'true' : 'false',
341
+ hash: input.brief.hash,
342
+ })}>`,
343
+ input.brief.content,
344
+ `</current_brief>`,
345
+ ].join('\n'));
346
+ }
347
+ if (input.annotations.length > 0) {
348
+ parts.push(buildAnnotations(input.annotations));
349
+ }
350
+ return parts.join('\n\n');
351
+ }
352
+ const CURRENT_PAGE_PREVIEW_LINES = 40;
353
+ function buildCurrentPage(path, body) {
354
+ if (body === null) {
355
+ return selfClose('current_page', attrs({ path, unavailable: 'true' }));
356
+ }
357
+ if (body.trim() === '') {
358
+ return selfClose('current_page', attrs({ path, empty: 'true' }));
359
+ }
360
+ const lines = body.split('\n');
361
+ const totalLines = lines.length;
362
+ if (totalLines <= CURRENT_PAGE_PREVIEW_LINES) {
363
+ return `<current_page ${attrs({ path, total_lines: totalLines })}>\n${body}\n</current_page>`;
364
+ }
365
+ const preview = lines.slice(0, CURRENT_PAGE_PREVIEW_LINES).join('\n');
366
+ const remaining = totalLines - CURRENT_PAGE_PREVIEW_LINES;
367
+ return `<current_page ${attrs({
368
+ path,
369
+ total_lines: totalLines,
370
+ preview_lines: `1-${CURRENT_PAGE_PREVIEW_LINES}`,
371
+ })}>
372
+ ${preview}
373
+ [... ${remaining} more line${remaining === 1 ? '' : 's'} truncated. Read ${path} to load the full page.]
374
+ </current_page>`;
375
+ }
376
+ function buildAnnotations(annotations) {
377
+ const lines = [`<annotations>`];
378
+ for (const a of annotations) {
379
+ lines.push(` <annotation ${attrs({ page: a.page, comment: a.comment ?? '' })}>`, a.text, ` </annotation>`);
380
+ }
381
+ lines.push(`</annotations>`);
382
+ return lines.join('\n');
383
+ }
384
+ export function buildSystemPrompt(input) {
385
+ const { projectName, cwd, pagesDir, currentPagePath, currentPageBody, pageCount, entityCounts, tagCount, sectionCount, annotations = [], planMode = false, currentPlan = null, planToolsAvailable = false, writingStyle = null, contextType = 'chat', brief = null, } = input;
386
+ // M21 m05ctxreg: brief context uses a completely different prompt frame —
387
+ // no plugin tooling, no entity counters, no plan tools. Just identity,
388
+ // brief-tools usage, brief-author skill (genre) + writing-style skill
389
+ // (methodology, supplies workflows/brief.md), and the brief snapshot.
390
+ if (contextType === 'brief') {
391
+ return buildBriefSystemPrompt({ projectName, cwd, brief, annotations, writingStyle });
392
+ }
393
+ const parts = [];
394
+ parts.push(buildIdentity(projectName));
395
+ // Project self-close — env metadata (cwd, pagesDir) before counters, then
396
+ // entity attrs in displayOrder, with `tags` last:
397
+ // (name, cwd, pagesDir, pages, sections, [entities...], tags).
398
+ const projectAttrs = {
399
+ name: projectName,
400
+ cwd,
401
+ pagesDir,
402
+ pages: pageCount,
403
+ sections: sectionCount,
404
+ };
405
+ for (const m of pluginHost.listEntities()) {
406
+ if (!m.systemPrompt.roleNoun)
407
+ continue; // opt-out (legacy ui-view)
408
+ const label = m.systemPrompt.countStat.label;
409
+ projectAttrs[label] = entityCounts[m.type] ?? 0;
410
+ }
411
+ projectAttrs.tags = tagCount;
412
+ parts.push(selfClose('project', attrs(projectAttrs)));
413
+ parts.push(buildTooling(planToolsAvailable));
414
+ if (planToolsAvailable) {
415
+ parts.push(PLAN_TOOLS_USAGE);
416
+ }
417
+ if (writingStyle) {
418
+ parts.push(buildProjectSkill(writingStyle));
419
+ }
420
+ if (currentPagePath) {
421
+ parts.push(buildCurrentPage(currentPagePath, currentPageBody));
422
+ }
423
+ if (annotations.length > 0) {
424
+ parts.push(buildAnnotations(annotations));
425
+ }
426
+ if (currentPlan && currentPlan.content.trim().length > 0) {
427
+ parts.push(`<current_plan ${attrs({ version: currentPlan.currentVersion })}>\n${currentPlan.content}\n</current_plan>`);
428
+ }
429
+ if (planMode) {
430
+ parts.push(PLAN_MODE);
431
+ }
432
+ return parts.join('\n\n');
433
+ }
434
+ //# sourceMappingURL=chat-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-context.js","sourceRoot":"","sources":["../../../src/server/services/chat-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAwBzD,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,KAAK,CAAC,CAAqD;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;SAC5D,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SAClD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,QAAgB;IAC/C,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC;AAC5D,CAAC;AAED,SAAS,eAAe;IACtB,4EAA4E;IAC5E,yEAAyE;IACzE,+CAA+C;IAC/C,MAAM,IAAI,GAAa,EAAE,CA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I,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzD,KAAK,CAAC,IAAI,CACR,iBAAiB,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,MAAM,WAAW,CAAC,OAAO,mBAAmB,CAC5G,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type Database from 'better-sqlite3';
2
+ import type { ChatContextType, ChatMessage, ChatMessageStatus, ChatRole, ChatSubagentTask, ChatThread, ChatThreadMeta, TodoItem, UsageStats } from '../../shared/entities.js';
3
+ export declare class ChatService {
4
+ private db;
5
+ constructor(db: Database.Database);
6
+ createThread(title?: string | null, opts?: {
7
+ contextType?: ChatContextType;
8
+ briefPath?: string | null;
9
+ }): ChatThread;
10
+ /** M21: list threads attached to a brief (path-keyed lookup). */
11
+ listThreadsForBrief(briefPath: string): ChatThreadMeta[];
12
+ /** M21: count threads for a brief (cheap version of listThreadsForBrief for list UI). */
13
+ threadCountForBrief(briefPath: string): number;
14
+ listThreads(): ChatThreadMeta[];
15
+ getThread(id: string, limit?: number, offset?: number): {
16
+ thread: ChatThread;
17
+ messages: ChatMessage[];
18
+ subagentTasks: ChatSubagentTask[];
19
+ } | null;
20
+ getThreadMeta(id: string): ChatThread | null;
21
+ deleteThread(id: string): {
22
+ deleted: true;
23
+ };
24
+ addMessage(threadId: string, role: ChatRole, content: string, toolName?: string | null, toolId?: string | null, subagentTaskId?: string | null, planMode?: boolean, status?: ChatMessageStatus): ChatMessage;
25
+ startSubagentTask(threadId: string, taskId: string, description: string, toolUseId: string | null): void;
26
+ updateSubagentTaskProgress(threadId: string, taskId: string, description: string): void;
27
+ completeSubagentTask(threadId: string, taskId: string, status: string, summary: string | null): void;
28
+ listSubagentTasks(threadId: string): ChatSubagentTask[];
29
+ getMessages(threadId: string, limit?: number, offset?: number): ChatMessage[];
30
+ updateTitle(threadId: string, title: string): void;
31
+ setLastSessionId(threadId: string, sessionId: string): void;
32
+ setInitialSystemPrompt(threadId: string, prompt: string): void;
33
+ getInitialSystemPrompt(threadId: string): string | null;
34
+ setLastUsage(threadId: string, usage: UsageStats): void;
35
+ attachTurnUsage(threadId: string, messageId: number, usage: UsageStats): void;
36
+ setLastContextSize(threadId: string, contextSize: number): void;
37
+ attachTurnContextSize(threadId: string, messageId: number, contextSize: number): void;
38
+ markToolUseComplete(threadId: string, toolUseId: string): void;
39
+ finalizeStreamingRows(threadId: string): void;
40
+ finalizeAllStreamingRows(): void;
41
+ updateCurrentTodoItems(threadId: string, items: TodoItem[] | null): void;
42
+ updateThreadSettings(threadId: string, patch: {
43
+ planMode?: boolean;
44
+ }): ChatThread;
45
+ private findThread;
46
+ private getThreadRow;
47
+ private hydrateThread;
48
+ private hydrateMessage;
49
+ private hydrateSubagentTask;
50
+ }