principles 0.1.3 → 0.1.5

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 (312) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +151 -1
  3. data/README.md +10 -6
  4. data/exe/principles +1 -1
  5. data/lib/principles/cli.rb +9 -10
  6. data/lib/principles/command_line.rb +15 -6
  7. data/lib/principles/command_routes.rb +18 -2
  8. data/lib/principles/controllers/acknowledgement.rb +19 -4
  9. data/lib/principles/controllers/acknowledgements.rb +43 -12
  10. data/lib/principles/controllers/after_commit_report.rb +15 -2
  11. data/lib/principles/controllers/assessment.rb +7 -3
  12. data/lib/principles/controllers/audit.rb +17 -8
  13. data/lib/principles/controllers/audit_completion.rb +34 -9
  14. data/lib/principles/controllers/carrier_edit_report.rb +40 -0
  15. data/lib/principles/controllers/carrier_practices.rb +26 -0
  16. data/lib/principles/controllers/command.rb +36 -5
  17. data/lib/principles/controllers/context_budget.rb +61 -0
  18. data/lib/principles/controllers/correction.rb +15 -5
  19. data/lib/principles/controllers/full_audit_request.rb +38 -42
  20. data/lib/principles/controllers/inventory.rb +78 -71
  21. data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
  22. data/lib/principles/controllers/member_addition.rb +20 -5
  23. data/lib/principles/controllers/member_entries.rb +50 -39
  24. data/lib/principles/controllers/member_entry_changes.rb +71 -0
  25. data/lib/principles/controllers/member_problems_report.rb +26 -6
  26. data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
  27. data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
  28. data/lib/principles/controllers/members_to_assess.rb +35 -8
  29. data/lib/principles/controllers/meta_principle_setup.rb +12 -4
  30. data/lib/principles/controllers/open_correction.rb +3 -2
  31. data/lib/principles/controllers/parts_to_read.rb +48 -6
  32. data/lib/principles/controllers/plugin_member_addition.rb +48 -0
  33. data/lib/principles/controllers/principle_listing.rb +84 -0
  34. data/lib/principles/controllers/request_logging.rb +65 -0
  35. data/lib/principles/controllers/running_tool.rb +55 -15
  36. data/lib/principles/controllers/session_start_report.rb +26 -2
  37. data/lib/principles/data/branches_bringing_in.rb +52 -0
  38. data/lib/principles/data/captured_requests.rb +118 -0
  39. data/lib/principles/data/carrier_page_markers.rb +38 -0
  40. data/lib/principles/data/changes_since.rb +56 -0
  41. data/lib/principles/data/claude_code_home.rb +75 -0
  42. data/lib/principles/data/command-steps.json +139 -23
  43. data/lib/principles/data/decoded_leaf.rb +63 -0
  44. data/lib/principles/data/head_reflog.rb +13 -2
  45. data/lib/principles/data/kept_line.rb +39 -0
  46. data/lib/principles/data/known_marketplaces.rb +50 -0
  47. data/lib/principles/data/logged_request_matches.rb +144 -0
  48. data/lib/principles/data/logged_request_scan.rb +188 -0
  49. data/lib/principles/data/map_files.rb +18 -4
  50. data/lib/principles/data/plugin_folder.rb +85 -0
  51. data/lib/principles/data/plugin_registry.rb +73 -0
  52. data/lib/principles/data/principles_store.rb +49 -0
  53. data/lib/principles/data/project_files.rb +15 -0
  54. data/lib/principles/data/ran.rb +25 -0
  55. data/lib/principles/data/raw_request_filter.rb +61 -0
  56. data/lib/principles/data/repository.rb +29 -27
  57. data/lib/principles/data/request_logging_folder.rb +135 -0
  58. data/lib/principles/data/request_shape.rb +33 -0
  59. data/lib/principles/data/running_version.rb +1 -1
  60. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
  61. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
  62. data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
  63. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  64. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  65. data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
  66. data/lib/principles/data/schemas/member-map.schema.json +12 -1
  67. data/lib/principles/data/settings_env_keys.rb +26 -0
  68. data/lib/principles/data/string_counts.rb +39 -0
  69. data/lib/principles/data/tools_on_path.rb +25 -0
  70. data/lib/principles/data/user_request_logging_folder.rb +73 -0
  71. data/lib/principles/invocation_options.rb +5 -3
  72. data/lib/principles/launch.rb +29 -10
  73. data/lib/principles/models/acknowledged_check.rb +11 -1
  74. data/lib/principles/models/acknowledgement.rb +5 -0
  75. data/lib/principles/models/acknowledgement_refusal.rb +20 -11
  76. data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
  77. data/lib/principles/models/after_commit_input.rb +5 -0
  78. data/lib/principles/models/answer_fields.rb +3 -0
  79. data/lib/principles/models/assessment_basis.rb +10 -3
  80. data/lib/principles/models/audit.rb +10 -10
  81. data/lib/principles/models/audit_record.rb +10 -0
  82. data/lib/principles/models/audit_records.rb +4 -3
  83. data/lib/principles/models/audit_start.rb +9 -0
  84. data/lib/principles/models/authored_locator.rb +33 -0
  85. data/lib/principles/models/candidate_files.rb +23 -3
  86. data/lib/principles/models/candidate_outline.rb +18 -125
  87. data/lib/principles/models/captured_sessions.rb +166 -0
  88. data/lib/principles/models/carrier_edit_input.rb +56 -0
  89. data/lib/principles/models/carrier_kind.rb +79 -0
  90. data/lib/principles/models/carrier_pages_shown.rb +28 -0
  91. data/lib/principles/models/carved_message_bytes.rb +115 -0
  92. data/lib/principles/models/cited_files.rb +12 -3
  93. data/lib/principles/models/context_parts.rb +59 -0
  94. data/lib/principles/models/decided_prior_findings.rb +5 -0
  95. data/lib/principles/models/declared_map_changes.rb +22 -13
  96. data/lib/principles/models/disposition.rb +37 -6
  97. data/lib/principles/models/disposition_placeholders.rb +12 -0
  98. data/lib/principles/models/disposition_text_field.rb +4 -0
  99. data/lib/principles/models/dropped_thinking.rb +73 -0
  100. data/lib/principles/models/feature.rb +54 -0
  101. data/lib/principles/models/finding_outcomes.rb +55 -0
  102. data/lib/principles/models/findings_left_open.rb +9 -11
  103. data/lib/principles/models/head_moves.rb +27 -10
  104. data/lib/principles/models/installed_component.rb +55 -0
  105. data/lib/principles/models/installed_plugins.rb +174 -0
  106. data/lib/principles/models/kept_sessions.rb +34 -0
  107. data/lib/principles/models/locator.rb +8 -0
  108. data/lib/principles/models/logged_request_reach.rb +52 -0
  109. data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
  110. data/lib/principles/models/map_format_raise.rb +28 -0
  111. data/lib/principles/models/mapped_baseline.rb +46 -0
  112. data/lib/principles/models/mapped_principles.rb +2 -1
  113. data/lib/principles/models/maps_holding_file_whole.rb +42 -0
  114. data/lib/principles/models/markdown_text.rb +143 -0
  115. data/lib/principles/models/member.rb +19 -1
  116. data/lib/principles/models/member_entry.rb +56 -0
  117. data/lib/principles/models/member_justification.rb +52 -0
  118. data/lib/principles/models/member_lines.rb +11 -0
  119. data/lib/principles/models/member_loads.rb +17 -2
  120. data/lib/principles/models/member_problems.rb +46 -42
  121. data/lib/principles/models/member_reach.rb +59 -0
  122. data/lib/principles/models/member_snapshots.rb +34 -4
  123. data/lib/principles/models/member_text_as_sent.rb +31 -0
  124. data/lib/principles/models/member_texts.rb +45 -0
  125. data/lib/principles/models/members_by_part.rb +67 -0
  126. data/lib/principles/models/members_in_logged_requests.rb +279 -0
  127. data/lib/principles/models/meta_principle.rb +4 -4
  128. data/lib/principles/models/missing_files.rb +41 -16
  129. data/lib/principles/models/nearly_matching_maps.rb +56 -0
  130. data/lib/principles/models/open_correction.rb +5 -0
  131. data/lib/principles/models/open_finding.rb +4 -3
  132. data/lib/principles/models/outline_budget.rb +10 -1
  133. data/lib/principles/models/outline_item.rb +25 -0
  134. data/lib/principles/models/outline_section.rb +15 -4
  135. data/lib/principles/models/part_named.rb +16 -2
  136. data/lib/principles/models/part_token_estimates.rb +60 -0
  137. data/lib/principles/models/plugin_component.rb +37 -0
  138. data/lib/principles/models/plugin_enabled_in_project_settings.rb +61 -0
  139. data/lib/principles/models/plugin_install.rb +33 -0
  140. data/lib/principles/models/plugin_name.rb +23 -0
  141. data/lib/principles/models/plugin_reference.rb +53 -0
  142. data/lib/principles/models/principle.rb +7 -4
  143. data/lib/principles/models/principle_members.rb +22 -0
  144. data/lib/principles/models/prior_finding_decision.rb +1 -1
  145. data/lib/principles/models/prior_finding_outcomes.rb +12 -1
  146. data/lib/principles/models/problem_report.rb +14 -25
  147. data/lib/principles/models/project.rb +51 -56
  148. data/lib/principles/models/project_harness.rb +48 -0
  149. data/lib/principles/models/project_history.rb +19 -5
  150. data/lib/principles/models/recorded_members.rb +7 -0
  151. data/lib/principles/models/report_hooks.rb +9 -4
  152. data/lib/principles/models/request_channel.rb +62 -0
  153. data/lib/principles/models/request_kind.rb +62 -0
  154. data/lib/principles/models/request_logging.rb +231 -0
  155. data/lib/principles/models/request_logging_guard.rb +84 -0
  156. data/lib/principles/models/request_time.rb +46 -0
  157. data/lib/principles/models/runs_from.rb +0 -5
  158. data/lib/principles/models/script_comments.rb +58 -0
  159. data/lib/principles/models/session_registry.rb +61 -0
  160. data/lib/principles/models/session_start_input.rb +11 -2
  161. data/lib/principles/models/session_trend.rb +36 -0
  162. data/lib/principles/models/stale_request.rb +9 -0
  163. data/lib/principles/models/turn_opening.rb +83 -0
  164. data/lib/principles/models/turn_position.rb +43 -0
  165. data/lib/principles/models/unfixed_part.rb +82 -0
  166. data/lib/principles/models/unresolved_plugin_members.rb +35 -0
  167. data/lib/principles/models/user_logged_requests.rb +90 -0
  168. data/lib/principles/models/user_settings_entries.rb +49 -0
  169. data/lib/principles/models/whole_file_member_read.rb +48 -0
  170. data/lib/principles/models/without_prose.rb +20 -0
  171. data/lib/principles/models/workflow_jobs.rb +92 -0
  172. data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
  173. data/lib/principles/show_principle_options.rb +32 -0
  174. data/lib/principles/version.rb +2 -2
  175. data/lib/principles/views/acknowledged_result.rb +31 -12
  176. data/lib/principles/views/acknowledgement_result.rb +18 -13
  177. data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
  178. data/lib/principles/views/acknowledgements_offered.rb +54 -0
  179. data/lib/principles/views/added_member.rb +22 -6
  180. data/lib/principles/views/answer_in_a_file.rb +15 -15
  181. data/lib/principles/views/assessed_members.rb +19 -8
  182. data/lib/principles/views/assessment_request.rb +14 -6
  183. data/lib/principles/views/audit_changes.rb +14 -8
  184. data/lib/principles/views/audit_findings.rb +34 -0
  185. data/lib/principles/views/audit_result.rb +26 -24
  186. data/lib/principles/views/candidate_files_result.rb +1 -1
  187. data/lib/principles/views/carrier_checks.rb +40 -0
  188. data/lib/principles/views/carrier_edit_denial.rb +36 -0
  189. data/lib/principles/views/carrier_practices_page.rb +49 -0
  190. data/lib/principles/views/completed_audit_findings.rb +33 -0
  191. data/lib/principles/views/completed_audit_next_step.rb +12 -4
  192. data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
  193. data/lib/principles/views/context_budget_result.rb +99 -0
  194. data/lib/principles/views/context_parts.rb +129 -25
  195. data/lib/principles/views/correction_request.rb +32 -17
  196. data/lib/principles/views/disposition_template.rb +35 -0
  197. data/lib/principles/views/first_audit.rb +29 -15
  198. data/lib/principles/views/first_audit_line.rb +4 -5
  199. data/lib/principles/views/hook_setup_result.rb +3 -1
  200. data/lib/principles/views/invocation.rb +14 -5
  201. data/lib/principles/views/last_record_notice.rb +41 -0
  202. data/lib/principles/views/lines_shared_with_member.rb +16 -22
  203. data/lib/principles/views/logged_request_status_meanings.rb +29 -0
  204. data/lib/principles/views/logged_requests_evidence.rb +84 -0
  205. data/lib/principles/views/map_added_to.rb +14 -12
  206. data/lib/principles/views/map_format_raised.rb +28 -0
  207. data/lib/principles/views/map_result.rb +41 -18
  208. data/lib/principles/views/maps_needing_members_or_audit.rb +1 -1
  209. data/lib/principles/views/member_change_since_baseline.rb +4 -0
  210. data/lib/principles/views/member_row.rb +13 -4
  211. data/lib/principles/views/member_sets_overlap.rb +31 -0
  212. data/lib/principles/views/members_a_commit_changed.rb +42 -25
  213. data/lib/principles/views/members_changed_during_audit.rb +27 -0
  214. data/lib/principles/views/members_in_logged_requests_result.rb +123 -0
  215. data/lib/principles/views/members_too_short_to_scan.rb +45 -0
  216. data/lib/principles/views/members_with_no_baseline.rb +6 -6
  217. data/lib/principles/views/meta_principle_result.rb +52 -15
  218. data/lib/principles/views/open_findings_line.rb +31 -92
  219. data/lib/principles/views/parts_index_result.rb +9 -5
  220. data/lib/principles/views/principle_read_result.rb +52 -11
  221. data/lib/principles/views/prior_findings_result.rb +9 -1
  222. data/lib/principles/views/problem_facts.rb +5 -3
  223. data/lib/principles/views/problem_lines.rb +54 -6
  224. data/lib/principles/views/problem_result.rb +7 -15
  225. data/lib/principles/views/prompts/assess-every-member/ask-whether-a-member-seen-only-as-read-is-loaded.md +3 -0
  226. data/lib/principles/views/prompts/assess-every-member/ask-whether-each-reason-holds.md +2 -0
  227. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
  228. data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-against-the-other-principles.md +2 -0
  229. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
  230. data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
  231. data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
  232. data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
  233. data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
  234. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  235. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +6 -1
  236. data/lib/principles/views/prompts/dispose-of-each-finding/read-the-carrier-page-before-fixing.md +1 -0
  237. data/lib/principles/views/prompts/edit-a-carrier/read-the-page-before-the-first-edit.md +2 -0
  238. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
  239. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
  240. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
  241. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
  242. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
  243. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
  244. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
  245. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
  246. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +49 -51
  247. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-name.md +12 -0
  248. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-reason.md +12 -0
  249. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
  250. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -1
  251. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
  252. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
  253. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  254. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
  255. data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +22 -0
  256. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
  257. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +8 -4
  258. data/lib/principles/views/prompts/learn-what-a-command-does/report-before-carrier-edit.md +13 -0
  259. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
  260. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
  261. data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
  262. data/lib/principles/views/prompts/learn-what-a-command-does/show-context-budget.md +69 -0
  263. data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +4 -4
  264. data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +22 -0
  265. data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +62 -0
  266. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +13 -10
  267. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +16 -16
  268. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
  269. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +17 -17
  270. data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +18 -0
  271. data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +44 -0
  272. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
  273. data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
  274. data/lib/principles/views/prompts/read-what-reached-the-context/explain-user-request-logging-to-the-user.md +10 -0
  275. data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
  276. data/lib/principles/views/prompts/read-what-reached-the-context/what-a-thread-continuation-holds.md +3 -0
  277. data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
  278. data/lib/principles/views/prompts/read-what-reached-the-context/what-each-context-budget-line-says.md +4 -0
  279. data/lib/principles/views/prompts/read-what-reached-the-context/what-each-member-line-says.md +2 -0
  280. data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
  281. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
  282. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
  283. data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
  284. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-audit-asks-to-acknowledge-or-audit-again.md +1 -0
  285. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-mapping-commit-asks-for-an-audit.md +1 -0
  286. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-pinned-asks-for-an-audit.md +1 -0
  287. data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
  288. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
  289. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
  290. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
  291. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -0
  292. data/lib/principles/views/prompts/set-principles-up/ask-to-set-principles-up-after-an-audit.md +1 -0
  293. data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
  294. data/lib/principles/views/prompts/set-principles-up/map-the-enabling-line-at-no-edit.md +3 -0
  295. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -2
  296. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +4 -2
  297. data/lib/principles/views/prompts/set-principles-up/what-the-passage-presumes.md +1 -1
  298. data/lib/principles/views/prompts/set-principles-up/why-set-principles-up.md +1 -0
  299. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
  300. data/lib/principles/views/prompts/start-a-session/ask-to-set-principles-up.md +2 -0
  301. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
  302. data/lib/principles/views/prompts/start-a-session/name-the-principles-nothing-checks.md +1 -0
  303. data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
  304. data/lib/principles/views/request_logging_result.rb +108 -0
  305. data/lib/principles/views/request_part.rb +10 -4
  306. data/lib/principles/views/request_parts.rb +9 -0
  307. data/lib/principles/views/set_up_offer_line.rb +43 -0
  308. data/lib/principles/views/whole_file_elsewhere.rb +30 -0
  309. metadata +154 -5
  310. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
  311. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
  312. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +0 -2
@@ -1,34 +1,17 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../error"
5
- require_relative "frontmatter_fields"
4
+ require_relative "markdown_text"
6
5
  require_relative "outline_group"
7
- require_relative "outline_section"
8
- require_relative "text_within"
6
+ require_relative "script_comments"
7
+ require_relative "workflow_jobs"
9
8
 
10
9
  module Principles
11
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
11
  module Models
13
- # One candidate file's outline, as the survey reads it in place of the file: its Markdown headings in order, and
14
- # under each its top-level list items. One user scripted a heading grep over 45 files to survey them,
15
- # and missed a principles section written as one numbered list, so this tool prints both.
12
+ # One candidate file's outline, as the survey reads it in place of the file: the sections of the text it outlines,
13
+ # and that text's description and opening line when it has them, cut to fit a budget.
16
14
  class CandidateOutline
17
- HEADING = /\A#+\s/
18
- FENCE = /\A\s*(?:```|~~~)/
19
- # A top-level list item, its marker and its text; an indented one is nested, and left out.
20
- ITEM = /\A(\d+\.|[-*])\s+(.*)/
21
- # A horizontal rule, such as `* * *` or `- - -`, which is no item.
22
- RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
23
- LINK = /\[([^\]]*)\]\([^)]*\)/
24
- BOLD_LEAD = /\A\*\*[^*]+\*\*/
25
- # The most characters of an item printed, cut back to a whole word.
26
- ITEM_CHARACTERS = 60
27
- # The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
28
- # mid-clause left 30 of one user's 45 opening lines a fragment. The line is short only when
29
- # its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
30
- # accepted, since the file's path and outline still say what it holds.
31
- OPENING_CHARACTERS = 160
32
15
  # The cuts that shorten an outline to fit a budget, in the order they are made, each keeping those before it.
33
16
  # The last leaves the whole outline out, which a big enough project needs once every other cut is made.
34
17
  CUTS = %w[description items headings opening_line outline].freeze
@@ -36,19 +19,11 @@ module Principles
36
19
  ENTRY_FILE_CUTS = CUTS.length - 1 #: Integer
37
20
  # The deepest heading level a cut outline keeps once its headings are folded.
38
21
  FOLDED_BELOW = 2
39
- # The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
40
- # one user's descriptions printed 12,537 B uncut, and suggested about 300.
41
- DESCRIPTION_CHARACTERS = 300
42
22
 
43
- # A description's key and any block scalar indicator, which its text starts after.
44
- DESCRIPTION_KEY = /\Adescription:\s*(?:[>|][-+]?\s)?/
45
- # A value inside a matching pair of quotes, printed without them; its escapes are left as written.
46
- QUOTED = /\A(["'])(.*)\1\z/
47
-
48
- #: (String) -> void
49
- def initialize(text)
50
- @lines = text.lines #: Array[String]
51
- @frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
23
+ # The file's text, read as the kind of text `as` names.
24
+ #: (String, ?as: singleton(MarkdownText) | singleton(ScriptComments) | singleton(WorkflowJobs)) -> void
25
+ def initialize(text, as: MarkdownText)
26
+ @text = as.new(text) #: MarkdownText | ScriptComments | WorkflowJobs
52
27
  freeze
53
28
  end
54
29
 
@@ -58,14 +33,16 @@ module Principles
58
33
  def to_h(cuts: 0)
59
34
  return {} if left_out?(cuts)
60
35
 
61
- { "description" => made?("description", cuts) ? cut_description : description,
62
- "opening_line" => (opening_line unless made?("opening_line", cuts) && description),
36
+ description = @text.description
37
+ { "description" => made?("description", cuts) ? @text.cut_description : description,
38
+ "opening_line" => (@text.opening_line unless made?("opening_line", cuts) && description),
63
39
  "outline" => outline_lines(cuts) }.compact
64
40
  end
65
41
 
66
- # Whether the first `cuts` of CUTS cut the outline's lines, rather than only its description.
42
+ # Whether the outline's lines are cut once the first `cuts` of CUTS are made: by those cuts, rather than only its
43
+ # description, or by a section leaving items out past OutlineSection::MOST_ITEMS before any cut.
67
44
  #: (Integer) -> bool
68
- def outline_cut?(cuts) = made?("items", cuts)
45
+ def outline_cut?(cuts) = made?("items", cuts) || sections.any?(&:leaves_items_out?)
69
46
 
70
47
  # Whether the first `cuts` of CUTS leave the whole outline out, the file printing its path and size alone.
71
48
  #: (Integer) -> bool
@@ -79,16 +56,9 @@ module Principles
79
56
  #: () -> Array[String]
80
57
  def cut_lines = sections.flat_map(&:cut_lines)
81
58
 
82
- # Each heading with the items under it, and the items before the first heading when there are any, each with
83
- # the lines of the file it spans.
59
+ # The text's sections, each a heading with the items under it and the lines of the file it spans.
84
60
  #: () -> Array[OutlineSection]
85
- def sections
86
- body = unfenced
87
- starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
88
- starts.zip(starts.drop(1)).filter_map do |first, after|
89
- section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
90
- end
91
- end
61
+ def sections = @text.sections
92
62
 
93
63
  private
94
64
 
@@ -96,7 +66,7 @@ module Principles
96
66
  # headings folded into the heading above, whose 11,112 B kept one user's result over budget.
97
67
  #: (Integer) -> Array[String]
98
68
  def outline_lines(cuts)
99
- return lines unless outline_cut?(cuts)
69
+ return lines unless made?("items", cuts)
100
70
  return cut_lines unless made?("headings", cuts)
101
71
 
102
72
  groups.flat_map(&:folded_lines)
@@ -113,83 +83,6 @@ module Principles
113
83
  # Whether the first `cuts` of CUTS include the one named.
114
84
  #: (String, Integer) -> bool
115
85
  def made?(cut, cuts) = CUTS.take(cuts).include?(cut)
116
-
117
- # The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
118
- # heading nor an item.
119
- #: (Array[String], first_line: Integer) -> OutlineSection?
120
- def section(lines, first_line:)
121
- heading = lines.first if lines.first&.match?(HEADING)
122
- items = lines.select { |line| item?(line) }.map { |line| item(line) }
123
- return nil unless heading || items.any?
124
-
125
- OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
126
- end
127
-
128
- # A top-level list item, not a horizontal rule written with the same marks.
129
- #: (String) -> bool
130
- def item?(line) = line.match?(ITEM) && !line.match?(RULE)
131
-
132
- # The index in the file of the body's first line, after any frontmatter.
133
- #: () -> Integer
134
- def body_start = (@frontmatter.closing_line || -1) + 1
135
-
136
- # The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
137
- #: () -> String?
138
- def description
139
- written = @frontmatter.field_lines("$.description") or return nil
140
- text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
141
- text[QUOTED, 2] || text
142
- rescue Error
143
- nil
144
- end
145
-
146
- # The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
147
- # characters it holds and the lines of the file that hold it, so the agent reads just those back.
148
- #: () -> String?
149
- def cut_description
150
- text = description or return nil
151
- within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
152
- return text unless within.cut?
153
-
154
- kept = within.kept
155
- first, last = @frontmatter.field("$.description")
156
- "#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
157
- end
158
-
159
- # The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
160
- # joined, with links as their text. The first physical line was a fragment in a hard-wrapped file.
161
- #: () -> String?
162
- def opening_line
163
- body = unfenced
164
- first = body.index { |line| prose?(line) } or return nil
165
- paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
166
- TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
167
- end
168
-
169
- #: (String) -> bool
170
- def prose?(line)
171
- text = line.strip
172
- !text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
173
- end
174
-
175
- # The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
176
- #: () -> Array[String]
177
- def unfenced
178
- fenced = false #: bool
179
- body = @lines.drop(body_start).map(&:chomp)
180
- body.map do |line|
181
- fenced = !fenced if line.match?(FENCE)
182
- fenced || line.match?(FENCE) ? "" : line
183
- end
184
- end
185
-
186
- # An item by its marker and its bold lead, or its opening words, with links as their text.
187
- #: (String) -> String
188
- def item(line)
189
- marker, text = line.match(ITEM)&.captures
190
- text = text.to_s.gsub(LINK, '\1')
191
- "#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: ITEM_CHARACTERS).by_words}"
192
- end
193
86
  end
194
87
  end
195
88
  end
@@ -0,0 +1,166 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../data/request_logging_folder"
5
+ require_relative "request_time"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # What the host captured under requests/, read from its files and its index: each session's requests, files and
11
+ # bytes, and the request files no index line names, whose cause is the agent's to judge.
12
+ class CapturedSessions
13
+ # Files counted, and their bytes.
14
+ class Tally
15
+ #: Integer
16
+ attr_reader :files, :bytes
17
+
18
+ #: (files: Integer, bytes: Integer) -> void
19
+ def initialize(files:, bytes:)
20
+ @files = files
21
+ @bytes = bytes
22
+ freeze
23
+ end
24
+
25
+ #: () -> Hash[String, Integer]
26
+ def to_h = { "files" => @files, "bytes" => @bytes }
27
+ end
28
+
29
+ # One session's tally: its requests, the files they and their responses fill, and those files' bytes, and when
30
+ # its first and last requests were sent, in UTC, from those of its index lines' timestamps that are times.
31
+ class Session
32
+ #: String
33
+ attr_reader :session_id
34
+ #: Integer
35
+ attr_reader :requests
36
+ #: Tally
37
+ attr_reader :tally
38
+
39
+ # sent_at is when each of its requests was sent, as its index lines give it.
40
+ #: (String, Integer, Tally, Array[RequestTime]) -> void
41
+ def initialize(session_id, requests, tally, sent_at)
42
+ @session_id = session_id
43
+ @requests = requests
44
+ @tally = tally
45
+ @sent_at = sent_at.select(&:utc).sort.freeze #: Array[RequestTime]
46
+ freeze
47
+ end
48
+
49
+ # When its first request was sent; none, sorting last, when no line of it gives a time.
50
+ #: () -> RequestTime
51
+ def first_sent = @sent_at.first || RequestTime.new(nil)
52
+
53
+ #: () -> Hash[String, untyped]
54
+ def to_h
55
+ { "session_id" => @session_id, "requests" => @requests, **@tally.to_h,
56
+ "first_request_at" => @sent_at.first&.utc, "last_request_at" => @sent_at.last&.utc }
57
+ end
58
+ end
59
+
60
+ #: (Array[Data::CapturedRequests::CapturedFile], Array[Data::CapturedRequests::IndexLine]) -> void
61
+ def initialize(files, index_lines)
62
+ @files = files.to_h { |file| [file.name, file] } #: Hash[String, Data::CapturedRequests::CapturedFile]
63
+ @index_lines = index_lines
64
+ freeze
65
+ end
66
+
67
+ # Only the sessions session_ids names, with the files their lines name, so no other session's file, and no
68
+ # request no line names, is counted or removed.
69
+ #: (Array[String]) -> CapturedSessions
70
+ def of(session_ids)
71
+ lines = @index_lines.select { |line| session_ids.include?(line.session_id) }
72
+ CapturedSessions.new(lines.flat_map { |line| named_files(line) }.uniq, lines)
73
+ end
74
+
75
+ # Each session the index names, once, in the order it first names it.
76
+ #: () -> Array[String]
77
+ def session_ids = @index_lines.map(&:session_id).uniq
78
+
79
+ # The files counted here that other does not count.
80
+ #: (CapturedSessions) -> Array[Data::CapturedRequests::CapturedFile]
81
+ def files_apart_from(other) = @files.values.reject { |file| other.file_names.include?(file.name) }
82
+
83
+ # The name of each file counted here.
84
+ #: () -> Array[String]
85
+ def file_names = @files.keys
86
+
87
+ # Each session the index names, by when its first request was sent, those with no time last in the order the
88
+ # index first names them.
89
+ #: () -> Array[Session]
90
+ def sessions
91
+ named = @index_lines.group_by(&:session_id).map { |session_id, lines| session(session_id, lines) }
92
+ named.each_with_index.sort_by { |session, first| [session.first_sent, first] }.map(&:first)
93
+ end
94
+
95
+ # The request files no index line names, counted, and their bytes.
96
+ #: () -> Tally
97
+ def orphans
98
+ unnamed = unnamed_requests
99
+ Tally.new(files: unnamed.size, bytes: unnamed.sum(&:bytes))
100
+ end
101
+
102
+ # When the newest request file was written, which says whether requests still arrive, or nil before any.
103
+ #: () -> Time?
104
+ def newest_request_written_at
105
+ @files.values.select { |file| file.name.end_with?(".request.json") }.map(&:modified_at).max
106
+ end
107
+
108
+ # Whether the host captured no request yet, as before a session is launched with capture on.
109
+ #: () -> bool
110
+ def none? = newest_request_written_at.nil?
111
+
112
+ # The session of the index's newest line, by its timestamp, or nil before the index has one. It compares the
113
+ # timestamps as text, which orders them only while the host writes them in one ISO 8601 form, not yet seen on a
114
+ # real launch.
115
+ #: () -> String?
116
+ def newest_session_id = @index_lines.max_by(&:timestamp)&.session_id
117
+
118
+ # The names of the files the index names for every session but the newest keep, ranked by each session's
119
+ # newest line, as newest_session_id compares them, leaving every file a kept session also names; then the
120
+ # request files no line names that were written before every kept session's file. With no session kept, every
121
+ # such file stays, since it may belong to a session still running.
122
+ #: (Integer) -> Array[String]
123
+ def older_than_newest(keep)
124
+ ranked = @index_lines.group_by(&:session_id).values.sort_by { |lines| lines.map(&:timestamp).max.to_s }
125
+ kept = ranked.last(keep).flatten
126
+ names(ranked.flatten - kept) - names(kept) + orphans_written_before(kept)
127
+ end
128
+
129
+ private
130
+
131
+ # The session session_id names, from its index lines: their count, the files they name and when each was sent.
132
+ #: (String, Array[Data::CapturedRequests::IndexLine]) -> Session
133
+ def session(session_id, lines)
134
+ files = lines.flat_map { |line| named_files(line) }.uniq
135
+ Session.new(session_id, lines.size, Tally.new(files: files.size, bytes: files.sum(&:bytes)),
136
+ lines.map { |line| RequestTime.new(line.timestamp) })
137
+ end
138
+
139
+ #: (Array[Data::CapturedRequests::IndexLine]) -> Array[String]
140
+ def orphans_written_before(kept)
141
+ oldest = kept.flat_map { |line| named_files(line) }.map(&:modified_at).min
142
+ return [] unless oldest
143
+
144
+ unnamed_requests.select { |file| file.modified_at < oldest }.map(&:name)
145
+ end
146
+
147
+ #: () -> Array[Data::CapturedRequests::CapturedFile]
148
+ def unnamed_requests
149
+ indexed = @index_lines.map { |line| base_name(line.request_file) }
150
+ @files.values.select { |file| file.name.end_with?(".request.json") && !indexed.include?(file.name) }
151
+ end
152
+
153
+ #: (Array[Data::CapturedRequests::IndexLine]) -> Array[String]
154
+ def names(lines) = lines.flat_map { |line| named_files(line) }.map(&:name).uniq
155
+
156
+ #: (String) -> String
157
+ def base_name(path) = path.split("/").last.to_s
158
+
159
+ # The files a line names that the folder holds, by name, since the index names them by their full paths.
160
+ #: (Data::CapturedRequests::IndexLine) -> Array[Data::CapturedRequests::CapturedFile]
161
+ def named_files(line)
162
+ [line.request_file, line.response_file].filter_map { |path| @files[base_name(path)] }
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "carrier_kind"
6
+ require_relative "project"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # The JSON a PreToolUse hook on Edit and Write is given on stdin, as far as report-before-carrier-edit reads it:
12
+ # the session and the carrier kind of the file the call would edit, inside the project. Input that is not JSON,
13
+ # names a session that is no plain name, or a file outside the project, gives no kind, since a hook reports what
14
+ # it can rather than refuse.
15
+ class CarrierEditInput
16
+ # A session id safe to name a folder by.
17
+ PLAIN = /\A[A-Za-z0-9_-]+\z/ #: Regexp
18
+
19
+ # The session the call is in, or nil.
20
+ #: String?
21
+ attr_reader :session
22
+
23
+ # text is the hook's input; project is the session's project, which places the file the call names.
24
+ #: (String, Project) -> void
25
+ def initialize(text, project)
26
+ given = parsed(text)
27
+ given = {} unless given.is_a?(Hash)
28
+ session = given["session_id"]
29
+ @session = session.is_a?(String) && PLAIN.match?(session) ? session : nil #: String?
30
+ tool_input = given["tool_input"]
31
+ file = tool_input["file_path"] if tool_input.is_a?(Hash)
32
+ @path = file.is_a?(String) ? project.harness.path_in_project(file) : nil #: String?
33
+ freeze
34
+ end
35
+
36
+ # The carrier kind of the file the call would edit, or nil when there is no session, no file in the project,
37
+ # or no kind a host loads by itself.
38
+ #: () -> String?
39
+ def kind
40
+ return nil unless @session && @path
41
+
42
+ name = CarrierKind.new(@path).name
43
+ name == CarrierKind::NONE ? nil : name
44
+ end
45
+
46
+ private
47
+
48
+ #: (String) -> untyped
49
+ def parsed(text)
50
+ JSON.parse(text)
51
+ rescue JSON::ParserError
52
+ nil
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,79 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "agent_loads"
7
+ require_relative "hook_commands"
8
+ require_relative "plugin_reference"
9
+
10
+ module Principles
11
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
+ module Models
13
+ # The kind of harness carrier a member's file is, by its path, whose own practices a request names for judging and
14
+ # editing it: an instruction file, a rule, a skill or a subagent, a plugin's too, a hook configuration, a script a
15
+ # hook command names, or none when no host loads the path by itself.
16
+ # Text a program prints into context has no kind here: the path cannot show it, so the agent judges it.
17
+ class CarrierKind
18
+ # The instruction files a host reads in a folder, Claude Code's and Codex's, at the root or below it.
19
+ INSTRUCTION_FILE = %r{(?:\A|/)(?:CLAUDE\.md|\.claude/CLAUDE\.md|CLAUDE\.local\.md|AGENTS\.md)\z} #: Regexp
20
+
21
+ # A rule file in a .claude/rules folder, at the root or below it.
22
+ RULE_FILE = %r{(?:\A|/)\.claude/rules/.+\.md\z} #: Regexp
23
+
24
+ # A skill's file in any skills folder: under .claude, as SkillLoads::SKILL_FILE, whose loading it derives, or at a
25
+ # plugin's root, such as a project's own plugin folder, whose loading it does not.
26
+ SKILL_IN_ANY_SKILLS_FOLDER = %r{(?:\A|/)skills/[^/]+/SKILL\.md\z} #: Regexp
27
+
28
+ # A plugin member's agent file, in the agents folder at the plugin's root.
29
+ PLUGIN_AGENT_FILE = %r{\A#{Regexp.escape(PluginReference::PREFIX)}[^/]+/agents/(?:[^/]+/)*[^/]+\.md\z} #: Regexp
30
+
31
+ # The hooks file at a plugin's root, or a project's own plugin folder, beside the settings files hooks are read
32
+ # from.
33
+ HOOKS_FILE = %r{(?:\A|/)hooks/hooks\.json\z} #: Regexp
34
+
35
+ # Each kind a path alone shows, in the order they are tried, with the paths that make a file one.
36
+ BY_PATH = {
37
+ "instructions" => [INSTRUCTION_FILE],
38
+ "rule" => [RULE_FILE],
39
+ "skill" => [SKILL_IN_ANY_SKILLS_FOLDER],
40
+ "subagent" => [AgentLoads::AGENT_FILE, PLUGIN_AGENT_FILE],
41
+ "hook_configuration" => [HOOKS_FILE, *HookCommands::ON_EVERY_HOST.map { /\A#{Regexp.escape(it)}\z/ }]
42
+ }.freeze #: Hash[String, Array[Regexp]]
43
+
44
+ # The kind of a file no host loads by itself.
45
+ NONE = "none" #: String
46
+
47
+ # Every kind's name: those a path shows, then a hook script and none.
48
+ NAMES = [*BY_PATH.keys, "hook_script", NONE].freeze #: Array[String]
49
+
50
+ # name, as an agent gives it, refused unless it is one of NAMES.
51
+ #: (String) -> String
52
+ def self.named(name)
53
+ return name if NAMES.include?(name)
54
+
55
+ raise Error.new("unknown_carrier_kind", "There is no carrier kind named #{name.inspect}.",
56
+ "Name one of #{ProseList.new(NAMES)}.")
57
+ end
58
+
59
+ # named_in_hooks is whether a hook command names the file, which makes a file no other kind holds a hook script.
60
+ #: (String, ?named_in_hooks: bool) -> void
61
+ def initialize(path, named_in_hooks: false)
62
+ @path = path
63
+ @named_in_hooks = named_in_hooks
64
+ freeze
65
+ end
66
+
67
+ # The kind's name, as show-carrier-practices takes it: the first BY_PATH names, or else a hook script or none.
68
+ #: () -> String
69
+ def name
70
+ by_path = BY_PATH.find { |_, paths| paths.any? { it.match?(@path) } }&.first
71
+ by_path || (@named_in_hooks ? "hook_script" : NONE)
72
+ end
73
+
74
+ # Whether a host loads a file of this kind by itself, so its absence from a request is not expected.
75
+ #: () -> bool
76
+ def carrier? = name != NONE
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,28 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../data/carrier_page_markers"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # Which carrier kinds' practices pages each session was pointed at before its first edit of that kind, kept in the
10
+ # temporary folder, so each kind is asked once a session and a new session asks again.
11
+ class CarrierPagesShown
12
+ #: (String) -> void
13
+ def initialize(temp_directory)
14
+ @markers = Data::CarrierPageMarkers.new(temp_directory) #: Data::CarrierPageMarkers
15
+ freeze
16
+ end
17
+
18
+ # Whether session should be pointed at kind's page now: it has not been yet, and it is recorded as pointed now,
19
+ # so the retry goes through. A marker that cannot be left points nowhere, so no edit is denied twice.
20
+ #: (String, String) -> bool
21
+ def point_now?(session, kind)
22
+ return false if @markers.marked?(session, kind)
23
+
24
+ @markers.mark(session, kind)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,115 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "../data/decoded_leaf"
6
+ require_relative "request_channel"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # The bytes of a request's messages that the host added itself, by the part of the context each is: the text of
12
+ # each string split at its reminder tags, each piece's channel told by RequestChannel, and its bytes counted as
13
+ # JSON writes it inside the string, so the pieces of a string sum to its bytes there. Counts alone, never text.
14
+ class CarvedMessageBytes
15
+ # Each part carved, as [part, kind], in the order they print: a system notice's kind is resent when the same
16
+ # text was sent earlier in the request, told from structure alone, never by reading what it says.
17
+ CARVED = [["reminders", nil], %w[system_notices first_sent], %w[system_notices resent]]
18
+ .freeze #: Array[[String, String?]]
19
+ # The keys under a message's content whose strings are what it says.
20
+ SAID = %w[text content].freeze #: Array[String]
21
+ TAGS = Data::DecodedLeaf::TAGS
22
+ SEGMENT_AFTER = Data::DecodedLeaf::SEGMENT_AFTER
23
+
24
+ #: (Array[untyped]) -> void
25
+ def initialize(messages)
26
+ @messages = messages
27
+ freeze
28
+ end
29
+
30
+ # Each part carved, as CARVED lists them, with its bytes.
31
+ #: () -> Array[Hash[String, untyped]]
32
+ def to_a
33
+ totals = carved
34
+ CARVED.map do |part, kind|
35
+ { "part" => part, **(kind ? { "kind" => kind } : {}), "bytes" => totals[[part, kind]] }
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # The bytes carved into each part, by [part, kind].
42
+ #: () -> Hash[[String, String?], Integer]
43
+ def carved
44
+ totals = CARVED.to_h { [it, 0] }
45
+ sent = {} #: Hash[String, bool]
46
+ each_said do |path, role, text|
47
+ pieces(text) do |segment, piece|
48
+ part = part_of(RequestChannel.new(path, segment, role:).to_s, piece, sent)
49
+ totals[part] = totals.fetch(part) + written(piece) if part
50
+ end
51
+ end
52
+ totals
53
+ end
54
+
55
+ # Each string a message says, with its path, keys and indexes joined by dots, and its message's role.
56
+ #: () { (String, String?, String) -> void } -> void
57
+ def each_said(&said)
58
+ each_string(@messages, ["messages"]) do |path, text|
59
+ said.call(path.join("."), role_at(path), text) if said?(path)
60
+ end
61
+ end
62
+
63
+ # The part a piece by channel is carved into, or nil where it stays in the conversation; a system notice's kind
64
+ # by whether sent holds the same piece already, which it then does.
65
+ #: (String, String, Hash[String, bool]) -> [String, String?]?
66
+ def part_of(channel, piece, sent)
67
+ return ["reminders", nil] if channel == "reminder"
68
+ return unless channel == "system_message"
69
+
70
+ resent = sent.key?(piece)
71
+ sent[piece] = true
72
+ ["system_notices", resent ? "resent" : "first_sent"]
73
+ end
74
+
75
+ # Each string in value, with its path from path, keys and indexes as strings.
76
+ #: (untyped, Array[String]) { (Array[String], String) -> void } -> void
77
+ def each_string(value, path, &found)
78
+ case value
79
+ when Hash then value.each { |key, inner| each_string(inner, [*path, key.to_s], &found) }
80
+ when Array then value.each_with_index { |inner, index| each_string(inner, [*path, index.to_s], &found) }
81
+ when String then found.call(path, value)
82
+ end
83
+ end
84
+
85
+ # Whether the string at path is text a message says, in its content, rather than a field naming its role, a
86
+ # block's type or an id.
87
+ #: (Array[String]) -> bool
88
+ def said?(path) = path[2] == "content" && (path.size == 3 || SAID.include?(path.last))
89
+
90
+ # The role of the message path lies in, or nil for none that is a string.
91
+ #: (Array[String]) -> String?
92
+ def role_at(path)
93
+ message = @messages[Integer(path.fetch(1))]
94
+ role = message.is_a?(Hash) ? message["role"] : nil
95
+ role.is_a?(String) ? role : nil
96
+ end
97
+
98
+ # Each piece of text with its segment, as DecodedLeaf splits it, each tag a reminder piece of its own.
99
+ #: (String) { (String, String) -> void } -> void
100
+ def pieces(text, &piece_in)
101
+ segment = "plain"
102
+ text.split(TAGS, -1).each do |piece|
103
+ next piece_in.call(segment, piece) unless SEGMENT_AFTER.key?(piece)
104
+
105
+ piece_in.call("reminder", piece)
106
+ segment = SEGMENT_AFTER.fetch(piece)
107
+ end
108
+ end
109
+
110
+ # The bytes piece takes inside a JSON string.
111
+ #: (String) -> Integer
112
+ def written(piece) = JSON.generate(piece).bytesize - 2
113
+ end
114
+ end
115
+ end
@@ -3,6 +3,8 @@
3
3
 
4
4
  require_relative "assessment_report"
5
5
  require_relative "project_history"
6
+ require_relative "installed_plugins"
7
+ require_relative "plugin_reference"
6
8
 
7
9
  module Principles
8
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -31,9 +33,16 @@ module Principles
31
33
  changed.uniq.sort
32
34
  end
33
35
 
34
- # Each cited file that no longer exists, in git or outside it.
35
- #: () -> Array[String]
36
- def missing = @paths - @history.existing(@paths)
36
+ # Each cited file that no longer exists, in git or outside it; a plugin's file, which is not in the project,
37
+ # when the plugin installed now does not hold it.
38
+ #: (InstalledPlugins) -> Array[String]
39
+ def missing(plugins)
40
+ existing = @history.existing(@paths)
41
+ @paths.reject do |path|
42
+ reference = PluginReference.in(path)
43
+ reference ? plugins.holds?(reference) : existing.include?(path)
44
+ end
45
+ end
37
46
  end
38
47
  end
39
48
  end