@proflandrigan/shards 1.1.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 (397) hide show
  1. package/README.md +475 -0
  2. package/package.json +37 -0
  3. package/src/agents/academic.md +276 -0
  4. package/src/agents/ai-engineer.md +377 -0
  5. package/src/agents/analytics-engineer.md +364 -0
  6. package/src/agents/applied-ml-scientist.md +410 -0
  7. package/src/agents/backend-engineer.md +255 -0
  8. package/src/agents/bi-engineer.md +333 -0
  9. package/src/agents/data-analyst.md +343 -0
  10. package/src/agents/data-engineer.md +260 -0
  11. package/src/agents/data-modeller.md +386 -0
  12. package/src/agents/data-scientist.md +366 -0
  13. package/src/agents/deep-learning-engineer.md +389 -0
  14. package/src/agents/ml-engineer.md +424 -0
  15. package/src/agents/mlops-engineer.md +339 -0
  16. package/src/agents/researcher.md +187 -0
  17. package/src/agents/specific_instructions/academic/critical_review.md +263 -0
  18. package/src/agents/specific_instructions/academic/report.md +113 -0
  19. package/src/agents/specific_instructions/ai_engineer/advise.md +162 -0
  20. package/src/agents/specific_instructions/ai_engineer/bi_engineer_handoff.md +86 -0
  21. package/src/agents/specific_instructions/ai_engineer/experiment.md +471 -0
  22. package/src/agents/specific_instructions/ai_engineer/experiment_ui_mode.md +44 -0
  23. package/src/agents/specific_instructions/ai_engineer/phases/index.md +45 -0
  24. package/src/agents/specific_instructions/ai_engineer/phases/phase-1.md +55 -0
  25. package/src/agents/specific_instructions/ai_engineer/phases/phase-2.md +86 -0
  26. package/src/agents/specific_instructions/ai_engineer/phases/phase-3.md +96 -0
  27. package/src/agents/specific_instructions/ai_engineer/phases/phase-4.md +138 -0
  28. package/src/agents/specific_instructions/ai_engineer/phases/phase-5.md +157 -0
  29. package/src/agents/specific_instructions/ai_engineer/phases/phase-6.md +196 -0
  30. package/src/agents/specific_instructions/ai_engineer/phases/phase-7.md +313 -0
  31. package/src/agents/specific_instructions/ai_engineer/phases.md +1011 -0
  32. package/src/agents/specific_instructions/ai_engineer/prompt_lab.md +161 -0
  33. package/src/agents/specific_instructions/ai_engineer/prompt_lab_ui_mode.md +28 -0
  34. package/src/agents/specific_instructions/ai_engineer/research.md +393 -0
  35. package/src/agents/specific_instructions/ai_engineer/research_ui_mode.md +66 -0
  36. package/src/agents/specific_instructions/ai_engineer/review.md +159 -0
  37. package/src/agents/specific_instructions/ai_engineer/validation_checklist.md +182 -0
  38. package/src/agents/specific_instructions/analytics_engineer/advise.md +155 -0
  39. package/src/agents/specific_instructions/analytics_engineer/bi_engineer_handoff.md +91 -0
  40. package/src/agents/specific_instructions/analytics_engineer/data_analyst_handoff.md +84 -0
  41. package/src/agents/specific_instructions/analytics_engineer/deep_phases.md +818 -0
  42. package/src/agents/specific_instructions/analytics_engineer/phases_deep/index.md +24 -0
  43. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-1.md +77 -0
  44. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-2.md +106 -0
  45. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-3.md +93 -0
  46. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-4.md +79 -0
  47. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-5.md +61 -0
  48. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-6.md +45 -0
  49. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-7.md +235 -0
  50. package/src/agents/specific_instructions/analytics_engineer/phases_deep/phase-8.md +221 -0
  51. package/src/agents/specific_instructions/analytics_engineer/phases_quick/index.md +19 -0
  52. package/src/agents/specific_instructions/analytics_engineer/phases_quick/phase-1.md +47 -0
  53. package/src/agents/specific_instructions/analytics_engineer/phases_quick/phase-2.md +78 -0
  54. package/src/agents/specific_instructions/analytics_engineer/quick_phases.md +112 -0
  55. package/src/agents/specific_instructions/analytics_engineer/review.md +167 -0
  56. package/src/agents/specific_instructions/analytics_engineer/service_mode.md +369 -0
  57. package/src/agents/specific_instructions/analytics_engineer/ui_mode.md +45 -0
  58. package/src/agents/specific_instructions/analytics_engineer/update.md +162 -0
  59. package/src/agents/specific_instructions/analytics_engineer/validation_checklist.md +121 -0
  60. package/src/agents/specific_instructions/applied_ml_scientist/advise.md +143 -0
  61. package/src/agents/specific_instructions/applied_ml_scientist/phases/index.md +21 -0
  62. package/src/agents/specific_instructions/applied_ml_scientist/phases/phase-1.md +51 -0
  63. package/src/agents/specific_instructions/applied_ml_scientist/phases/phase-2.md +66 -0
  64. package/src/agents/specific_instructions/applied_ml_scientist/phases/phase-3.md +113 -0
  65. package/src/agents/specific_instructions/applied_ml_scientist/phases/phase-4.md +104 -0
  66. package/src/agents/specific_instructions/applied_ml_scientist/phases/phase-5.md +156 -0
  67. package/src/agents/specific_instructions/applied_ml_scientist/phases.md +428 -0
  68. package/src/agents/specific_instructions/applied_ml_scientist/research.md +379 -0
  69. package/src/agents/specific_instructions/applied_ml_scientist/review.md +142 -0
  70. package/src/agents/specific_instructions/applied_ml_scientist/validation_checklist.md +136 -0
  71. package/src/agents/specific_instructions/backend_engineer/clean.md +149 -0
  72. package/src/agents/specific_instructions/backend_engineer/review.md +91 -0
  73. package/src/agents/specific_instructions/backend_engineer/review_checklist.md +54 -0
  74. package/src/agents/specific_instructions/backend_engineer/service_mode.md +67 -0
  75. package/src/agents/specific_instructions/bi_engineer/advise.md +137 -0
  76. package/src/agents/specific_instructions/bi_engineer/data_analyst_handoff.md +77 -0
  77. package/src/agents/specific_instructions/bi_engineer/incoming_handoff.md +45 -0
  78. package/src/agents/specific_instructions/bi_engineer/phases/index.md +20 -0
  79. package/src/agents/specific_instructions/bi_engineer/phases/phase-1.md +164 -0
  80. package/src/agents/specific_instructions/bi_engineer/phases/phase-2.md +92 -0
  81. package/src/agents/specific_instructions/bi_engineer/phases/phase-3.md +121 -0
  82. package/src/agents/specific_instructions/bi_engineer/phases/phase-4.md +106 -0
  83. package/src/agents/specific_instructions/bi_engineer/phases.md +451 -0
  84. package/src/agents/specific_instructions/bi_engineer/review.md +166 -0
  85. package/src/agents/specific_instructions/bi_engineer/update.md +147 -0
  86. package/src/agents/specific_instructions/bi_engineer/validation_checklist.md +124 -0
  87. package/src/agents/specific_instructions/data_analyst/advise.md +138 -0
  88. package/src/agents/specific_instructions/data_analyst/explain.md +221 -0
  89. package/src/agents/specific_instructions/data_analyst/incoming_handoff.md +40 -0
  90. package/src/agents/specific_instructions/data_analyst/phases/index.md +20 -0
  91. package/src/agents/specific_instructions/data_analyst/phases/phase-1.md +159 -0
  92. package/src/agents/specific_instructions/data_analyst/phases/phase-2.md +112 -0
  93. package/src/agents/specific_instructions/data_analyst/phases/phase-3.md +265 -0
  94. package/src/agents/specific_instructions/data_analyst/phases/phase-4.md +100 -0
  95. package/src/agents/specific_instructions/data_analyst/phases.md +501 -0
  96. package/src/agents/specific_instructions/data_analyst/review.md +138 -0
  97. package/src/agents/specific_instructions/data_analyst/ui_mode.md +26 -0
  98. package/src/agents/specific_instructions/data_analyst/update.md +144 -0
  99. package/src/agents/specific_instructions/data_analyst/validation_checklist.md +95 -0
  100. package/src/agents/specific_instructions/data_engineer/advise.md +137 -0
  101. package/src/agents/specific_instructions/data_engineer/phases.md +466 -0
  102. package/src/agents/specific_instructions/data_engineer/phases_deep/index.md +23 -0
  103. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-1.md +49 -0
  104. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-2.md +93 -0
  105. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-3.md +55 -0
  106. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-4.md +48 -0
  107. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-5.md +40 -0
  108. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-6.md +102 -0
  109. package/src/agents/specific_instructions/data_engineer/phases_deep/phase-7.md +87 -0
  110. package/src/agents/specific_instructions/data_engineer/phases_quick/index.md +19 -0
  111. package/src/agents/specific_instructions/data_engineer/phases_quick/phase-1.md +45 -0
  112. package/src/agents/specific_instructions/data_engineer/phases_quick/phase-2.md +54 -0
  113. package/src/agents/specific_instructions/data_engineer/review.md +135 -0
  114. package/src/agents/specific_instructions/data_engineer/validation_checklist.md +136 -0
  115. package/src/agents/specific_instructions/data_modeller/advise.md +137 -0
  116. package/src/agents/specific_instructions/data_modeller/phases.md +581 -0
  117. package/src/agents/specific_instructions/data_modeller/phases_deep/index.md +23 -0
  118. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-1.md +52 -0
  119. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-2.md +113 -0
  120. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-3.md +47 -0
  121. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-4.md +51 -0
  122. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-5.md +45 -0
  123. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-6.md +105 -0
  124. package/src/agents/specific_instructions/data_modeller/phases_deep/phase-7.md +136 -0
  125. package/src/agents/specific_instructions/data_modeller/phases_quick/index.md +19 -0
  126. package/src/agents/specific_instructions/data_modeller/phases_quick/phase-1.md +47 -0
  127. package/src/agents/specific_instructions/data_modeller/phases_quick/phase-2.md +65 -0
  128. package/src/agents/specific_instructions/data_modeller/review.md +141 -0
  129. package/src/agents/specific_instructions/data_modeller/service_mode.md +218 -0
  130. package/src/agents/specific_instructions/data_modeller/validation_checklist.md +125 -0
  131. package/src/agents/specific_instructions/data_scientist/advise.md +158 -0
  132. package/src/agents/specific_instructions/data_scientist/bi_engineer_handoff.md +63 -0
  133. package/src/agents/specific_instructions/data_scientist/experiment.md +482 -0
  134. package/src/agents/specific_instructions/data_scientist/experiment_ui_mode.md +44 -0
  135. package/src/agents/specific_instructions/data_scientist/explain.md +247 -0
  136. package/src/agents/specific_instructions/data_scientist/greenfield_data.md +35 -0
  137. package/src/agents/specific_instructions/data_scientist/ml_engineer_handoff.md +52 -0
  138. package/src/agents/specific_instructions/data_scientist/notebook_walkthrough.md +76 -0
  139. package/src/agents/specific_instructions/data_scientist/phases/index.md +24 -0
  140. package/src/agents/specific_instructions/data_scientist/phases/phase-1.md +45 -0
  141. package/src/agents/specific_instructions/data_scientist/phases/phase-2.md +67 -0
  142. package/src/agents/specific_instructions/data_scientist/phases/phase-3.md +89 -0
  143. package/src/agents/specific_instructions/data_scientist/phases/phase-4.md +143 -0
  144. package/src/agents/specific_instructions/data_scientist/phases/phase-5.md +71 -0
  145. package/src/agents/specific_instructions/data_scientist/phases/phase-6.md +239 -0
  146. package/src/agents/specific_instructions/data_scientist/phases/phase-7.md +207 -0
  147. package/src/agents/specific_instructions/data_scientist/phases.md +651 -0
  148. package/src/agents/specific_instructions/data_scientist/research.md +345 -0
  149. package/src/agents/specific_instructions/data_scientist/research_ui_mode.md +52 -0
  150. package/src/agents/specific_instructions/data_scientist/review.md +136 -0
  151. package/src/agents/specific_instructions/data_scientist/service_mode.md +247 -0
  152. package/src/agents/specific_instructions/data_scientist/validation_checklist.md +183 -0
  153. package/src/agents/specific_instructions/deep_learning_engineer/advise.md +145 -0
  154. package/src/agents/specific_instructions/deep_learning_engineer/phases/index.md +21 -0
  155. package/src/agents/specific_instructions/deep_learning_engineer/phases/phase-1.md +74 -0
  156. package/src/agents/specific_instructions/deep_learning_engineer/phases/phase-2.md +98 -0
  157. package/src/agents/specific_instructions/deep_learning_engineer/phases/phase-3.md +76 -0
  158. package/src/agents/specific_instructions/deep_learning_engineer/phases/phase-4.md +128 -0
  159. package/src/agents/specific_instructions/deep_learning_engineer/phases/phase-5.md +292 -0
  160. package/src/agents/specific_instructions/deep_learning_engineer/phases.md +567 -0
  161. package/src/agents/specific_instructions/deep_learning_engineer/research.md +389 -0
  162. package/src/agents/specific_instructions/deep_learning_engineer/review.md +155 -0
  163. package/src/agents/specific_instructions/deep_learning_engineer/validation_checklist.md +147 -0
  164. package/src/agents/specific_instructions/ml_engineer/advise.md +174 -0
  165. package/src/agents/specific_instructions/ml_engineer/bi_engineer_handoff.md +71 -0
  166. package/src/agents/specific_instructions/ml_engineer/experiment.md +474 -0
  167. package/src/agents/specific_instructions/ml_engineer/experiment_ui_mode.md +44 -0
  168. package/src/agents/specific_instructions/ml_engineer/notebook_walkthrough.md +75 -0
  169. package/src/agents/specific_instructions/ml_engineer/phases/index.md +25 -0
  170. package/src/agents/specific_instructions/ml_engineer/phases/phase-1.md +49 -0
  171. package/src/agents/specific_instructions/ml_engineer/phases/phase-2.md +75 -0
  172. package/src/agents/specific_instructions/ml_engineer/phases/phase-3.md +124 -0
  173. package/src/agents/specific_instructions/ml_engineer/phases/phase-4.md +279 -0
  174. package/src/agents/specific_instructions/ml_engineer/phases/phase-5.md +160 -0
  175. package/src/agents/specific_instructions/ml_engineer/phases/phase-6-5.md +170 -0
  176. package/src/agents/specific_instructions/ml_engineer/phases/phase-6.md +295 -0
  177. package/src/agents/specific_instructions/ml_engineer/phases/phase-7.md +337 -0
  178. package/src/agents/specific_instructions/ml_engineer/phases.md +1068 -0
  179. package/src/agents/specific_instructions/ml_engineer/research.md +437 -0
  180. package/src/agents/specific_instructions/ml_engineer/research_ui_mode.md +71 -0
  181. package/src/agents/specific_instructions/ml_engineer/review.md +187 -0
  182. package/src/agents/specific_instructions/ml_engineer/service_mode.md +273 -0
  183. package/src/agents/specific_instructions/ml_engineer/validation_checklist.md +185 -0
  184. package/src/agents/specific_instructions/mlops_engineer/advise.md +139 -0
  185. package/src/agents/specific_instructions/mlops_engineer/phases/index.md +23 -0
  186. package/src/agents/specific_instructions/mlops_engineer/phases/phase-1.md +52 -0
  187. package/src/agents/specific_instructions/mlops_engineer/phases/phase-2.md +86 -0
  188. package/src/agents/specific_instructions/mlops_engineer/phases/phase-3.md +105 -0
  189. package/src/agents/specific_instructions/mlops_engineer/phases/phase-4.md +128 -0
  190. package/src/agents/specific_instructions/mlops_engineer/phases/phase-5.md +106 -0
  191. package/src/agents/specific_instructions/mlops_engineer/phases/phase-6.md +128 -0
  192. package/src/agents/specific_instructions/mlops_engineer/phases/phase-7.md +144 -0
  193. package/src/agents/specific_instructions/mlops_engineer/phases.md +671 -0
  194. package/src/agents/specific_instructions/mlops_engineer/review.md +164 -0
  195. package/src/agents/specific_instructions/mlops_engineer/service_mode.md +81 -0
  196. package/src/agents/specific_instructions/mlops_engineer/validation_checklist.md +151 -0
  197. package/src/agents/specific_instructions/researcher/critical_review.md +292 -0
  198. package/src/agents/specific_instructions/researcher/review_checklist.md +67 -0
  199. package/src/agents/specific_instructions/researcher/service_mode.md +224 -0
  200. package/src/agents/specific_instructions/shared/auto_verify_mode.md +141 -0
  201. package/src/agents/specific_instructions/shared/autonomous_research.md +1289 -0
  202. package/src/agents/specific_instructions/shared/behavioral_rules.md +36 -0
  203. package/src/agents/specific_instructions/shared/diverge_protocol.md +387 -0
  204. package/src/agents/specific_instructions/shared/engineering_guidelines.md +136 -0
  205. package/src/agents/specific_instructions/shared/experiment_versioning.md +184 -0
  206. package/src/agents/specific_instructions/shared/goal_mode.md +187 -0
  207. package/src/agents/specific_instructions/shared/incremental_testing.md +139 -0
  208. package/src/agents/specific_instructions/shared/intent_discovery.md +223 -0
  209. package/src/agents/specific_instructions/shared/join_path_protocol.md +168 -0
  210. package/src/agents/specific_instructions/shared/knowledge_checkpoint.md +83 -0
  211. package/src/agents/specific_instructions/shared/knowledge_harvest.md +220 -0
  212. package/src/agents/specific_instructions/shared/knowledge_retrieval.md +100 -0
  213. package/src/agents/specific_instructions/shared/notebook_walkthrough_protocol.md +367 -0
  214. package/src/agents/specific_instructions/shared/reviewer_verdict_protocol.md +74 -0
  215. package/src/agents/specific_instructions/shared/swarm_protocol.md +97 -0
  216. package/src/agents/specific_instructions/shared/validation_protocol.md +139 -0
  217. package/src/agents/specific_instructions/syn/arbiter.md +140 -0
  218. package/src/agents/specific_instructions/syn/brainstorm.md +550 -0
  219. package/src/agents/specific_instructions/syn/code_review.md +232 -0
  220. package/src/agents/specific_instructions/syn/diff.md +239 -0
  221. package/src/agents/specific_instructions/syn/final_review.md +65 -0
  222. package/src/agents/specific_instructions/syn/fixer.md +240 -0
  223. package/src/agents/specific_instructions/syn/free_form.md +130 -0
  224. package/src/agents/specific_instructions/syn/knowledge.md +468 -0
  225. package/src/agents/specific_instructions/syn/notebook_walkthrough.md +78 -0
  226. package/src/agents/specific_instructions/syn/panel_review.md +634 -0
  227. package/src/agents/specific_instructions/syn/pm.md +453 -0
  228. package/src/agents/specific_instructions/syn/pr_review.md +255 -0
  229. package/src/agents/specific_instructions/syn/slides.md +417 -0
  230. package/src/agents/syn.md +729 -0
  231. package/src/commands/academic.md +41 -0
  232. package/src/commands/ai-engineer.md +45 -0
  233. package/src/commands/analytics-engineer.md +48 -0
  234. package/src/commands/applied-ml-scientist.md +45 -0
  235. package/src/commands/backend-engineer.md +35 -0
  236. package/src/commands/bi-engineer.md +40 -0
  237. package/src/commands/brainstorm.md +24 -0
  238. package/src/commands/data-analyst.md +38 -0
  239. package/src/commands/data-engineer.md +37 -0
  240. package/src/commands/data-modeller.md +38 -0
  241. package/src/commands/data-scientist.md +38 -0
  242. package/src/commands/deep-learning-engineer.md +47 -0
  243. package/src/commands/end.md +49 -0
  244. package/src/commands/knowledge.md +24 -0
  245. package/src/commands/ml-engineer.md +42 -0
  246. package/src/commands/mlops-engineer.md +47 -0
  247. package/src/commands/notebook-walkthrough.md +58 -0
  248. package/src/commands/researcher.md +40 -0
  249. package/src/commands/resume.md +57 -0
  250. package/src/commands/review-pr.md +26 -0
  251. package/src/commands/shards-guide.md +41 -0
  252. package/src/commands/shards-ui.md +32 -0
  253. package/src/commands/shards.md +41 -0
  254. package/src/docs/01-getting-started/concepts.md +109 -0
  255. package/src/docs/01-getting-started/first-session.md +79 -0
  256. package/src/docs/01-getting-started/install.md +61 -0
  257. package/src/docs/02-agents/academic.md +71 -0
  258. package/src/docs/02-agents/ai-engineer.md +78 -0
  259. package/src/docs/02-agents/analytics-engineer.md +58 -0
  260. package/src/docs/02-agents/applied-ml-scientist.md +59 -0
  261. package/src/docs/02-agents/backend-engineer.md +58 -0
  262. package/src/docs/02-agents/bi-engineer.md +65 -0
  263. package/src/docs/02-agents/data-analyst.md +67 -0
  264. package/src/docs/02-agents/data-engineer.md +57 -0
  265. package/src/docs/02-agents/data-modeller.md +51 -0
  266. package/src/docs/02-agents/data-scientist.md +78 -0
  267. package/src/docs/02-agents/deep-learning-engineer.md +64 -0
  268. package/src/docs/02-agents/ml-engineer.md +80 -0
  269. package/src/docs/02-agents/mlops-engineer.md +59 -0
  270. package/src/docs/02-agents/overview.md +62 -0
  271. package/src/docs/02-agents/researcher.md +73 -0
  272. package/src/docs/02-agents/syn.md +88 -0
  273. package/src/docs/03-protocols/auto-verify.md +82 -0
  274. package/src/docs/03-protocols/autonomous-research.md +59 -0
  275. package/src/docs/03-protocols/behavioral-rules.md +35 -0
  276. package/src/docs/03-protocols/diverge.md +50 -0
  277. package/src/docs/03-protocols/engineering-guidelines.md +56 -0
  278. package/src/docs/03-protocols/experiment-versioning.md +38 -0
  279. package/src/docs/03-protocols/gate-pattern.md +65 -0
  280. package/src/docs/03-protocols/incremental-testing.md +68 -0
  281. package/src/docs/03-protocols/join-path.md +46 -0
  282. package/src/docs/03-protocols/knowledge-ledger.md +70 -0
  283. package/src/docs/03-protocols/reviewer-verdicts.md +39 -0
  284. package/src/docs/03-protocols/swarm.md +40 -0
  285. package/src/docs/03-protocols/validation.md +174 -0
  286. package/src/docs/04-ui/activity-bar.md +70 -0
  287. package/src/docs/04-ui/chat-pane.md +80 -0
  288. package/src/docs/04-ui/code-intel.md +62 -0
  289. package/src/docs/04-ui/file-editing.md +61 -0
  290. package/src/docs/04-ui/git.md +54 -0
  291. package/src/docs/04-ui/keybindings.md +79 -0
  292. package/src/docs/04-ui/knowledge-map.md +76 -0
  293. package/src/docs/04-ui/overview.md +93 -0
  294. package/src/docs/04-ui/panels.md +49 -0
  295. package/src/docs/04-ui/pinboard-selection.md +66 -0
  296. package/src/docs/04-ui/quick-open-palette.md +56 -0
  297. package/src/docs/04-ui/sessions.md +81 -0
  298. package/src/docs/04-ui/settings-permissions.md +56 -0
  299. package/src/docs/05-commands/reference.md +59 -0
  300. package/src/docs/06-outputs/directory-map.md +116 -0
  301. package/src/docs/07-workflows/ai-eval-first.md +57 -0
  302. package/src/docs/07-workflows/deep-study-to-production.md +76 -0
  303. package/src/docs/07-workflows/diverge-exploration.md +77 -0
  304. package/src/docs/07-workflows/quick-analysis.md +45 -0
  305. package/src/docs/08-integrations/claude-code-auto-mode.md +191 -0
  306. package/src/docs/08-integrations/google-slides.md +175 -0
  307. package/src/docs/README.md +30 -0
  308. package/src/docs/manifest.json +108 -0
  309. package/src/templates/analysis-template.md +20 -0
  310. package/src/templates/branch-report.md +46 -0
  311. package/src/templates/diff-report.md +88 -0
  312. package/src/templates/knowledge-index.md +7 -0
  313. package/src/templates/model-card-schema.json +186 -0
  314. package/src/templates/model-card-schema.md +88 -0
  315. package/src/templates/model-card.md +124 -0
  316. package/src/templates/project-plan.md +47 -0
  317. package/src/templates/project-specs.md +81 -0
  318. package/src/templates/report-template.md +43 -0
  319. package/src/templates/study-template.md +25 -0
  320. package/src/ui/cc-readonly.js +181 -0
  321. package/src/ui/chat-session.js +466 -0
  322. package/src/ui/css/base.css +136 -0
  323. package/src/ui/css/brainstorm.css +525 -0
  324. package/src/ui/css/chat.css +1405 -0
  325. package/src/ui/css/editor.css +546 -0
  326. package/src/ui/css/eval-dashboard.css +157 -0
  327. package/src/ui/css/experiment.css +237 -0
  328. package/src/ui/css/guide.css +186 -0
  329. package/src/ui/css/knowledge-map.css +383 -0
  330. package/src/ui/css/layout.css +431 -0
  331. package/src/ui/css/model-card.css +161 -0
  332. package/src/ui/css/notebook-walkthrough.css +271 -0
  333. package/src/ui/css/pr-review.css +403 -0
  334. package/src/ui/css/prompt-lab.css +325 -0
  335. package/src/ui/css/sessions.css +258 -0
  336. package/src/ui/css/sidebar.css +661 -0
  337. package/src/ui/css/terminal.css +113 -0
  338. package/src/ui/css/theme-light.css +542 -0
  339. package/src/ui/index.html +389 -0
  340. package/src/ui/js/agents.js +32 -0
  341. package/src/ui/js/bookmarks.js +230 -0
  342. package/src/ui/js/chat.js +1776 -0
  343. package/src/ui/js/code-intel.js +328 -0
  344. package/src/ui/js/command-palette.js +142 -0
  345. package/src/ui/js/events.js +591 -0
  346. package/src/ui/js/explorer.js +317 -0
  347. package/src/ui/js/file-view.js +477 -0
  348. package/src/ui/js/git.js +536 -0
  349. package/src/ui/js/guide.js +198 -0
  350. package/src/ui/js/hud.js +75 -0
  351. package/src/ui/js/init.js +351 -0
  352. package/src/ui/js/knowledge-map.js +906 -0
  353. package/src/ui/js/markdown.js +114 -0
  354. package/src/ui/js/monaco.js +164 -0
  355. package/src/ui/js/notebook-walkthrough.js +272 -0
  356. package/src/ui/js/notebook.js +448 -0
  357. package/src/ui/js/panels.js +2681 -0
  358. package/src/ui/js/pinboard.js +186 -0
  359. package/src/ui/js/quick-open.js +164 -0
  360. package/src/ui/js/selection-context.js +131 -0
  361. package/src/ui/js/sessions.js +256 -0
  362. package/src/ui/js/settings.js +476 -0
  363. package/src/ui/js/split-view.js +82 -0
  364. package/src/ui/js/state.js +343 -0
  365. package/src/ui/js/table.js +161 -0
  366. package/src/ui/js/tabs.js +284 -0
  367. package/src/ui/js/tabular.js +125 -0
  368. package/src/ui/js/terminal.js +354 -0
  369. package/src/ui/js/timeline.js +137 -0
  370. package/src/ui/js/utils.js +293 -0
  371. package/src/ui/notebook-kernel.py +790 -0
  372. package/src/ui/open-browser.js +55 -0
  373. package/src/ui/permission-pattern.js +42 -0
  374. package/src/ui/relay.js +513 -0
  375. package/src/ui/server.js +3072 -0
  376. package/src/ui/session-index.js +225 -0
  377. package/src/ui/shards_icon.png +0 -0
  378. package/src/ui/spawn-server.js +41 -0
  379. package/src/ui/symbol-index.js +813 -0
  380. package/src/ui/ui-push.js +177 -0
  381. package/tools/gate-hook/VALIDATION_SPEC.md +273 -0
  382. package/tools/gate-hook/__tests__/auto-verify.test.js +343 -0
  383. package/tools/gate-hook/auto-allowlist.js +179 -0
  384. package/tools/gate-hook/auto-state.js +68 -0
  385. package/tools/gate-hook/classify.js +21 -0
  386. package/tools/gate-hook/log.js +57 -0
  387. package/tools/gate-hook/parser.js +205 -0
  388. package/tools/gate-hook/sql-guard.js +230 -0
  389. package/tools/gate-hook/state.js +170 -0
  390. package/tools/gate-hook/sweep.js +139 -0
  391. package/tools/gate-hook/transcript.js +45 -0
  392. package/tools/gate-hook/validation.js +321 -0
  393. package/tools/gate-hook.js +475 -0
  394. package/tools/install.js +914 -0
  395. package/tools/shards-gates.js +311 -0
  396. package/tools/shards-sessions.js +261 -0
  397. package/tools/shards-ui.js +377 -0
@@ -0,0 +1,906 @@
1
+ // ═══════════════════════════════════════════════════════════════
2
+ // Knowledge Map — interactive project wiki panel
3
+ // ═══════════════════════════════════════════════════════════════
4
+
5
+ var knowledgeCache = null;
6
+ var kmActiveView = 'cards'; // 'cards' | 'graph'
7
+ var kmActiveFilters = { search: '', type: 'all', confidence: 'all' };
8
+ var kmShowNewForm = false;
9
+
10
+ // ─── YAML frontmatter parser ──────────────────────────────────
11
+
12
+ function kmParseFrontmatter(text) {
13
+ var meta = {};
14
+ var body = text;
15
+ if (!text || !text.startsWith('---')) return { meta: meta, body: body };
16
+
17
+ var endIdx = text.indexOf('---', 3);
18
+ if (endIdx === -1) return { meta: meta, body: body };
19
+
20
+ var yamlBlock = text.substring(3, endIdx).trim();
21
+ body = text.substring(endIdx + 3).trim();
22
+
23
+ var lines = yamlBlock.split('\n');
24
+ var currentKey = null;
25
+ var multilineValue = '';
26
+ var inMultiline = false;
27
+
28
+ for (var i = 0; i < lines.length; i++) {
29
+ var line = lines[i];
30
+
31
+ if (inMultiline) {
32
+ // Multiline block: indented lines belong to current key
33
+ if (line.match(/^\s/) && (i + 1 >= lines.length || lines[i + 1].match(/^\s/) || !lines[i + 1].includes(':'))) {
34
+ multilineValue += (multilineValue ? '\n' : '') + line.replace(/^\s{2}/, '');
35
+ if (i === lines.length - 1) {
36
+ meta[currentKey] = multilineValue;
37
+ }
38
+ continue;
39
+ } else {
40
+ meta[currentKey] = multilineValue;
41
+ inMultiline = false;
42
+ multilineValue = '';
43
+ }
44
+ }
45
+
46
+ var colonIdx = line.indexOf(':');
47
+ if (colonIdx === -1) continue;
48
+
49
+ var key = line.substring(0, colonIdx).trim();
50
+ var val = line.substring(colonIdx + 1).trim();
51
+
52
+ if (val === '|') {
53
+ currentKey = key;
54
+ inMultiline = true;
55
+ multilineValue = '';
56
+ continue;
57
+ }
58
+
59
+ // Array: [a, b, c]
60
+ if (val.startsWith('[') && val.endsWith(']')) {
61
+ var inner = val.substring(1, val.length - 1);
62
+ meta[key] = inner ? inner.split(',').map(function(s) { return s.trim(); }) : [];
63
+ } else {
64
+ meta[key] = val;
65
+ }
66
+ }
67
+
68
+ return { meta: meta, body: body };
69
+ }
70
+
71
+ function kmRebuildFrontmatter(meta) {
72
+ var lines = ['---'];
73
+ var order = ['title', 'domain', 'source_project', 'contributed_by', 'date', 'type', 'confidence'];
74
+ var written = {};
75
+
76
+ for (var i = 0; i < order.length; i++) {
77
+ var k = order[i];
78
+ if (meta[k] === undefined) continue;
79
+ lines.push(kmSerializeField(k, meta[k]));
80
+ written[k] = true;
81
+ }
82
+
83
+ // Write any remaining keys not in standard order
84
+ var keys = Object.keys(meta);
85
+ for (var j = 0; j < keys.length; j++) {
86
+ if (written[keys[j]]) continue;
87
+ lines.push(kmSerializeField(keys[j], meta[keys[j]]));
88
+ }
89
+
90
+ lines.push('---');
91
+ return lines.join('\n');
92
+ }
93
+
94
+ function kmSerializeField(key, val) {
95
+ if (Array.isArray(val)) {
96
+ return key + ': [' + val.join(', ') + ']';
97
+ }
98
+ if (typeof val === 'string' && val.indexOf('\n') !== -1) {
99
+ return key + ': |\n' + val.split('\n').map(function(l) { return ' ' + l; }).join('\n');
100
+ }
101
+ return key + ': ' + val;
102
+ }
103
+
104
+ function kmSlugify(title) {
105
+ return title.toLowerCase()
106
+ .replace(/[^a-z0-9\s-]/g, '')
107
+ .replace(/\s+/g, '-')
108
+ .replace(/-+/g, '-')
109
+ .replace(/^-|-$/g, '')
110
+ .substring(0, 60);
111
+ }
112
+
113
+ function kmIsStale(entry) {
114
+ if (entry.meta.confidence === 'low') return true;
115
+ if (!entry.meta.date) return false;
116
+ var entryDate = new Date(entry.meta.date);
117
+ var sixMonthsAgo = new Date();
118
+ sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
119
+ return entryDate < sixMonthsAgo;
120
+ }
121
+
122
+ // ─── Data loading ─────────────────────────────────────────────
123
+
124
+ function kmLoadEntries() {
125
+ return authFetch('/knowledge/entries').then(function(res) {
126
+ return res.json();
127
+ }).then(function(data) {
128
+ var entries = [];
129
+ for (var i = 0; i < data.entries.length; i++) {
130
+ var e = data.entries[i];
131
+ var parsed = kmParseFrontmatter(e.content);
132
+ entries.push({
133
+ path: e.path,
134
+ meta: parsed.meta,
135
+ body: parsed.body,
136
+ raw: e.content,
137
+ });
138
+ }
139
+ knowledgeCache = entries;
140
+ return entries;
141
+ });
142
+ }
143
+
144
+ // ─── Main renderer ────────────────────────────────────────────
145
+
146
+ function renderKnowledgeMapPanel(container, panel) {
147
+ container.innerHTML = '';
148
+
149
+ var wrapper = document.createElement('div');
150
+ wrapper.className = 'km-panel';
151
+
152
+ // Toolbar
153
+ var toolbar = document.createElement('div');
154
+ toolbar.className = 'km-toolbar';
155
+ toolbar.innerHTML =
156
+ '<input class="km-search" type="text" placeholder="Search entries..." value="' + esc(kmActiveFilters.search) + '">' +
157
+ '<div class="km-filter-group">' +
158
+ '<button class="km-filter-chip' + (kmActiveFilters.type === 'all' ? ' active' : '') + '" data-type="all">All</button>' +
159
+ '<button class="km-filter-chip' + (kmActiveFilters.type === 'entities' ? ' active' : '') + '" data-type="entities">Entities</button>' +
160
+ '<button class="km-filter-chip' + (kmActiveFilters.type === 'infrastructure' ? ' active' : '') + '" data-type="infrastructure">Infra</button>' +
161
+ '<button class="km-filter-chip' + (kmActiveFilters.type === 'patterns' ? ' active' : '') + '" data-type="patterns">Patterns</button>' +
162
+ '<button class="km-filter-chip' + (kmActiveFilters.type === 'features' ? ' active' : '') + '" data-type="features">Features</button>' +
163
+ '</div>' +
164
+ '<div class="km-toolbar-actions">' +
165
+ '<button class="km-btn" id="km-rebuild-idx" title="Rebuild INDEX.md from disk">Rebuild Index</button>' +
166
+ '<button class="km-btn" id="km-view-toggle">' + (kmActiveView === 'cards' ? 'Graph View' : 'Card View') + '</button>' +
167
+ '<button class="km-btn km-btn-primary" id="km-add-btn">+ Add Entry</button>' +
168
+ '</div>';
169
+ wrapper.appendChild(toolbar);
170
+
171
+ // Content area
172
+ var content = document.createElement('div');
173
+ content.className = 'km-content';
174
+ content.id = 'km-content-area';
175
+ wrapper.appendChild(content);
176
+
177
+ container.appendChild(wrapper);
178
+
179
+ // Wire toolbar events
180
+ var searchInput = toolbar.querySelector('.km-search');
181
+ var debounceTimer = null;
182
+ searchInput.addEventListener('input', function() {
183
+ kmActiveFilters.search = this.value;
184
+ clearTimeout(debounceTimer);
185
+ debounceTimer = setTimeout(function() { kmRefreshContent(content); }, 200);
186
+ });
187
+
188
+ var chips = toolbar.querySelectorAll('.km-filter-chip');
189
+ for (var i = 0; i < chips.length; i++) {
190
+ chips[i].addEventListener('click', function() {
191
+ kmActiveFilters.type = this.getAttribute('data-type');
192
+ for (var j = 0; j < chips.length; j++) chips[j].classList.remove('active');
193
+ this.classList.add('active');
194
+ kmRefreshContent(content);
195
+ });
196
+ }
197
+
198
+ document.getElementById('km-view-toggle').addEventListener('click', function() {
199
+ kmActiveView = kmActiveView === 'cards' ? 'graph' : 'cards';
200
+ this.textContent = kmActiveView === 'cards' ? 'Graph View' : 'Card View';
201
+ kmRefreshContent(content);
202
+ });
203
+
204
+ document.getElementById('km-add-btn').addEventListener('click', function() {
205
+ kmShowNewForm = true;
206
+ kmRefreshContent(content);
207
+ });
208
+
209
+ document.getElementById('km-rebuild-idx').addEventListener('click', function() {
210
+ if (!knowledgeCache) return;
211
+ kmUpdateIndex(knowledgeCache).then(function() {
212
+ alert('INDEX.md rebuilt successfully.');
213
+ });
214
+ });
215
+
216
+ // Load and render
217
+ content.innerHTML = '<div class="km-empty-state"><p>Loading...</p></div>';
218
+ kmLoadEntries().then(function() {
219
+ kmRefreshContent(content);
220
+ }).catch(function(err) {
221
+ content.innerHTML = '<div class="km-empty-state"><h3>Failed to load knowledge entries</h3><p>' + esc(String(err)) + '</p></div>';
222
+ });
223
+ }
224
+
225
+ function kmRefreshContent(contentEl) {
226
+ if (!contentEl) return;
227
+ contentEl.innerHTML = '';
228
+
229
+ if (kmShowNewForm) {
230
+ kmRenderNewEntryForm(contentEl);
231
+ return;
232
+ }
233
+
234
+ var entries = knowledgeCache || [];
235
+
236
+ if (entries.length === 0) {
237
+ contentEl.innerHTML =
238
+ '<div class="km-empty-state">' +
239
+ '<div class="km-empty-icon">&#9671;</div>' +
240
+ '<h3>No knowledge entries yet</h3>' +
241
+ '<p>The Knowledge Ledger is where agents store reusable facts about your project — entity relationships, infrastructure quirks, SQL patterns, and verified features.</p>' +
242
+ '<button class="km-btn km-btn-primary" onclick="kmShowNewForm=true;kmRefreshContent(document.getElementById(\'km-content-area\'))">Create First Entry</button>' +
243
+ '</div>';
244
+ return;
245
+ }
246
+
247
+ if (kmActiveView === 'graph') {
248
+ kmRenderGraph(contentEl, kmFilterEntries(entries));
249
+ } else {
250
+ kmRenderCards(contentEl, kmFilterEntries(entries));
251
+ }
252
+ }
253
+
254
+ function kmFilterEntries(entries) {
255
+ var result = [];
256
+ var search = kmActiveFilters.search.toLowerCase();
257
+ for (var i = 0; i < entries.length; i++) {
258
+ var e = entries[i];
259
+ // Hide superseded entries unless searching explicitly
260
+ if (e.meta.superseded === 'true' && !search) continue;
261
+ if (kmActiveFilters.type !== 'all' && e.meta.type !== kmActiveFilters.type) continue;
262
+ if (search) {
263
+ var doms = Array.isArray(e.meta.domain) ? e.meta.domain : (e.meta.domain ? [e.meta.domain] : []);
264
+ var haystack = ((e.meta.title || '') + ' ' + e.body + ' ' + doms.join(' ')).toLowerCase();
265
+ if (haystack.indexOf(search) === -1) continue;
266
+ }
267
+ result.push(e);
268
+ }
269
+ return result;
270
+ }
271
+
272
+ // ─── Card view ────────────────────────────────────────────────
273
+
274
+ function kmRenderCards(contentEl, entries) {
275
+ var types = ['entities', 'infrastructure', 'patterns', 'features'];
276
+ var grouped = {};
277
+ for (var t = 0; t < types.length; t++) grouped[types[t]] = [];
278
+ for (var i = 0; i < entries.length; i++) {
279
+ var type = entries[i].meta.type || 'patterns';
280
+ if (!grouped[type]) grouped[type] = [];
281
+ grouped[type].push(entries[i]);
282
+ }
283
+
284
+ var hasAny = false;
285
+ for (var ti = 0; ti < types.length; ti++) {
286
+ var typeEntries = grouped[types[ti]];
287
+ if (typeEntries.length === 0) continue;
288
+ hasAny = true;
289
+
290
+ var section = document.createElement('div');
291
+ section.className = 'km-type-section';
292
+
293
+ var header = document.createElement('div');
294
+ header.className = 'km-type-header';
295
+ header.textContent = types[ti] + ' (' + typeEntries.length + ')';
296
+ section.appendChild(header);
297
+
298
+ var grid = document.createElement('div');
299
+ grid.className = 'km-card-grid';
300
+
301
+ for (var j = 0; j < typeEntries.length; j++) {
302
+ grid.appendChild(kmCreateCard(typeEntries[j]));
303
+ }
304
+
305
+ section.appendChild(grid);
306
+ contentEl.appendChild(section);
307
+ }
308
+
309
+ if (!hasAny) {
310
+ contentEl.innerHTML = '<div class="km-empty-state"><h3>No entries match filters</h3></div>';
311
+ }
312
+ }
313
+
314
+ function kmCreateCard(entry) {
315
+ var card = document.createElement('div');
316
+ card.className = 'km-card';
317
+ card.setAttribute('data-path', entry.path);
318
+
319
+ var domains = Array.isArray(entry.meta.domain) ? entry.meta.domain : (entry.meta.domain ? [entry.meta.domain] : []);
320
+ var confidence = entry.meta.confidence || 'medium';
321
+ var type = entry.meta.type || 'patterns';
322
+ var stale = kmIsStale(entry);
323
+
324
+ // Preview: strip markdown, take first ~80 chars
325
+ var previewText = entry.body.replace(/[#*`_\[\]]/g, '').substring(0, 100);
326
+
327
+ card.innerHTML =
328
+ '<div class="km-card-top">' +
329
+ '<span class="km-type-badge ' + esc(type) + '">' + esc(type) + '</span>' +
330
+ '<span class="km-card-title" title="' + esc(entry.meta.title || '') + '">' + esc(entry.meta.title || 'Untitled') + '</span>' +
331
+ '<span class="km-confidence-dot ' + esc(confidence) + '" title="Confidence: ' + esc(confidence) + '"></span>' +
332
+ '</div>' +
333
+ '<div class="km-card-meta">' +
334
+ domains.map(function(d) { return '<span class="km-domain-tag">' + esc(d) + '</span>'; }).join('') +
335
+ '<span class="km-card-date">' + esc(entry.meta.date || '') +
336
+ (stale ? ' <span class="km-stale-badge">Stale</span>' : '') +
337
+ '</span>' +
338
+ '</div>' +
339
+ '<div class="km-card-preview">' + esc(previewText) + '</div>';
340
+
341
+ card.addEventListener('click', function(e) {
342
+ if (card.classList.contains('expanded')) return;
343
+ kmExpandCard(card, entry);
344
+ });
345
+
346
+ return card;
347
+ }
348
+
349
+ function kmExpandCard(card, entry) {
350
+ card.classList.add('expanded');
351
+ var domains = Array.isArray(entry.meta.domain) ? entry.meta.domain : (entry.meta.domain ? [entry.meta.domain] : []);
352
+ var confidence = entry.meta.confidence || 'medium';
353
+ var type = entry.meta.type || 'patterns';
354
+
355
+ var formHtml =
356
+ '<div class="km-card-top">' +
357
+ '<span class="km-type-badge ' + esc(type) + '">' + esc(type) + '</span>' +
358
+ '<span class="km-card-title">' + esc(entry.meta.title || 'Untitled') + '</span>' +
359
+ '<span class="km-confidence-dot ' + esc(confidence) + '"></span>' +
360
+ '</div>' +
361
+ '<div class="km-edit-form">' +
362
+ '<div class="km-field-row">' +
363
+ '<div class="km-field"><label>Title</label><input type="text" class="km-edit-title" value="' + esc(entry.meta.title || '') + '"></div>' +
364
+ '<div class="km-field"><label>Type</label>' +
365
+ '<select class="km-edit-type">' +
366
+ '<option value="entities"' + (type === 'entities' ? ' selected' : '') + '>Entities</option>' +
367
+ '<option value="infrastructure"' + (type === 'infrastructure' ? ' selected' : '') + '>Infrastructure</option>' +
368
+ '<option value="patterns"' + (type === 'patterns' ? ' selected' : '') + '>Patterns</option>' +
369
+ '<option value="features"' + (type === 'features' ? ' selected' : '') + '>Features</option>' +
370
+ '</select>' +
371
+ '</div>' +
372
+ '</div>' +
373
+ '<div class="km-field-row">' +
374
+ '<div class="km-field"><label>Domains (comma-separated)</label><input type="text" class="km-edit-domains" value="' + esc(domains.join(', ')) + '"></div>' +
375
+ '<div class="km-field"><label>Confidence</label>' +
376
+ '<select class="km-edit-confidence">' +
377
+ '<option value="high"' + (confidence === 'high' ? ' selected' : '') + '>High</option>' +
378
+ '<option value="medium"' + (confidence === 'medium' ? ' selected' : '') + '>Medium</option>' +
379
+ '<option value="low"' + (confidence === 'low' ? ' selected' : '') + '>Low</option>' +
380
+ '</select>' +
381
+ '</div>' +
382
+ '</div>' +
383
+ '<div class="km-field"><label>Content</label><textarea class="km-edit-body">' + esc(entry.body) + '</textarea></div>' +
384
+ '<div class="km-preview-label">Preview</div>' +
385
+ '<div class="km-preview-area"></div>' +
386
+ '<div class="km-edit-actions">' +
387
+ '<button class="km-btn km-btn-primary km-save-btn">Save</button>' +
388
+ '<button class="km-btn km-cancel-btn">Cancel</button>' +
389
+ '<button class="km-btn km-btn-danger km-supersede-btn">Mark Superseded</button>' +
390
+ '</div>' +
391
+ '</div>';
392
+
393
+ card.innerHTML = formHtml;
394
+
395
+ // Live preview
396
+ var textarea = card.querySelector('.km-edit-body');
397
+ var previewArea = card.querySelector('.km-preview-area');
398
+ function updatePreview() {
399
+ if (typeof marked !== 'undefined') {
400
+ previewArea.innerHTML = marked.parse(textarea.value);
401
+ } else {
402
+ previewArea.textContent = textarea.value;
403
+ }
404
+ }
405
+ textarea.addEventListener('input', updatePreview);
406
+ updatePreview();
407
+
408
+ // Save
409
+ card.querySelector('.km-save-btn').addEventListener('click', function(e) {
410
+ e.stopPropagation();
411
+ var newMeta = Object.assign({}, entry.meta);
412
+ newMeta.title = card.querySelector('.km-edit-title').value.trim();
413
+ newMeta.type = card.querySelector('.km-edit-type').value;
414
+ newMeta.confidence = card.querySelector('.km-edit-confidence').value;
415
+ var domainStr = card.querySelector('.km-edit-domains').value;
416
+ newMeta.domain = domainStr ? domainStr.split(',').map(function(s) { return s.trim(); }).filter(Boolean) : [];
417
+ var newBody = textarea.value;
418
+
419
+ // If type changed, we need to write to new path and blank the old file
420
+ var oldType = entry.meta.type || 'patterns';
421
+ var newType = newMeta.type;
422
+ if (oldType !== newType) {
423
+ var filename = entry.path.split('/').pop();
424
+ var newPath = '.shards/knowledge/' + newType + '/' + filename;
425
+ var content = kmRebuildFrontmatter(newMeta) + '\n\n' + newBody;
426
+ // Write new file, then mark old file as moved (redirect stub)
427
+ authFetch('/browse/file/save', {
428
+ method: 'POST',
429
+ headers: { 'Content-Type': 'application/json' },
430
+ body: JSON.stringify({ path: newPath, content: content }),
431
+ }).then(function() {
432
+ // Write a stub so the old path isn't an orphan empty file
433
+ var stub = '---\nsuperseded: true\nmoved_to: ' + newPath + '\n---\n\nMoved to ' + newPath + '\n';
434
+ return authFetch('/browse/file/save', {
435
+ method: 'POST',
436
+ headers: { 'Content-Type': 'application/json' },
437
+ body: JSON.stringify({ path: entry.path, content: stub }),
438
+ });
439
+ }).then(function() {
440
+ entry.path = newPath;
441
+ entry.meta = newMeta;
442
+ entry.body = newBody;
443
+ entry.raw = content;
444
+ return kmUpdateIndex(knowledgeCache);
445
+ }).then(function() {
446
+ kmRefreshContent(document.getElementById('km-content-area'));
447
+ });
448
+ } else {
449
+ kmSaveEntry(entry, newMeta, newBody).then(function() {
450
+ kmRefreshContent(document.getElementById('km-content-area'));
451
+ });
452
+ }
453
+ });
454
+
455
+ // Cancel
456
+ card.querySelector('.km-cancel-btn').addEventListener('click', function(e) {
457
+ e.stopPropagation();
458
+ kmRefreshContent(document.getElementById('km-content-area'));
459
+ });
460
+
461
+ // Mark superseded
462
+ card.querySelector('.km-supersede-btn').addEventListener('click', function(e) {
463
+ e.stopPropagation();
464
+ kmConfirm('Mark this entry as superseded?', function() {
465
+ var newMeta = Object.assign({}, entry.meta);
466
+ newMeta.superseded = 'true';
467
+ kmSaveEntry(entry, newMeta, entry.body).then(function() {
468
+ kmRefreshContent(document.getElementById('km-content-area'));
469
+ });
470
+ });
471
+ });
472
+
473
+ // Prevent card click from collapsing
474
+ card.querySelector('.km-edit-form').addEventListener('click', function(e) {
475
+ e.stopPropagation();
476
+ });
477
+ }
478
+
479
+ // ─── Persistence ──────────────────────────────────────────────
480
+
481
+ function kmSaveEntry(entry, newMeta, newBody) {
482
+ var content = kmRebuildFrontmatter(newMeta) + '\n\n' + newBody;
483
+
484
+ return authFetch('/browse/file/save', {
485
+ method: 'POST',
486
+ headers: { 'Content-Type': 'application/json' },
487
+ body: JSON.stringify({ path: entry.path, content: content }),
488
+ }).then(function() {
489
+ // Only update cache after successful save
490
+ entry.meta = newMeta;
491
+ entry.body = newBody;
492
+ entry.raw = content;
493
+ return kmUpdateIndex(knowledgeCache);
494
+ });
495
+ }
496
+
497
+ function kmCreateEntry(meta, body) {
498
+ var slug = kmSlugify(meta.title || 'untitled');
499
+ var category = meta.type || 'patterns';
500
+ var filePath = '.shards/knowledge/' + category + '/' + slug + '.md';
501
+
502
+ // Check for conflicts in cache
503
+ if (knowledgeCache) {
504
+ var existing = knowledgeCache.filter(function(e) { return e.path === filePath; });
505
+ if (existing.length > 0) {
506
+ var v = 2;
507
+ while (knowledgeCache.some(function(e) { return e.path === '.shards/knowledge/' + category + '/' + slug + '_v' + v + '.md'; })) v++;
508
+ slug = slug + '_v' + v;
509
+ filePath = '.shards/knowledge/' + category + '/' + slug + '.md';
510
+ }
511
+ }
512
+
513
+ if (!meta.date) {
514
+ var d = new Date();
515
+ meta.date = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
516
+ }
517
+
518
+ var content = kmRebuildFrontmatter(meta) + '\n\n' + body;
519
+ var newEntry = { path: filePath, meta: meta, body: body, raw: content };
520
+
521
+ return authFetch('/browse/file/save', {
522
+ method: 'POST',
523
+ headers: { 'Content-Type': 'application/json' },
524
+ body: JSON.stringify({ path: filePath, content: content }),
525
+ }).then(function() {
526
+ if (!knowledgeCache) knowledgeCache = [];
527
+ knowledgeCache.push(newEntry);
528
+ return kmUpdateIndex(knowledgeCache);
529
+ });
530
+ }
531
+
532
+ function kmUpdateIndex(entries) {
533
+ var lines = [
534
+ '# Knowledge Ledger — Index',
535
+ '',
536
+ '| Date | Type | Title | Domains | Confidence | File |',
537
+ '|------|------|-------|---------|------------|------|',
538
+ ];
539
+
540
+ // Sort by date descending
541
+ var sorted = entries.slice().sort(function(a, b) {
542
+ return (b.meta.date || '').localeCompare(a.meta.date || '');
543
+ });
544
+
545
+ for (var i = 0; i < sorted.length; i++) {
546
+ var e = sorted[i];
547
+ var domains = Array.isArray(e.meta.domain) ? e.meta.domain.join(', ') : (e.meta.domain || '');
548
+ lines.push(
549
+ '| ' + (e.meta.date || '') +
550
+ ' | ' + (e.meta.type || '') +
551
+ ' | ' + (e.meta.title || '') +
552
+ ' | ' + domains +
553
+ ' | ' + (e.meta.confidence || '') +
554
+ ' | ' + e.path + ' |'
555
+ );
556
+ }
557
+
558
+ lines.push('');
559
+ var content = lines.join('\n');
560
+
561
+ return authFetch('/browse/file/save', {
562
+ method: 'POST',
563
+ headers: { 'Content-Type': 'application/json' },
564
+ body: JSON.stringify({ path: '.shards/knowledge/INDEX.md', content: content }),
565
+ });
566
+ }
567
+
568
+ // ─── New entry form ───────────────────────────────────────────
569
+
570
+ function kmRenderNewEntryForm(contentEl) {
571
+ var form = document.createElement('div');
572
+ form.className = 'km-new-entry-form';
573
+ form.innerHTML =
574
+ '<h3>New Knowledge Entry</h3>' +
575
+ '<div class="km-edit-form">' +
576
+ '<div class="km-field"><label>Title</label><input type="text" class="km-new-title" placeholder="e.g. Orders table grain is one row per order_id"></div>' +
577
+ '<div class="km-field-row">' +
578
+ '<div class="km-field"><label>Type</label>' +
579
+ '<select class="km-new-type">' +
580
+ '<option value="entities">Entities</option>' +
581
+ '<option value="infrastructure">Infrastructure</option>' +
582
+ '<option value="patterns">Patterns</option>' +
583
+ '<option value="features">Features</option>' +
584
+ '</select>' +
585
+ '</div>' +
586
+ '<div class="km-field"><label>Confidence</label>' +
587
+ '<select class="km-new-confidence">' +
588
+ '<option value="high">High</option>' +
589
+ '<option value="medium" selected>Medium</option>' +
590
+ '<option value="low">Low</option>' +
591
+ '</select>' +
592
+ '</div>' +
593
+ '</div>' +
594
+ '<div class="km-field"><label>Domains (comma-separated)</label><input type="text" class="km-new-domains" placeholder="e.g. orders, analytics, dbt"></div>' +
595
+ '<div class="km-field"><label>Source Project</label><input type="text" class="km-new-source" placeholder="e.g. studies/churn_analysis or Manual entry"></div>' +
596
+ '<div class="km-field"><label>Content (3-10 lines, specific and actionable)</label><textarea class="km-new-body" placeholder="Include table names, column names, SQL, or system names. Vague entries are less useful."></textarea></div>' +
597
+ '<div class="km-preview-label">Preview</div>' +
598
+ '<div class="km-preview-area"></div>' +
599
+ '<div class="km-edit-actions">' +
600
+ '<button class="km-btn km-btn-primary km-create-btn">Create Entry</button>' +
601
+ '<button class="km-btn km-new-cancel-btn">Cancel</button>' +
602
+ '</div>' +
603
+ '</div>';
604
+
605
+ contentEl.appendChild(form);
606
+
607
+ // Live preview
608
+ var textarea = form.querySelector('.km-new-body');
609
+ var previewArea = form.querySelector('.km-preview-area');
610
+ textarea.addEventListener('input', function() {
611
+ if (typeof marked !== 'undefined') {
612
+ previewArea.innerHTML = marked.parse(textarea.value);
613
+ } else {
614
+ previewArea.textContent = textarea.value;
615
+ }
616
+ });
617
+
618
+ // Create
619
+ form.querySelector('.km-create-btn').addEventListener('click', function() {
620
+ var title = form.querySelector('.km-new-title').value.trim();
621
+ if (!title) { alert('Title is required.'); return; }
622
+
623
+ var body = textarea.value.trim();
624
+ if (!body) { alert('Content is required.'); return; }
625
+
626
+ var domainStr = form.querySelector('.km-new-domains').value;
627
+ var meta = {
628
+ title: title,
629
+ domain: domainStr ? domainStr.split(',').map(function(s) { return s.trim(); }).filter(Boolean) : [],
630
+ source_project: form.querySelector('.km-new-source').value.trim() || 'Manual entry',
631
+ contributed_by: 'User (via UI)',
632
+ date: '',
633
+ type: form.querySelector('.km-new-type').value,
634
+ confidence: form.querySelector('.km-new-confidence').value,
635
+ };
636
+
637
+ kmCreateEntry(meta, body).then(function() {
638
+ kmShowNewForm = false;
639
+ kmRefreshContent(document.getElementById('km-content-area'));
640
+ });
641
+ });
642
+
643
+ // Cancel
644
+ form.querySelector('.km-new-cancel-btn').addEventListener('click', function() {
645
+ kmShowNewForm = false;
646
+ kmRefreshContent(document.getElementById('km-content-area'));
647
+ });
648
+ }
649
+
650
+ // ─── Graph view ───────────────────────────────────────────────
651
+
652
+ function kmRenderGraph(contentEl, entries) {
653
+ if (entries.length === 0) {
654
+ contentEl.innerHTML = '<div class="km-empty-state"><h3>No entries to graph</h3></div>';
655
+ return;
656
+ }
657
+
658
+ if (typeof mermaid === 'undefined') {
659
+ contentEl.innerHTML = '<div class="km-empty-state"><h3>Mermaid.js not loaded</h3><p>Cannot render knowledge graph.</p></div>';
660
+ return;
661
+ }
662
+
663
+ var edges = kmDeriveRelationships(entries);
664
+ var def = kmBuildMermaidDef(entries, edges);
665
+
666
+ var viewport = document.createElement('div');
667
+ viewport.className = 'km-graph-viewport diagram-viewport';
668
+
669
+ var canvas = document.createElement('div');
670
+ canvas.className = 'km-graph-canvas diagram-canvas';
671
+
672
+ var diagramId = 'km-graph-' + Date.now();
673
+ var mermaidDiv = document.createElement('div');
674
+ mermaidDiv.className = 'mermaid';
675
+ mermaidDiv.id = diagramId;
676
+ mermaidDiv.textContent = def;
677
+
678
+ canvas.appendChild(mermaidDiv);
679
+ viewport.appendChild(canvas);
680
+
681
+ // Controls
682
+ var controls = document.createElement('div');
683
+ controls.className = 'diagram-controls';
684
+ controls.innerHTML =
685
+ '<button class="diagram-ctrl-btn" title="Zoom in" data-action="zoom-in">+</button>' +
686
+ '<span class="diagram-zoom-label">100%</span>' +
687
+ '<button class="diagram-ctrl-btn" title="Zoom out" data-action="zoom-out">&minus;</button>' +
688
+ '<button class="diagram-ctrl-btn" title="Fit to view" data-action="fit">&#9638;</button>';
689
+ viewport.appendChild(controls);
690
+ contentEl.appendChild(viewport);
691
+
692
+ // Force full height
693
+ viewport.style.height = '100%';
694
+ viewport.style.minHeight = '400px';
695
+
696
+ mermaid.initialize({
697
+ startOnLoad: false,
698
+ theme: document.documentElement.getAttribute('data-theme') !== 'light' ? 'dark' : 'default',
699
+ securityLevel: 'loose',
700
+ });
701
+
702
+ var graphState = { panX: 0, panY: 0, scale: 1, lastContent: null };
703
+
704
+ try {
705
+ var result = mermaid.run({ nodes: [document.getElementById(diagramId)] });
706
+ var afterRender = function() {
707
+ if (typeof fitDiagramToView === 'function') {
708
+ fitDiagramToView(viewport, canvas, graphState, controls);
709
+ }
710
+ // Attach click handlers to nodes
711
+ kmAttachGraphClicks(viewport, entries);
712
+ };
713
+
714
+ if (result && typeof result.then === 'function') {
715
+ result.then(afterRender);
716
+ } else {
717
+ afterRender();
718
+ }
719
+ } catch(e) {
720
+ contentEl.innerHTML = '<div class="km-empty-state"><h3>Failed to render graph</h3><p>' + esc(e.message) + '</p></div>';
721
+ return;
722
+ }
723
+
724
+ if (typeof initDiagramPanZoom === 'function') {
725
+ initDiagramPanZoom(viewport, canvas, graphState, controls);
726
+ }
727
+ }
728
+
729
+ function kmDeriveRelationships(entries) {
730
+ var edges = [];
731
+ var seen = {};
732
+
733
+ for (var i = 0; i < entries.length; i++) {
734
+ var a = entries[i];
735
+ var aDomains = Array.isArray(a.meta.domain) ? a.meta.domain : (a.meta.domain ? [a.meta.domain] : []);
736
+
737
+ for (var j = i + 1; j < entries.length; j++) {
738
+ var b = entries[j];
739
+ var bDomains = Array.isArray(b.meta.domain) ? b.meta.domain : (b.meta.domain ? [b.meta.domain] : []);
740
+ var key = a.path + '::' + b.path;
741
+ if (seen[key]) continue;
742
+
743
+ // Shared domains
744
+ for (var d = 0; d < aDomains.length; d++) {
745
+ if (bDomains.indexOf(aDomains[d]) !== -1) {
746
+ edges.push({ from: a.path, to: b.path, label: aDomains[d], type: 'domain' });
747
+ seen[key] = true;
748
+ break;
749
+ }
750
+ }
751
+ if (seen[key]) continue;
752
+
753
+ // Content cross-references (title mentions)
754
+ var aTitle = (a.meta.title || '').toLowerCase();
755
+ var bTitle = (b.meta.title || '').toLowerCase();
756
+ var aBody = (a.body || '').toLowerCase();
757
+ var bBody = (b.body || '').toLowerCase();
758
+
759
+ if (aTitle.length > 4 && bBody.indexOf(aTitle) !== -1) {
760
+ edges.push({ from: b.path, to: a.path, label: 'references', type: 'reference' });
761
+ seen[key] = true;
762
+ continue;
763
+ }
764
+ if (bTitle.length > 4 && aBody.indexOf(bTitle) !== -1) {
765
+ edges.push({ from: a.path, to: b.path, label: 'references', type: 'reference' });
766
+ seen[key] = true;
767
+ continue;
768
+ }
769
+
770
+ // Same source_project
771
+ if (a.meta.source_project && b.meta.source_project &&
772
+ a.meta.source_project === b.meta.source_project &&
773
+ a.meta.source_project !== 'Manual entry') {
774
+ edges.push({ from: a.path, to: b.path, label: '', type: 'project' });
775
+ seen[key] = true;
776
+ }
777
+ }
778
+ }
779
+
780
+ return edges;
781
+ }
782
+
783
+ function kmBuildMermaidDef(entries, edges) {
784
+ var TYPE_ICONS = { entities: '🔷', infrastructure: '🔧', patterns: '🧩', features: '⭐' };
785
+ var lines = ['graph LR'];
786
+
787
+ for (var i = 0; i < entries.length; i++) {
788
+ var e = entries[i];
789
+ var nodeId = kmNodeId(e.path);
790
+ var icon = TYPE_ICONS[e.meta.type] || '▪';
791
+ var label = icon + ' ' + (e.meta.title || 'Untitled').replace(/["[\](){}|<>#&]/g, ' ');
792
+ lines.push(' ' + nodeId + '["' + label + '"]');
793
+ }
794
+
795
+ for (var j = 0; j < edges.length; j++) {
796
+ var edge = edges[j];
797
+ var fromId = kmNodeId(edge.from);
798
+ var toId = kmNodeId(edge.to);
799
+
800
+ if (edge.type === 'domain') {
801
+ var safeLabel = (edge.label || '').replace(/[|[\]"]/g, ' ');
802
+ lines.push(' ' + fromId + ' --- |' + safeLabel + '| ' + toId);
803
+ } else if (edge.type === 'reference') {
804
+ lines.push(' ' + fromId + ' --> |references| ' + toId);
805
+ } else {
806
+ lines.push(' ' + fromId + ' -.- ' + toId);
807
+ }
808
+ }
809
+
810
+ // Style classes
811
+ lines.push(' classDef entity fill:#0e1e3a,stroke:#4a8ae8,color:#4a8ae8');
812
+ lines.push(' classDef infra fill:#1e0e2a,stroke:#9a6ac8,color:#9a6ac8');
813
+ lines.push(' classDef pattern fill:#0e2a1a,stroke:#4ac87a,color:#4ac87a');
814
+ lines.push(' classDef feature fill:#2a1e0a,stroke:#c8a04a,color:#c8a04a');
815
+
816
+ for (var k = 0; k < entries.length; k++) {
817
+ var ent = entries[k];
818
+ var nId = kmNodeId(ent.path);
819
+ var cls = { entities: 'entity', infrastructure: 'infra', patterns: 'pattern', features: 'feature' }[ent.meta.type];
820
+ if (cls) lines.push(' class ' + nId + ' ' + cls);
821
+ }
822
+
823
+ return lines.join('\n');
824
+ }
825
+
826
+ function kmNodeId(path) {
827
+ // Convert file path to valid Mermaid node ID
828
+ return 'n_' + path.replace(/[^a-zA-Z0-9]/g, '_');
829
+ }
830
+
831
+ function kmAttachGraphClicks(viewport, entries) {
832
+ var nodes = viewport.querySelectorAll('.node');
833
+ for (var i = 0; i < nodes.length; i++) {
834
+ (function(node) {
835
+ node.style.cursor = 'pointer';
836
+ node.addEventListener('click', function() {
837
+ var nodeId = node.id;
838
+ // Find matching entry
839
+ for (var j = 0; j < entries.length; j++) {
840
+ if (kmNodeId(entries[j].path) === nodeId) {
841
+ // Switch to card view and scroll to that entry
842
+ kmActiveView = 'cards';
843
+ var toggle = document.getElementById('km-view-toggle');
844
+ if (toggle) toggle.textContent = 'Graph View';
845
+ kmRefreshContent(document.getElementById('km-content-area'));
846
+ // After render, find and expand the card
847
+ setTimeout(function() {
848
+ var card = document.querySelector('.km-card[data-path="' + entries[j].path + '"]');
849
+ if (card) {
850
+ card.scrollIntoView({ behavior: 'smooth', block: 'center' });
851
+ kmExpandCard(card, entries[j]);
852
+ }
853
+ }, 100);
854
+ break;
855
+ }
856
+ }
857
+ });
858
+ })(nodes[i]);
859
+ }
860
+ }
861
+
862
+ // ─── Confirmation dialog ──────────────────────────────────────
863
+
864
+ function kmConfirm(message, onConfirm) {
865
+ var overlay = document.createElement('div');
866
+ overlay.className = 'km-confirm-overlay';
867
+ overlay.innerHTML =
868
+ '<div class="km-confirm-box">' +
869
+ '<p>' + esc(message) + '</p>' +
870
+ '<div class="km-edit-actions">' +
871
+ '<button class="km-btn km-btn-danger km-confirm-yes">Yes</button>' +
872
+ '<button class="km-btn km-confirm-no">Cancel</button>' +
873
+ '</div>' +
874
+ '</div>';
875
+ document.body.appendChild(overlay);
876
+
877
+ overlay.querySelector('.km-confirm-yes').addEventListener('click', function() {
878
+ document.body.removeChild(overlay);
879
+ onConfirm();
880
+ });
881
+ overlay.querySelector('.km-confirm-no').addEventListener('click', function() {
882
+ document.body.removeChild(overlay);
883
+ });
884
+ overlay.addEventListener('click', function(e) {
885
+ if (e.target === overlay) document.body.removeChild(overlay);
886
+ });
887
+ }
888
+
889
+ // ─── Panel lifecycle ──────────────────────────────────────────
890
+
891
+ function cleanupKnowledgeMap(panel) {
892
+ // Reset state for fresh render
893
+ knowledgeCache = null;
894
+ }
895
+
896
+ function openKnowledgeMapPanel() {
897
+ kmActiveView = 'cards';
898
+ kmActiveFilters = { search: '', type: 'all', confidence: 'all' };
899
+ kmShowNewForm = false;
900
+ knowledgeCache = null;
901
+ openPanelTab('knowledge-map-main', {
902
+ panel: 'knowledge-map',
903
+ title: 'Knowledge Map',
904
+ data: null,
905
+ });
906
+ }