principles 0.0.7 → 0.0.8

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 (331) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +383 -0
  3. data/LICENSE +202 -0
  4. data/NOTICE +4 -0
  5. data/README.md +111 -0
  6. data/exe/principles +20 -0
  7. data/lib/principles/after_commit_hook_options.rb +2 -2
  8. data/lib/principles/cli.rb +50 -42
  9. data/lib/principles/command_line.rb +22 -16
  10. data/lib/principles/command_routes.rb +20 -6
  11. data/lib/principles/controllers/acknowledgement.rb +29 -74
  12. data/lib/principles/controllers/acknowledgements.rb +154 -0
  13. data/lib/principles/controllers/after_commit_report.rb +44 -0
  14. data/lib/principles/controllers/answer.rb +48 -18
  15. data/lib/principles/controllers/answer_phase.rb +20 -3
  16. data/lib/principles/controllers/assessment.rb +32 -11
  17. data/lib/principles/controllers/audit.rb +43 -19
  18. data/lib/principles/controllers/audit_completion.rb +21 -12
  19. data/lib/principles/controllers/command.rb +13 -12
  20. data/lib/principles/controllers/correction.rb +15 -7
  21. data/lib/principles/controllers/first_audit_brief.rb +40 -0
  22. data/lib/principles/controllers/full_audit_request.rb +41 -82
  23. data/lib/principles/controllers/hook_setup.rb +49 -0
  24. data/lib/principles/controllers/inventory.rb +10 -8
  25. data/lib/principles/controllers/mapping.rb +2 -2
  26. data/lib/principles/controllers/member_acknowledgement.rb +32 -21
  27. data/lib/principles/controllers/member_entries.rb +4 -4
  28. data/lib/principles/controllers/member_problems_report.rb +62 -16
  29. data/lib/principles/controllers/members_a_commit_changed.rb +3 -3
  30. data/lib/principles/controllers/members_to_assess.rb +23 -20
  31. data/lib/principles/controllers/meta_principle_setup.rb +5 -6
  32. data/lib/principles/controllers/open_correction.rb +42 -0
  33. data/lib/principles/controllers/parts_to_read.rb +117 -0
  34. data/lib/principles/controllers/repoint.rb +1 -1
  35. data/lib/principles/controllers/running_tool.rb +56 -6
  36. data/lib/principles/controllers/session_start_report.rb +62 -0
  37. data/lib/principles/controllers/survey.rb +2 -2
  38. data/lib/principles/data/audit_files.rb +7 -7
  39. data/lib/principles/data/bounded_file.rb +1 -1
  40. data/lib/principles/data/candidate_files_found.rb +6 -3
  41. data/lib/principles/data/command-steps.json +61 -6
  42. data/lib/principles/data/expected_type.rb +3 -3
  43. data/lib/principles/data/first_parent_log.rb +1 -1
  44. data/lib/principles/data/head_reflog.rb +74 -0
  45. data/lib/principles/data/hook_input.rb +59 -0
  46. data/lib/principles/data/ignored_by_git.rb +2 -2
  47. data/lib/principles/data/known_fields.rb +1 -1
  48. data/lib/principles/data/linked_path.rb +1 -1
  49. data/lib/principles/data/map_files.rb +2 -2
  50. data/lib/principles/data/principles_on_path.rb +83 -0
  51. data/lib/principles/data/principles_subfolder.rb +1 -1
  52. data/lib/principles/data/project_files.rb +10 -3
  53. data/lib/principles/data/repository.rb +14 -7
  54. data/lib/principles/data/running_version.rb +10 -8
  55. data/lib/principles/data/schema_check.rb +5 -5
  56. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +86 -21
  57. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +9 -2
  58. data/lib/principles/data/schemas/assessment-answer.schema.json +43 -22
  59. data/lib/principles/data/schemas/audit-record.schema.json +29 -20
  60. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  61. data/lib/principles/data/schemas/correction-answer-guide.schema.json +1 -1
  62. data/lib/principles/data/schemas/correction-answer.schema.json +9 -9
  63. data/lib/principles/data/schemas/member-map.schema.json +3 -3
  64. data/lib/principles/data/schemas/repointing-answer.schema.json +1 -1
  65. data/lib/principles/error.rb +4 -4
  66. data/lib/principles/failure_refusal.rb +57 -0
  67. data/lib/principles/invocation_options.rb +4 -4
  68. data/lib/principles/launch.rb +49 -0
  69. data/lib/principles/list_open_findings_options.rb +1 -1
  70. data/lib/principles/models/accepted_loading.rb +2 -2
  71. data/lib/principles/models/acknowledged_check.rb +23 -11
  72. data/lib/principles/models/acknowledgement.rb +34 -18
  73. data/lib/principles/models/acknowledgement_left_as_printed.rb +7 -15
  74. data/lib/principles/models/acknowledgement_refusal.rb +25 -10
  75. data/lib/principles/models/acknowledgements.rb +45 -29
  76. data/lib/principles/models/acknowledgements_across.rb +68 -0
  77. data/lib/principles/models/activation.rb +2 -2
  78. data/lib/principles/models/after_commit_input.rb +115 -0
  79. data/lib/principles/models/agent_loads.rb +1 -1
  80. data/lib/principles/models/answer_fields.rb +2 -2
  81. data/lib/principles/models/answer_place.rb +3 -3
  82. data/lib/principles/models/answer_text.rb +2 -2
  83. data/lib/principles/models/answered_time.rb +4 -4
  84. data/lib/principles/models/assessment_answer.rb +10 -10
  85. data/lib/principles/models/assessment_basis.rb +2 -2
  86. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  87. data/lib/principles/models/assessment_report.rb +6 -7
  88. data/lib/principles/models/audit.rb +33 -34
  89. data/lib/principles/models/audit_record.rb +54 -28
  90. data/lib/principles/models/audit_records.rb +13 -13
  91. data/lib/principles/models/audit_start.rb +3 -3
  92. data/lib/principles/models/audited_member_lines.rb +1 -1
  93. data/lib/principles/models/candidate_files.rb +18 -10
  94. data/lib/principles/models/candidate_inventory.rb +6 -6
  95. data/lib/principles/models/candidate_outline.rb +9 -9
  96. data/lib/principles/models/carried_assessments.rb +18 -3
  97. data/lib/principles/models/carried_member.rb +5 -5
  98. data/lib/principles/models/changed_regions.rb +92 -0
  99. data/lib/principles/models/check_result_guide.rb +50 -0
  100. data/lib/principles/models/check_since_last_audit.rb +5 -4
  101. data/lib/principles/models/cited_files.rb +4 -4
  102. data/lib/principles/models/command_steps.rb +3 -3
  103. data/lib/principles/models/commits_brought_in.rb +1 -1
  104. data/lib/principles/models/commits_since_base.rb +1 -1
  105. data/lib/principles/models/correction_answer.rb +2 -2
  106. data/lib/principles/models/correction_basis.rb +7 -7
  107. data/lib/principles/models/dated_line.rb +1 -2
  108. data/lib/principles/models/decided_prior_findings.rb +6 -6
  109. data/lib/principles/models/declared_map_changes.rb +5 -5
  110. data/lib/principles/models/disposition.rb +21 -21
  111. data/lib/principles/models/entry_file.rb +1 -1
  112. data/lib/principles/models/entry_files.rb +1 -1
  113. data/lib/principles/models/evidence_item.rb +1 -1
  114. data/lib/principles/models/evidence_lines_since.rb +2 -2
  115. data/lib/principles/models/evidence_replacements.rb +3 -3
  116. data/lib/principles/models/finding_write_ups.rb +12 -5
  117. data/lib/principles/models/findings_left_open.rb +4 -4
  118. data/lib/principles/models/first_full_audit.rb +32 -0
  119. data/lib/principles/models/first_raised_claim.rb +1 -1
  120. data/lib/principles/models/fix_only_fields.rb +1 -1
  121. data/lib/principles/models/head_moves.rb +66 -0
  122. data/lib/principles/models/hook_commands.rb +49 -4
  123. data/lib/principles/models/ignored_candidates.rb +1 -1
  124. data/lib/principles/models/instruction_named.rb +2 -3
  125. data/lib/principles/models/json_digest.rb +2 -2
  126. data/lib/principles/models/json_path_query.rb +1 -1
  127. data/lib/principles/models/kept_prior_finding.rb +9 -9
  128. data/lib/principles/models/last_completed_revision.rb +4 -5
  129. data/lib/principles/models/left_as_printed.rb +2 -2
  130. data/lib/principles/models/line_diff.rb +113 -0
  131. data/lib/principles/models/line_span.rb +1 -1
  132. data/lib/principles/models/list_member_problems_check.rb +4 -4
  133. data/lib/principles/models/listed_members.rb +7 -9
  134. data/lib/principles/models/loaded_files.rb +4 -5
  135. data/lib/principles/models/loading_decision.rb +3 -3
  136. data/lib/principles/models/loading_facts.rb +1 -1
  137. data/lib/principles/models/loads_to_check.rb +1 -1
  138. data/lib/principles/models/located_text.rb +1 -1
  139. data/lib/principles/models/mapped_principles.rb +2 -2
  140. data/lib/principles/models/member.rb +31 -4
  141. data/lib/principles/models/member_assessments.rb +8 -8
  142. data/lib/principles/models/member_elsewhere.rb +4 -4
  143. data/lib/principles/models/member_file.rb +4 -4
  144. data/lib/principles/models/member_grounds.rb +1 -1
  145. data/lib/principles/models/member_hashes_as_written.rb +1 -1
  146. data/lib/principles/models/member_lines.rb +29 -61
  147. data/lib/principles/models/member_loads.rb +2 -2
  148. data/lib/principles/models/member_moves.rb +1 -1
  149. data/lib/principles/models/member_problems.rb +14 -15
  150. data/lib/principles/models/member_repair_moves.rb +15 -9
  151. data/lib/principles/models/member_sighting.rb +10 -10
  152. data/lib/principles/models/member_snapshots.rb +1 -1
  153. data/lib/principles/models/member_state.rb +1 -1
  154. data/lib/principles/models/members_across_principles.rb +77 -0
  155. data/lib/principles/models/members_elsewhere.rb +2 -2
  156. data/lib/principles/models/members_sharing_lines.rb +7 -7
  157. data/lib/principles/models/meta_principle.rb +11 -4
  158. data/lib/principles/models/missing_files.rb +3 -3
  159. data/lib/principles/models/new_findings.rb +4 -4
  160. data/lib/principles/models/open_correction.rb +57 -0
  161. data/lib/principles/models/open_finding.rb +36 -31
  162. data/lib/principles/models/open_findings_elsewhere.rb +2 -2
  163. data/lib/principles/models/other_principles.rb +2 -2
  164. data/lib/principles/models/other_templates_placeholders.rb +17 -16
  165. data/lib/principles/models/outline_budget.rb +7 -7
  166. data/lib/principles/models/outline_group.rb +1 -1
  167. data/lib/principles/models/outline_section.rb +2 -2
  168. data/lib/principles/models/part_named.rb +41 -0
  169. data/lib/principles/models/placement.rb +2 -2
  170. data/lib/principles/models/principle.rb +13 -13
  171. data/lib/principles/models/principle_history.rb +8 -8
  172. data/lib/principles/models/principle_members.rb +14 -7
  173. data/lib/principles/models/principles_folder_move.rb +1 -1
  174. data/lib/principles/models/principles_on_path.rb +29 -0
  175. data/lib/principles/models/principles_package.rb +3 -3
  176. data/lib/principles/models/prior_decision_fields.rb +8 -8
  177. data/lib/principles/models/prior_finding_decision.rb +8 -8
  178. data/lib/principles/models/prior_finding_outcomes.rb +1 -1
  179. data/lib/principles/models/prior_findings.rb +5 -5
  180. data/lib/principles/models/problem_report.rb +26 -8
  181. data/lib/principles/models/project.rb +27 -19
  182. data/lib/principles/models/project_history.rb +18 -12
  183. data/lib/principles/models/quoted_change.rb +8 -8
  184. data/lib/principles/models/recent_decision.rb +3 -3
  185. data/lib/principles/models/record_format.rb +16 -10
  186. data/lib/principles/models/record_judged_against.rb +4 -4
  187. data/lib/principles/models/recorded_entry.rb +17 -8
  188. data/lib/principles/models/recorded_finding.rb +9 -9
  189. data/lib/principles/models/recorded_findings.rb +2 -2
  190. data/lib/principles/models/recorded_hashes.rb +2 -2
  191. data/lib/principles/models/recorded_members.rb +13 -13
  192. data/lib/principles/models/refusal_before_shape.rb +2 -2
  193. data/lib/principles/models/repoint.rb +3 -3
  194. data/lib/principles/models/report_hooks.rb +69 -0
  195. data/lib/principles/models/reported_check.rb +34 -31
  196. data/lib/principles/models/request_id.rb +18 -6
  197. data/lib/principles/models/runs_from.rb +7 -2
  198. data/lib/principles/models/sent_answer.rb +14 -12
  199. data/lib/principles/models/sent_prior_decisions.rb +1 -1
  200. data/lib/principles/models/session_start_input.rb +37 -0
  201. data/lib/principles/models/shape_problems_beside.rb +1 -1
  202. data/lib/principles/models/skill_loads.rb +1 -1
  203. data/lib/principles/models/stale_request.rb +59 -0
  204. data/lib/principles/models/still_holds_restatement.rb +6 -6
  205. data/lib/principles/models/submitted_answer.rb +1 -1
  206. data/lib/principles/models/template_placeholders.rb +6 -6
  207. data/lib/principles/models/text_within.rb +1 -1
  208. data/lib/principles/models/tracked_paths.rb +38 -0
  209. data/lib/principles/models/unchecked_members.rb +2 -2
  210. data/lib/principles/models/uncommitted_files.rb +1 -1
  211. data/lib/principles/models/uncommitted_outside_the_map.rb +2 -2
  212. data/lib/principles/models/waits_on.rb +1 -1
  213. data/lib/principles/models/write_up_opening.rb +5 -5
  214. data/lib/principles/models/write_up_pointer.rb +3 -3
  215. data/lib/principles/models/write_up_repoint.rb +2 -3
  216. data/lib/principles/positional_arguments.rb +13 -6
  217. data/lib/principles/prose_list.rb +1 -1
  218. data/lib/principles/session_start_options.rb +1 -1
  219. data/lib/principles/start_audit_options.rb +46 -12
  220. data/lib/principles/supported_ruby.rb +24 -7
  221. data/lib/principles/version.rb +2 -2
  222. data/lib/principles/views/acknowledged_since_last_audit.rb +2 -2
  223. data/lib/principles/views/acknowledgement_result.rb +97 -11
  224. data/lib/principles/views/activation_in_hand.rb +1 -1
  225. data/lib/principles/views/answered_request.rb +6 -2
  226. data/lib/principles/views/assessed_members.rb +50 -41
  227. data/lib/principles/views/assessment_request.rb +39 -36
  228. data/lib/principles/views/audit_changes.rb +4 -4
  229. data/lib/principles/views/audit_commit.rb +5 -4
  230. data/lib/principles/views/audit_result.rb +92 -53
  231. data/lib/principles/views/candidate_files_result.rb +7 -6
  232. data/lib/principles/views/check_notes.rb +29 -6
  233. data/lib/principles/views/check_result_template.rb +45 -34
  234. data/lib/principles/views/completed_audit_next_step.rb +44 -0
  235. data/lib/principles/views/context_parts.rb +112 -0
  236. data/lib/principles/views/correction_request.rb +44 -25
  237. data/lib/principles/views/diff_since_last_audit.rb +8 -6
  238. data/lib/principles/views/findings_result.rb +17 -6
  239. data/lib/principles/views/first_audit_brief.rb +51 -0
  240. data/lib/principles/views/first_audit_line.rb +45 -0
  241. data/lib/principles/views/help.rb +4 -4
  242. data/lib/principles/views/hook_setup_result.rb +91 -0
  243. data/lib/principles/views/instruction.rb +3 -3
  244. data/lib/principles/views/invocation.rb +14 -6
  245. data/lib/principles/views/json_with_entries_on_lines.rb +6 -35
  246. data/lib/principles/views/landed_since_base.rb +1 -1
  247. data/lib/principles/views/line_history_since_last_audit.rb +35 -0
  248. data/lib/principles/views/lines_shared_with_member.rb +6 -6
  249. data/lib/principles/views/loads_to_check_result.rb +8 -5
  250. data/lib/principles/views/map_added_to.rb +3 -3
  251. data/lib/principles/views/map_result.rb +9 -9
  252. data/lib/principles/views/member_change_since_baseline.rb +44 -23
  253. data/lib/principles/views/member_lines_beside_text.rb +43 -0
  254. data/lib/principles/views/member_repairs.rb +3 -2
  255. data/lib/principles/views/member_row.rb +2 -2
  256. data/lib/principles/views/members_a_commit_changed.rb +13 -10
  257. data/lib/principles/views/members_with_no_baseline.rb +3 -3
  258. data/lib/principles/views/meta_principle_passage.rb +1 -1
  259. data/lib/principles/views/meta_principle_result.rb +12 -5
  260. data/lib/principles/views/one_member_check_result_template.rb +7 -7
  261. data/lib/principles/views/open_findings_elsewhere_result.rb +5 -2
  262. data/lib/principles/views/open_findings_line.rb +25 -36
  263. data/lib/principles/views/other_principles_unjudged_result.rb +6 -3
  264. data/lib/principles/views/outside_the_map_result.rb +5 -2
  265. data/lib/principles/views/package_since_last_audit_result.rb +29 -6
  266. data/lib/principles/views/parts_index_result.rb +60 -0
  267. data/lib/principles/views/principle_read_result.rb +5 -6
  268. data/lib/principles/views/principle_with_changed_members.rb +1 -1
  269. data/lib/principles/views/principles_with_no_completed_audit.rb +1 -2
  270. data/lib/principles/views/printed_json.rb +51 -0
  271. data/lib/principles/views/printed_principle.rb +1 -1
  272. data/lib/principles/views/prior_finding_decisions_result.rb +4 -4
  273. data/lib/principles/views/prior_findings_result.rb +17 -14
  274. data/lib/principles/views/problem_lines.rb +39 -17
  275. data/lib/principles/views/problem_result.rb +40 -37
  276. data/lib/principles/views/prompts/acknowledge-a-change/judge-each-member-once-for-every-principle.md +2 -0
  277. data/lib/principles/views/prompts/acknowledge-a-change/read-the-deferred-findings-it-keeps.md +1 -0
  278. data/lib/principles/views/prompts/acknowledge-a-change/resolve-them-in-a-full-audit.md +1 -0
  279. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +3 -3
  280. data/lib/principles/views/prompts/assess-every-member/confirm-each-write-up-pointer-the-answer-drops.md +2 -0
  281. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +1 -1
  282. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  283. data/lib/principles/views/prompts/assess-every-member/judge-a-carried-assessment-citing-a-decided-finding.md +3 -0
  284. data/lib/principles/views/prompts/assess-every-member/judge-a-submitted-carried-assessment-citing-a-decided-finding.md +5 -0
  285. data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-under-the-release-since-the-last-audit.md +1 -1
  286. data/lib/principles/views/prompts/assess-every-member/keep-the-printed-review-basis-or-replace-it.md +1 -0
  287. data/lib/principles/views/prompts/assess-every-member/name-the-commit-that-made-the-check.md +1 -0
  288. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -1
  289. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +1 -0
  290. data/lib/principles/views/prompts/assess-every-member/why-each-member-is-judged-again.md +3 -2
  291. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  292. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -0
  293. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -4
  294. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +2 -2
  295. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +4 -3
  296. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +6 -6
  297. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -11
  298. data/lib/principles/views/prompts/learn-what-a-command-does/report-after-commit.md +14 -0
  299. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +26 -0
  300. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +20 -18
  301. data/lib/principles/views/prompts/learn-what-a-command-does/show-first-audit-brief.md +19 -0
  302. data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +13 -0
  303. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +3 -1
  304. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +12 -0
  305. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +21 -22
  306. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +5 -4
  307. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +2 -2
  308. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +18 -0
  309. data/lib/principles/views/prompts/set-principles-up/offer-the-report-hooks.md +2 -0
  310. data/lib/principles/views/prompts/set-principles-up/wire-the-report-hooks-with-the-user.md +8 -0
  311. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +3 -4
  312. data/lib/principles/views/prompts/start-a-session/every-loaded-line-costs-every-session.md +1 -1
  313. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +3 -0
  314. data/lib/principles/views/prompts/start-a-session/run-each-command-above.md +1 -0
  315. data/lib/principles/views/prompts/start-a-session/start-no-second-first-audit.md +2 -0
  316. data/lib/principles/views/prompts.rb +1 -1
  317. data/lib/principles/views/read_the_change.rb +36 -0
  318. data/lib/principles/views/record_waiting_on_an_upgrade.rb +2 -2
  319. data/lib/principles/views/repoint_result.rb +1 -1
  320. data/lib/principles/views/report_hooks_offer.rb +25 -0
  321. data/lib/principles/views/request_part.rb +5 -5
  322. data/lib/principles/views/request_parts.rb +1 -1
  323. data/lib/principles/views/session_start_report.rb +46 -0
  324. data/lib/principles/views/shell_word.rb +1 -1
  325. data/lib/principles/views/trimmed_instructions_note.rb +30 -0
  326. data/lib/principles/views/visible_text.rb +1 -1
  327. data/lib/principles/views/workflow_diagram.rb +1 -1
  328. data/principles.gemspec +44 -0
  329. metadata +83 -14
  330. data/lib/principles/views/prompts/start-a-session/it-returns-after-each-clear-or-compaction-too.md +0 -1
  331. data/lib/principles/views/prompts/start-a-session/it-returns-at-each-session-start.md +0 -1
@@ -1,31 +1,34 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "changed_regions"
5
+ require_relative "line_diff"
6
+
4
7
  module Principles
5
8
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
6
9
  module Models
7
10
  # A member's own lines at its baseline and now, as a one-member audit's request shows them, so the agent reads
8
- # the change its quotes are checked against and not the rest of an edit to the file (#379). A long member, such
11
+ # the change its quotes are checked against and not the rest of an edit to the file. A long member, such
9
12
  # as a whole file, shows only its changed region: the lines between its first and last difference, with a little
10
- # context (#449). Past a limit even that is counted instead, so a request never carries a file twice (D38).
13
+ # context. Past a limit even that is counted instead, so a request never carries a file twice.
11
14
  class MemberLines
12
15
  # The most lines either side shows: a section or a passage fits, and so does the changed region of most edits
13
- # to a whole file. A first guess, for an alpha test to confirm (#379).
16
+ # to a whole file. A first guess, for an alpha test to confirm.
14
17
  SHOWN_AT_MOST = 80
15
18
 
16
19
  # The most bytes both sides together show whole: a 4 KB acknowledgement less its 2.7 KB of other fields,
17
- # so a short file of long lines shows its changed region and not itself twice (D93's review F4, #1069).
20
+ # so a short file of long lines shows its changed region and not itself twice.
18
21
  SHOWN_BYTES_AT_MOST = 1300
19
22
 
20
- # The most unchanged lines shown on each side of a changed region, as git shows by default (#449); fewer
21
- # when these would pass SHOWN_BYTES_AT_MOST (#1069).
23
+ # The most unchanged lines shown on each side of a changed region, as git shows by default; fewer
24
+ # when these would pass SHOWN_BYTES_AT_MOST.
22
25
  CONTEXT_LINES = 3
23
26
 
24
- # The most shown around a one-line change, whose edit first_changed_lines already gives (#1146).
27
+ # The most shown around a one-line change, whose edit first_changed_lines already gives.
25
28
  ONE_LINE_CONTEXT_LINES = 1
26
29
 
27
30
  # Each line is kept without its line ending, so a line the agent copies from the request is a whole line it
28
- # can quote (#451).
31
+ # can quote.
29
32
  #: (at_baseline: Array[String], now: Array[String]) -> void
30
33
  def initialize(at_baseline:, now:)
31
34
  @at_baseline = at_baseline.map(&:chomp) #: Array[String]
@@ -40,13 +43,13 @@ module Principles
40
43
  #: Array[String]
41
44
  attr_reader :now
42
45
 
43
- # Whether its lines now read otherwise than at the baseline, as a prior finding's evidence item says (#858).
46
+ # Whether its lines now read otherwise than at the baseline, as a prior finding's evidence item says.
44
47
  #: () -> bool
45
48
  def changed? = @at_baseline != @now
46
49
 
47
50
  # Both sides' lines while each is at most SHOWN_AT_MOST lines and together at most SHOWN_BYTES_AT_MOST less
48
51
  # taken, the bytes a request's other parts take beyond its usual ones, as a checked member's check_result
49
- # template does (#1119); else their changed region, with where it starts within the member and each side's
52
+ # template does; else their changed region, with where it starts within the member and each side's
50
53
  # length; else how many lines each side has.
51
54
  #: (?taken: Integer) -> Hash[String, untyped]
52
55
  def shown(taken: 0)
@@ -55,10 +58,10 @@ module Principles
55
58
  return sides if within_line_limit?(sides.values) && bytes(sides.values) <= budget
56
59
 
57
60
  counts = sides.transform_values(&:length)
58
- context, region = region_within(budget)
59
- return { "omitted" => "too_long", "lines" => counts } unless within_line_limit?(lines_of(region))
61
+ regions = regions_within(budget)
62
+ return { "omitted" => "too_long", "lines" => counts } unless within_line_limit?(regions.lines)
60
63
 
61
- { "changed_region" => { "context_lines" => context, **region }, "lines" => counts }
64
+ { **regions.shown, "lines" => counts }
62
65
  end
63
66
 
64
67
  private
@@ -72,61 +75,26 @@ module Principles
72
75
  sides.all? { |lines| lines.length <= SHOWN_AT_MOST }
73
76
  end
74
77
 
75
- # The changed region with the most context, up to CONTEXT_LINES, whose lines fit budget, and how many lines of
76
- # context it has; with none when no context fits, since the changed lines are what is judged, and then the sides
77
- # first_changed_lines' span and read_the_change stand in for left out (#1103, #1144).
78
- #: (Integer) -> [Integer, Hash[String, Hash[String, untyped]]]
79
- def region_within(budget)
80
- regions = most_context.downto(0).map { |context| [context, changed_region(context)] }
81
- regions.find { |_, region| bytes(lines_of(region)) <= budget } ||
82
- [0, with_sides_left_out(regions.fetch(-1).last)]
78
+ # The changed regions with the most context, up to CONTEXT_LINES, whose lines fit budget; with none when no
79
+ # context fits, since the changed lines are what is judged, and then the sides first_changed_lines' span and
80
+ # read_the_change stand in for left out.
81
+ #: (Integer) -> ChangedRegions
82
+ def regions_within(budget)
83
+ hunks = LineDiff.new(@at_baseline, @now).hunks
84
+ all = most_context(hunks).downto(0).map { ChangedRegions.new(@at_baseline, @now, hunks: hunks, context: it) }
85
+ all.find { bytes(it.lines) <= budget } || all.fetch(-1).with_sides_left_out
83
86
  end
84
87
 
85
- # ONE_LINE_CONTEXT_LINES when each side changed one line at most, else CONTEXT_LINES.
86
- #: () -> Integer
87
- def most_context
88
- one_line = lines_of(changed_region(0)).all? { it.length <= 1 }
88
+ # ONE_LINE_CONTEXT_LINES when one run changed one line at most on each side, else CONTEXT_LINES.
89
+ #: (Array[LineDiff::Hunk]) -> Integer
90
+ def most_context(hunks)
91
+ one_line = ChangedRegions.new(@at_baseline, @now, hunks: hunks, context: 0).one_line?
89
92
  one_line ? ONE_LINE_CONTEXT_LINES : CONTEXT_LINES
90
93
  end
91
-
92
- # region with its baseline side's lines left out, saying so, and its side now too when each side holds one line
93
- # at most, whose change first_changed_lines' span shows whole (#1144); a longer region's other changed lines no
94
- # hint shows, so its side now stays (#1069).
95
- #: (Hash[String, Hash[String, untyped]]) -> Hash[String, Hash[String, untyped]]
96
- def with_sides_left_out(region)
97
- one_line = lines_of(region).all? { it.length <= 1 }
98
- left_out = one_line ? %w[at_baseline now] : %w[at_baseline]
99
- region.to_h do |name, side|
100
- [name, left_out.include?(name) ? { "from_line" => side.fetch("from_line"), "omitted" => "too_long" } : side]
101
- end
102
- end
103
-
104
- # Each side's lines in a changed region, none for a side left out.
105
- #: (Hash[String, Hash[String, untyped]]) -> Array[Array[String]]
106
- def lines_of(region) = region.values.map { |side| side.fetch("lines", []) }
107
-
108
- # Each side's lines from context lines before its first difference to context lines after its last, with the
109
- # 1-based line, within the member, the region starts at.
110
- #: (Integer) -> Hash[String, Hash[String, untyped]]
111
- def changed_region(context)
112
- same_start = common_length(@at_baseline, @now)
113
- same_end = common_length(@at_baseline.drop(same_start).reverse, @now.drop(same_start).reverse)
114
- from = [same_start - context, 0].max
115
- { "at_baseline" => @at_baseline, "now" => @now }.transform_values do |lines|
116
- to = [lines.length - same_end + context, lines.length].min
117
- { "from_line" => from + 1, "lines" => lines[from...to] || [] }
118
- end
119
- end
120
-
121
- # How many lines two sides share from their start.
122
- #: (Array[String], Array[String]) -> Integer
123
- def common_length(one, other)
124
- one.zip(other).take_while { |line, other_line| line == other_line && !other_line.nil? }.length
125
- end
126
94
  end
127
95
 
128
96
  # A member that cannot be placed in its file at the last full audit's commit, as after a move: the commit lacks
129
- # the file, or the member's reference finds nothing there. An empty side would say it was empty (#457).
97
+ # the file, or the member's reference finds nothing there. An empty side would say it was empty.
130
98
  class MemberLinesNotFoundAtLastAudit
131
99
  #: () -> void
132
100
  def initialize
@@ -14,7 +14,7 @@ module Principles
14
14
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
15
15
  module Models
16
16
  # When a host loads a member's file into the agent's context, derived from the file's path as the host
17
- # documents its loading, with the size of what loads (D38). Only Claude Code is derived. A derivation says
17
+ # documents its loading, with the size of what loads. Only Claude Code is derived. A derivation says
18
18
  # what the documentation promises, not what loaded in any session. An audit record keeps these loads, and
19
19
  # audit-record.schema.json names each field so show-audit prints it; member_loads_spec holds a sample of each
20
20
  # branch to hold the two together, so add one there for a new branch.
@@ -61,7 +61,7 @@ module Principles
61
61
  new(locator, nil, hooks: hooks)
62
62
  end
63
63
 
64
- # A whole file's loads, with no member's share in it, as LoadedFiles lists each file (#483).
64
+ # A whole file's loads, with no member's share in it, as LoadedFiles lists each file.
65
65
  #: (Data::ProjectFiles, String, hooks: HookCommands) -> MemberLoads
66
66
  def self.of_file(files, path, hooks:)
67
67
  new(Locator.new("path" => path), files.read_text(path), hooks: hooks)
@@ -11,7 +11,7 @@ module Principles
11
11
  module Models
12
12
  # The members a correction says the agent moved after the audit began, from each old id to its new one. A
13
13
  # fix can rewrite the text a member's locator quotes; the agent then runs move-member and declares the
14
- # move, and this tool checks it against the map at the base commit (D28).
14
+ # move, and this tool checks it against the map at the base commit.
15
15
  class MemberMoves
16
16
  #: (untyped) -> void
17
17
  def initialize(moves)
@@ -19,7 +19,7 @@ module Principles
19
19
  # A member is changed only when its own text changed, so an edit elsewhere in its file is not one.
20
20
  class MemberProblems
21
21
  # What this tool last knew of each member's text, by key: the last audit's hashes and the commit it began
22
- # from, and each member's hash and commit at the commit that mapped it where it is (#243).
22
+ # from, and each member's hash and commit at the commit that mapped it where it is.
23
23
  class Baselines
24
24
  # The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
25
25
  # where it is, read with the map as that commit held it; none outside git.
@@ -47,8 +47,8 @@ module Principles
47
47
  def waiting? = @hashes.waiting?
48
48
 
49
49
  # audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
50
- # completed, so a one-member audit is offered only where one would be accepted (#626). hashes is the member
51
- # hashes the record holds, which a later copy may have written, so its members are compared read-only (#1066).
50
+ # completed, so a one-member audit is offered only where one would be accepted. hashes is the member
51
+ # hashes the record holds, which a later copy may have written, so its members are compared read-only.
52
52
  #: (audit: AuditRecord?, mapped: Hash[String, Hash[String, String]], in_git: bool,
53
53
  #| ?hashes: RecordedHashes, ?mapping: PrincipleMappingHistory?) -> void
54
54
  def initialize(audit:, mapped:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE, mapping: nil)
@@ -89,8 +89,7 @@ module Principles
89
89
  #: () -> String
90
90
  def none_because = @in_git ? "not_committed" : "outside_git"
91
91
 
92
- # Whether no full audit of the principle has completed: it has no record, or an open one that keeps none
93
- # (D58).
92
+ # Whether no full audit of the principle has completed: it has no record, or an open one that keeps none.
94
93
  #: () -> bool
95
94
  def no_completed_audit?
96
95
  audit = @audit
@@ -99,7 +98,7 @@ module Principles
99
98
 
100
99
  # Whether a one-member audit may judge member's change to now_sha256: in git, and where the audit record gives
101
100
  # no refusal, which Acknowledgement refuses by too, so list-member-problems offers no command certain to be
102
- # refused (#626, #632).
101
+ # refused.
103
102
  #: (Member, String?) -> bool
104
103
  def acknowledgeable?(member, now_sha256)
105
104
  audit = @audit
@@ -152,16 +151,16 @@ module Principles
152
151
  end
153
152
 
154
153
  # Whether a member an audit or acknowledgement assessed changed since, rather than only a member edited since
155
- # the commit that mapped it, which no audit assessed (D44).
154
+ # the commit that mapped it, which no audit assessed.
156
155
  #: () -> bool
157
156
  def assessed_change? = assessed_changes.positive?
158
157
 
159
- # How many such members changed, which the session-start hook counts by principle (#1261).
158
+ # How many such members changed, which the session-start hook counts by principle.
160
159
  #: () -> Integer
161
160
  def assessed_changes = changes_to_act_on.count { |member| assessed?(member) }
162
161
 
163
162
  # How many members no audit has assessed, compared only with the commit that mapped them, edited or not, which
164
- # --short counts on stdout (#1254); none while the principle's audits wait on an upgrade.
163
+ # --short counts on stdout; none while the principle's audits wait on an upgrade.
165
164
  #: () -> Integer
166
165
  def never_assessed = @baselines.waiting? ? 0 : compared_with.fetch("mapping_commit", 0)
167
166
 
@@ -178,7 +177,7 @@ module Principles
178
177
  end
179
178
 
180
179
  # Each member in paths whose own text changed or whose reference is now broken, with its state, as a completed
181
- # audit names them for another map that shares a file the audit's fixes changed (#410).
180
+ # audit names them for another map that shares a file the audit's fixes changed.
182
181
  #: (Array[String]) -> Array[MemberState]
183
182
  def changed_or_broken_in(paths)
184
183
  return [] if @unreadable
@@ -188,7 +187,7 @@ module Principles
188
187
  end
189
188
 
190
189
  # Each member no audit has judged as it is now, by id with its state: changed or broken since what this tool
191
- # last knew of it, or never assessed, having only its mapping commit or no baseline at all (D71, D44). A map
190
+ # last knew of it, or never assessed, having only its mapping commit or no baseline at all. A map
192
191
  # this tool cannot read is one entry, with no id, whose state is unreadable_map.
193
192
  #: () -> Array[Hash[String, untyped]]
194
193
  def unjudged = entries.reject { it.fetch("state") == "unchanged" }.map { it.slice("id", "state") }
@@ -197,7 +196,7 @@ module Principles
197
196
  def principle_id = @members.principle_id
198
197
 
199
198
  # The ids of the members whose own text changed and whose change a one-member audit may judge on its own, so
200
- # list-member-problems fills that audit's command for each (D56, #728).
199
+ # list-member-problems fills that audit's command for each.
201
200
  #: () -> Array[String]
202
201
  def acknowledgeable_member_ids
203
202
  changed_members.select { |member| @baselines.acknowledgeable?(member, @now[member.key]) }.map(&:id)
@@ -225,7 +224,7 @@ module Principles
225
224
 
226
225
  # Whether the principle awaits its first full audit: none has completed and a member is found, in git one a
227
226
  # commit or an open audit gives a baseline, since until a commit holds its map committing gives its members
228
- # one (D58, #731 R7).
227
+ # one.
229
228
  #: () -> bool
230
229
  def awaits_first_audit?
231
230
  return false if @baselines.waiting? || !@baselines.no_completed_audit?
@@ -269,7 +268,7 @@ module Principles
269
268
  end
270
269
 
271
270
  # The changed members this copy can act on: none while a later copy's record makes them wait on an upgrade,
272
- # so they give --short neither exit 3 nor 4 (D85 V8, #1066).
271
+ # so they give --short neither exit 3 nor 4.
273
272
  #: () -> Array[Member]
274
273
  def changes_to_act_on = @baselines.waiting? ? [] : changed_members
275
274
 
@@ -287,7 +286,7 @@ module Principles
287
286
 
288
287
  # listed, compared with the last audit's hash for key, or else with its hash at the commit that mapped it.
289
288
  # An unchanged member compared only with the commit that mapped it has never been assessed, so it is
290
- # counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited (#569).
289
+ # counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited.
291
290
  #: (Hash[String, untyped], String, String) -> Hash[String, untyped]
292
291
  def compared(listed, key, sha)
293
292
  then_sha, since = baseline(key)
@@ -6,31 +6,37 @@ module Principles
6
6
  module Models
7
7
  # The moves that may repair a member this tool cannot find, each as the locator fields it keeps and those the agent
8
8
  # fills in, which Views::MemberRepairs prints as move-member commands. A member whose file is gone moves to the
9
- # path the agent finds, keeping its own section, passage or query, so a rename keeps its audit (#268). A member
10
- # whose place in its file is gone moves within it, or into another file its text moved to (#378); a passage keeps
11
- # its anchors, so a move cannot silently widen it to its whole new section (#251), but not an opening or ending text
12
- # that is gone, which a move repeating it would fail on again as printed (#1104, #1139); and it is given no section
13
- # a passage located by its opening alone never had (#1134). Which fits is the agent's to judge.
9
+ # path the agent finds, keeping its own section, passage or query, so a rename keeps its audit; so does one whose
10
+ # file git tracks only under another spelling, moved to that spelling when its refusal names it, which the agent
11
+ # checks first. A member whose place in its file is gone moves within it, or into another file its text moved to; a
12
+ # passage keeps its anchors, so a move cannot silently widen it to its whole new section, but not an opening or
13
+ # ending text that is gone, which a move repeating it would fail on again as printed; and it is given no section a
14
+ # passage located by its opening alone never had. Which fits is the agent's to judge.
14
15
  class MemberRepairMoves
15
16
  # The locator fields a member may give beside its path.
16
17
  LOCATOR = %w[section starting_at ending_at query].freeze #: Array[String]
17
18
  # The passage anchor each refusal code says is no longer in its file, which a move fills in afresh.
18
19
  LOST_ANCHOR = { "passage_not_found" => %w[starting_at],
19
20
  "passage_end_not_found" => %w[ending_at] }.freeze #: Hash[String, Array[String]]
21
+ # The refusal codes that say a member's file is not at its path, though its text may be unchanged: gone, or
22
+ # tracked by git only under another spelling.
23
+ FILE_NOT_AT_PATH = %w[unreadable_file renamed_in_case].freeze #: Array[String]
20
24
 
21
25
  # member is the member's locator fields, as its map holds them; code is that of the refusal saying why it cannot
22
- # be found.
23
- #: (Hash[String, untyped], code: String?) -> void
24
- def initialize(member, code:)
26
+ # be found, and tracked_as the spelling git tracks its path under, which a renamed_in_case refusal gives.
27
+ #: (Hash[String, untyped], code: String?, ?tracked_as: String?) -> void
28
+ def initialize(member, code:, tracked_as: nil)
25
29
  @member = given(member, LOCATOR) #: Hash[String, untyped]
26
30
  @code = code
31
+ @tracked_as = tracked_as
27
32
  freeze
28
33
  end
29
34
 
30
35
  # Each move, as { "keep" => the locator fields it keeps, by name, "fill" => the fields the agent fills in }.
31
36
  #: () -> Array[Hash[String, untyped]]
32
37
  def to_a
33
- return [move(@member, %w[path])] if @code == "unreadable_file"
38
+ return [move(@member.merge("path" => @tracked_as), [])] if @code == "renamed_in_case" && @tracked_as
39
+ return [move(@member, %w[path])] if FILE_NOT_AT_PATH.include?(@code)
34
40
  return [move({}, %w[query])] if @member["query"]
35
41
 
36
42
  lost = LOST_ANCHOR.fetch(@code.to_s, [])
@@ -13,7 +13,7 @@ module Principles
13
13
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
14
14
  module Models
15
15
  # One member assessment's sighting: whether its delivery was observed, what was seen, and when, as the last full
16
- # audit's sighting of the member bears on it (#680, #716). Its delivery picks its kind: Observed, or NotObserved.
16
+ # audit's sighting of the member bears on it. Its delivery picks its kind: Observed, or NotObserved.
17
17
  class MemberSighting
18
18
  # The sighting of assessment, one of the answer's member_assessments at the place at, of the kind its
19
19
  # delivery names; carried knows the last full audit's sightings, and answered_at is when the answer came. A
@@ -48,7 +48,7 @@ module Principles
48
48
  #: (String) -> String
49
49
  def pointer(field) = @at.child(field).pointer
50
50
 
51
- # A delivery not observed has no sighting, so it gives no observed_at (#680).
51
+ # A delivery not observed has no sighting, so it gives no observed_at.
52
52
  class NotObserved < MemberSighting
53
53
  #: (Hash[String, untyped], at: AnswerPlace) -> void
54
54
  def initialize(assessment, at:)
@@ -71,7 +71,7 @@ module Principles
71
71
  # repeat of the last full audit's but as that sighting or one in this audit.
72
72
  class Observed < MemberSighting
73
73
  SHAPE_EXAMPLE = "2026-11-01T09:30:00Z" #: String
74
- # A record that gives only its date gives it at midnight UTC, the observation saying the time is unknown (#785).
74
+ # A record that gives only its date gives it at midnight UTC, the observation saying the time is unknown.
75
75
  DATE_ALONE_EXAMPLE = "2026-11-01T00:00:00Z" #: String
76
76
  OR_NULL_FOR_THIS_AUDIT = "or null for a sighting in this audit." #: String
77
77
  # The repair for an observed_at naming no UTC time exactly, which shows the form to follow.
@@ -99,7 +99,7 @@ module Principles
99
99
 
100
100
  private
101
101
 
102
- # An observed delivery needs what was seen (D29: a rule across fields stays in the model).
102
+ # An observed delivery needs what was seen: a rule across fields stays in the model.
103
103
  #: () -> void
104
104
  def refuse_missing_observation
105
105
  return if AnswerText.new(@assessment["observation"]).written?
@@ -111,8 +111,8 @@ module Principles
111
111
  end
112
112
 
113
113
  # An observed_at is a UTC time in audited_at's form, as the record dates every other sighting, to compare; a
114
- # date alone or fractional seconds cannot, nor a time no calendar has (#699). One given with an offset arrives
115
- # here already in that form (#1187). Null or none is this audit's.
114
+ # date alone or fractional seconds cannot, nor a time no calendar has. One given with an offset arrives
115
+ # here already in that form. Null or none is this audit's.
116
116
  #: () -> void
117
117
  def refuse_unshaped_observed_at
118
118
  observed_at = @assessment["observed_at"]
@@ -126,7 +126,7 @@ module Principles
126
126
  end
127
127
 
128
128
  # The repair for an observed_at not in audited_at's form: for a date alone, its midnight, to copy, when that is
129
- # no later than the answer, which would refuse it in turn; otherwise the form to follow (#801).
129
+ # no later than the answer, which would refuse it in turn; otherwise the form to follow.
130
130
  #: (AnsweredTime) -> String
131
131
  def shape_repair(given)
132
132
  exact = given.exact_utc
@@ -136,8 +136,8 @@ module Principles
136
136
  "unknown, #{OR_NULL_FOR_THIS_AUDIT}"
137
137
  end
138
138
 
139
- # A sighting is made before the answer that reports it, so its observed_at is no later than answered_at
140
- # (#699). Checked once its form is, so the two compare as times.
139
+ # A sighting is made before the answer that reports it, so its observed_at is no later than answered_at.
140
+ # Checked once its form is, so the two compare as times.
141
141
  #: () -> void
142
142
  def refuse_observed_after_answer
143
143
  observed_at = @assessment["observed_at"]
@@ -152,7 +152,7 @@ module Principles
152
152
 
153
153
  # A fresh observation that repeats the last full audit's word for word describes that audit's sighting or one
154
154
  # made in this audit; only the agent knows which, so it gives the recorded date or null, copied from the repair
155
- # so it never types a clock time (#680, #716). Any other date is another sighting, described in its own words.
155
+ # so it never types a clock time. Any other date is another sighting, described in its own words.
156
156
  #: () -> void
157
157
  def refuse_repeated_observation
158
158
  seen = @carried&.repeated_sighting(id, @assessment["observation"]) or return
@@ -41,7 +41,7 @@ module Principles
41
41
  #: () -> Hash[String, String]
42
42
  def hashes = @by_id.transform_values { |snapshot| snapshot.fetch("sha256") }
43
43
 
44
- # The lines the members span now, against which another principle's evidence is said to share them (D64).
44
+ # The lines the members span now, against which another principle's evidence is said to share them.
45
45
  #: () -> AuditedMemberLines
46
46
  def audited_lines = AuditedMemberLines.new(@by_id.transform_values { LocatedText.of(it) })
47
47
  end
@@ -5,7 +5,7 @@ module Principles
5
5
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # One member by its id, with its state now as list-member-problems reports it, which a completed audit names for
8
- # another principle sharing a file its fixes changed (#410, #823).
8
+ # another principle sharing a file its fixes changed.
9
9
  class MemberState
10
10
  # The states that mean a member's reference is broken, so an audit would refuse it. unreadable_map is a map's
11
11
  # state, which MemberProblems#broken reads over its entries; no MemberState holds it, since a map that cannot be
@@ -0,0 +1,77 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "principle"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # The members an acknowledgement across several principles names, and which of them each principle maps:
12
+ # every member must be mapped by one of them, and each of them must map one, or it would acknowledge nothing.
13
+ class MembersAcrossPrinciples
14
+ #: (Array[Principle], Array[String]) -> void
15
+ def initialize(principles, member_ids)
16
+ @principles = principles.uniq(&:id).sort_by(&:id) #: Array[Principle]
17
+ @member_ids = member_ids
18
+ freeze
19
+ end
20
+
21
+ # The first member none of the principles maps, or nil when each is mapped by one.
22
+ #: () -> String?
23
+ def unmapped = @member_ids.find { |member_id| @principles.none? { it.members.taken?(member_id) } }
24
+
25
+ # Each principle's id, in id order, with the members it maps in the order they were named; refused for a member
26
+ # none maps, as an unknown member of the first principle, which names a near miss, or for a principle that maps
27
+ # none.
28
+ #: () -> Hash[String, Array[String]]
29
+ def by_principle
30
+ missing = unmapped
31
+ @principles.fetch(0).member(missing) if missing
32
+ @member_ids.each { refuse_checked_differently(it) }
33
+ @principles.to_h do |principle|
34
+ mapped = @member_ids.select { principle.members.taken?(it) }
35
+ refuse_mapping_none(principle.id) if mapped.empty?
36
+ [principle.id, mapped]
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ # Each principle that checks member_id, by id beside the check it names.
43
+ #: (String) -> Array[[String, String]]
44
+ def checks_of(member_id)
45
+ @principles.filter_map do |principle|
46
+ check = principle.members.with_id(member_id)&.check
47
+ [principle.id, check] if check
48
+ end
49
+ end
50
+
51
+ # Refuses member_id when the principles that check it name different checks, since one check_result, which an
52
+ # answer across them gives once, cannot report two runs: each principle acknowledges it with its own request.
53
+ #: (String) -> void
54
+ def refuse_checked_differently(member_id)
55
+ checks = checks_of(member_id)
56
+ return if checks.map(&:last).uniq.size < 2
57
+
58
+ each = ProseList.new(checks.map { |id, check| "#{check} in #{id}" }, conjunction: "and by")
59
+ each_own = checks.map do |id, _check|
60
+ Error::RepairCommand.new(purpose: "To acknowledge it in #{id}", command: "start-audit", values: [id],
61
+ options: ["--member", member_id])
62
+ end
63
+ refusal = Error.new("cannot_acknowledge",
64
+ "#{member_id} is checked by #{each}, and one check_result cannot report both", "")
65
+ raise refusal.ending_with(each_own)
66
+ end
67
+
68
+ # Refuses principle id, which maps none of the members, so it would acknowledge nothing.
69
+ #: (String) -> void
70
+ def refuse_mapping_none(id)
71
+ raise Error.new("cannot_acknowledge", "#{id} maps none of the members named: #{ProseList.new(@member_ids)}. " \
72
+ "Give only the ids of principles that map one",
73
+ "Run #{Error::EXECUTABLE} show-principle #{id} to see the members it maps.")
74
+ end
75
+ end
76
+ end
77
+ end
@@ -9,7 +9,7 @@ module Principles
9
9
  module Models
10
10
  # The members of other principles' maps sharing a line with one located member, as MembersSharingLines finds
11
11
  # them: what each result prints of them under mapped_elsewhere, and whether the agent should check the text
12
- # where their lines meet (#756, #776).
12
+ # where their lines meet.
13
13
  class MembersElsewhere
14
14
  #: (Array[MemberElsewhere]) -> void
15
15
  def initialize(members)
@@ -30,7 +30,7 @@ module Principles
30
30
  def principle_ids = @members.map(&:principle_id).uniq
31
31
 
32
32
  # Each as a full audit's request prints it, naming the findings left_open_by_principle gives its principle that
33
- # name it (#772, D62).
33
+ # name it.
34
34
  #: (Hash[String, Array[OpenFinding]]) -> Array[Hash[String, untyped]]
35
35
  def naming(left_open_by_principle)
36
36
  @members.map { |member| member.naming(left_open_by_principle.fetch(member.principle_id, [])) }
@@ -41,7 +41,7 @@ module Principles
41
41
  end
42
42
 
43
43
  # The ids of members whose text spans exactly the located member's first and last lines, so the agent sees
44
- # it may be mapping the same lines twice (#442). Equal lines are not equal text: a passage can end within
44
+ # it may be mapping the same lines twice. Equal lines are not equal text: a passage can end within
45
45
  # its last line.
46
46
  #: (Array[Member]) -> Array[String]
47
47
  def same_lines_ids_in(members)
@@ -50,7 +50,7 @@ module Principles
50
50
 
51
51
  # The members sharing a line with the located one, beside map, its own: those in map, those of them on exactly
52
52
  # its lines, and those in the other maps, as plain values, with whether the agent should check the text where
53
- # one of those holds the other's lines without being a whole file (#756).
53
+ # one of those holds the other's lines without being a whole file.
54
54
  #: (Principle)
55
55
  #| -> { overlaps: Array[String], same_lines_as: Array[String], mapped_elsewhere: Array[Hash[String, untyped]],
56
56
  #| text_check: bool }
@@ -62,10 +62,10 @@ module Principles
62
62
  end
63
63
 
64
64
  # Each member of a map other than except whose text shares a line with the located member, with its map, its
65
- # role there and its lines, so the agent sees that one edit changes both, checks the roles fit (#383) and how
66
- # much of the located member it holds, which no other part of the page shows (#610): same_lines when it spans
67
- # exactly the located member's lines (#442), spans_these_lines when its lines include all of them, and
68
- # within_these_lines when they include all of its, so the agent can tell which member an edit reaches (#718). A
65
+ # role there and its lines, so the agent sees that one edit changes both, checks the roles fit and how
66
+ # much of the located member it holds, which no other part of the page shows: same_lines when it spans
67
+ # exactly the located member's lines, spans_these_lines when its lines include all of them, and
68
+ # within_these_lines when they include all of its, so the agent can tell which member an edit reaches. A
69
69
  # partial overlap is marked neither way. A map that cannot be read is left out; list-member-problems
70
70
  # reports it.
71
71
  #: (except: String) -> MembersElsewhere
@@ -88,7 +88,7 @@ module Principles
88
88
  end
89
89
 
90
90
  # Each member that shares a line with the located member, with where it is found now: in the same file, by
91
- # its own path or through a symbolic link (#695).
91
+ # its own path or through a symbolic link.
92
92
  #: (Array[Member]) -> Array[[Member, LocatedText]]
93
93
  def sharing(members)
94
94
  members.filter_map do |member|
@@ -7,7 +7,7 @@ require_relative "activation"
7
7
  module Principles
8
8
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
- # The principle that keeps every other principle held, which setting principles up maps first (D67, D68). It is
10
+ # The principle that keeps every other principle held, which setting principles up maps first. It is
11
11
  # this product's own principle, not an example, so what its map starts with ships with the tool; once mapped, the
12
12
  # project owns the map like any other.
13
13
  module MetaPrinciple
@@ -24,18 +24,25 @@ module Principles
24
24
  # The heading of the passage this tool proposes, which the add-member command it prints names as the section.
25
25
  PASSAGE_HEADING = "Stick to your principles"
26
26
 
27
+ # The plugin's session-start hook and skill, at the paths this product's own source keeps them. Only a project
28
+ # holding that source can map them there; elsewhere they are in the installed plugin, outside the project. A
29
+ # project without the plugin wires the hook into its own settings or hooks file, where Member#package_part
30
+ # recognises it by its command; the skill comes only with the plugin.
31
+ HOOK_PATH = "plugin/hooks/hooks.json"
32
+ SKILL_PATH = "plugin/skills/principles/SKILL.md"
33
+
27
34
  # The part the passage plays as the principle's first member. It carries no check: a command stored in the
28
35
  # committed map runs on every machine that reads it, where principles may not be installed or may run from
29
- # another path (D71).
36
+ # another path.
30
37
  PASSAGE_ROLE = "States the practice of keeping every principle held, in every session"
31
38
 
32
39
  # The part a passage the project already has plays when it carries one of the passage's steps in its place,
33
- # so the step is said once (#895, #911).
40
+ # so the step is said once.
34
41
  STEP_ROLE = "Says, for this project, one of the keeping steps"
35
42
 
36
43
  # The part any other place that keeps the principles held plays as a member, such as a timer or the committed
37
44
  # setting that enables the plugin: the agent replaces STEP with the keeping step it runs and TRIGGER with what
38
- # starts it, a hook, a timer or a reader (D75).
45
+ # starts it, a hook, a timer or a reader.
39
46
  KEEPING_PLACE_ROLE = "Runs STEP, started by TRIGGER"
40
47
 
41
48
  # The repair line that sets this principle up, for a refusal of its id before its map exists: setup writes no
@@ -8,9 +8,9 @@ module Principles
8
8
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The files that broken members name but that cannot be read, each with the members it held, so one rename
11
- # reads as one new path to find (#273). Each member still takes its own move: whether every one of them
11
+ # reads as one new path to find. Each member still takes its own move: whether every one of them
12
12
  # landed in the same place is the agent's judgement. Beside a path, git_detected_rename gives any rename git
13
- # detects for it, which the agent checks before using (#276).
13
+ # detects for it, which the agent checks before using.
14
14
  class MissingFiles
15
15
  # How to read a git_detected_rename, wherever this tool gives one beside a missing file.
16
16
  RENAME_MATCH = "check before you use it: its similarity is git's percentage of the old file found in the " \
@@ -29,7 +29,7 @@ module Principles
29
29
  end
30
30
 
31
31
  # The broken members, each whose file is missing with a repair that points to its missing_files entry, so
32
- # a reader of the member alone sees any rename git detected (#285).
32
+ # a reader of the member alone sees any rename git detected.
33
33
  #: () -> Array[Hash[String, untyped]]
34
34
  def members
35
35
  @broken.map do |entry|