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
@@ -6,9 +6,9 @@ require_relative "prompts"
6
6
  module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
- # What --help prints: Markdown, because it is a prompt the agent reads before running a command (ticket 001
10
- # D15). It is kept short, since every line lands in the agent's context. Refusal codes stay out: a refusal
11
- # arrives with its own code and repair when it happens.
9
+ # What --help prints: Markdown, because it is a prompt the agent reads before running a command. It is kept short,
10
+ # since every line lands in the agent's context. Refusal codes stay out: a refusal arrives with its own code and
11
+ # repair when it happens.
12
12
  module Help
13
13
  # What the page says after an agent's step: what the tool then checks, what it cannot check, and the
14
14
  # usage of the command the agent runs next.
@@ -19,7 +19,7 @@ module Principles
19
19
  attr_reader :cannot_check
20
20
  #: String?
21
21
  attr_reader :then_run
22
- # When the agent runs then_run, where it is the agent's to time; "Then" otherwise (#627).
22
+ # When the agent runs then_run, where it is the agent's to time; "Then" otherwise.
23
23
  #: String?
24
24
  attr_reader :then_run_when
25
25
 
@@ -0,0 +1,91 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "../prose_list"
6
+ require_relative "prompts"
7
+
8
+ module Principles
9
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
+ module Views
11
+ # What show-hook-setup prints: each host's file and the hook entries that go in it, for the agent to show the user
12
+ # and write only once the user agrees.
13
+ class HookSetupResult
14
+ # The executable each entry runs: principles as found on PATH, since the running executable's path names the
15
+ # installed version, which an upgrade removes, and Codex asks the user to trust a hook again when it changes.
16
+ EXECUTABLE = "principles"
17
+
18
+ # What the agent reads when principles did not start, which both commands' exit status 0 never says otherwise.
19
+ FAILED = "principles: principles failed to start, so this session gets no report from it: run it with " \
20
+ "--version to see why."
21
+
22
+ # A hook's timeout, in seconds, as each host reads it.
23
+ TIMEOUT = 15
24
+
25
+ # What the result says first when no principles on PATH prints a version, so every entry would fail to start.
26
+ NONE_ON_PATH = "No principles on PATH prints its version, so each entry below would print its failure line in " \
27
+ "every session. Install the principles gem where the hooks' shell finds it before writing them."
28
+
29
+ # What the result says first when another version of principles is first on PATH, which each entry would run,
30
+ # and the commands of the entries that copy does not run.
31
+ #: (String, String, String, lacking: Array[String]) -> String
32
+ def self.other_on_path(path, version, running, lacking:)
33
+ runs = if lacking.empty?
34
+ "which runs both report commands, so each entry would report as #{version} does"
35
+ else
36
+ "which does not run #{ProseList.new(lacking, conjunction: "or")}, so each entry would print its " \
37
+ "failure line in every session"
38
+ end
39
+ "The principles on PATH, #{path}, is #{version}, not this #{running}, so each entry below would run " \
40
+ "#{version}, #{runs}. Update or remove that copy before writing them."
41
+ end
42
+
43
+ # hosts gives each "host" by name, its "file", why it is "offered" and its "hooks", each with its "event",
44
+ # "matcher" and "command";
45
+ # principles_on_path says what PATH would run in place of this copy, or is nil when it runs this one.
46
+ #: (Array[Hash[String, untyped]], principles_on_path: String?) -> void
47
+ def initialize(hosts, principles_on_path:)
48
+ @hosts = hosts
49
+ @principles_on_path = principles_on_path
50
+ freeze
51
+ end
52
+
53
+ # The entries, after what PATH would run in their place, when that is not this copy.
54
+ #: () -> Hash[String, untyped]
55
+ def result
56
+ { **({ "principles_on_path" => @principles_on_path } if @principles_on_path),
57
+ "hosts" => @hosts.map { it.slice("host", "file", "offered").merge("entries" => entries(it)) },
58
+ "next_action" => Prompts.text("set-principles-up/wire-the-report-hooks-with-the-user"), "wrote" => [] }
59
+ end
60
+
61
+ private
62
+
63
+ # host's entries by event, each one matcher group.
64
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
65
+ def entries(host)
66
+ { "hooks" => host.fetch("hooks").to_h { [it.fetch("event"), [group(it)]] } }
67
+ end
68
+
69
+ # One matcher group, its one handler running hook's command, guarded.
70
+ #: (Hash[String, String]) -> Hash[String, untyped]
71
+ def group(hook)
72
+ command = guarded(hook.fetch("event"), hook.fetch("command"))
73
+ { "matcher" => hook.fetch("matcher"),
74
+ "hooks" => [{ "type" => "command", "command" => command, "timeout" => TIMEOUT }] }
75
+ end
76
+
77
+ # command, followed by the echo that runs when it exits other than 0, which it never does once started: plain
78
+ # text at session start, and after a call the hook's JSON, since the agent never reads such a hook's plain
79
+ # stdout.
80
+ #: (String, String) -> String
81
+ def guarded(event, command)
82
+ said = if event == "SessionStart"
83
+ FAILED
84
+ else
85
+ JSON.generate({ "hookSpecificOutput" => { "hookEventName" => event, "additionalContext" => FAILED } })
86
+ end
87
+ "#{EXECUTABLE} #{command} || echo '#{said}'"
88
+ end
89
+ end
90
+ end
91
+ end
@@ -5,7 +5,7 @@ module Principles
5
5
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
6
  module Views
7
7
  # One instruction a judgement request prints under its own field: its paragraphs, each printed only when the
8
- # request holds the case it explains, and every one when the agent reads the field whole (D81 step 2, #983).
8
+ # request holds the case it explains, and every one when the agent reads the field whole.
9
9
  class Instruction
10
10
  #: String
11
11
  attr_reader :field
@@ -42,13 +42,13 @@ module Principles
42
42
  end
43
43
 
44
44
  # The guide to an answer's shapes a judgement request prints under its own field: its entries, each printed only
45
- # when the request holds the case it shows, and every one when the agent reads the field whole (D81 step 2).
45
+ # when the request holds the case it shows, and every one when the agent reads the field whole.
46
46
  class GuideInstruction
47
47
  #: String
48
48
  attr_reader :field
49
49
 
50
50
  # guide is every entry; held says, by entry name, whether the request holds its case. narrowed is, by name, an
51
- # entry as the request prints it when it holds the entry's case but not every case within it (#983).
51
+ # entry as the request prints it when it holds the entry's case but not every case within it.
52
52
  #: (String, Hash[String, untyped], ?narrowed: Hash[String, untyped]) { (String) -> bool } -> void
53
53
  def initialize(field, guide, narrowed: {}, &held)
54
54
  @field = field
@@ -25,25 +25,29 @@ module Principles
25
25
  end
26
26
 
27
27
  # The same invocation, its commands leaving out --project, for output that names the project once and whose
28
- # commands run from there, as list-member-problems --short's stderr does (#1263).
28
+ # commands run from there, as list-member-problems --short's stderr does.
29
29
  #: () -> Invocation
30
30
  def without_project = Invocation.new(executable: @executable, project: @project, named: false)
31
31
 
32
+ # Whether each command names the project.
33
+ #: () -> bool
34
+ def named? = @named
35
+
32
36
  # The project as a shell word, as --project gives it.
33
37
  #: () -> String
34
38
  def project_word = shell_word(@project)
35
39
 
36
- # A command to run in this project, which it names right after the executable, as model repairs do (#580).
40
+ # A command to run in this project, which it names right after the executable, as model repairs do.
37
41
  # Each value is shell-quoted, because ids, paths and headings come from project files that anyone may have
38
- # written (#227). options are flags with their values, such as
42
+ # written. options are flags with their values, such as
39
43
  # ["--starting-at", text], quoted the same way. usage is this tool's own placeholder text, such as
40
44
  # "--section HEADING", left for the agent to fill and never quoted. When a value starts with "-", as a
41
- # path may, every option comes first and "--" ends them, so the value is not read as an option (#240).
45
+ # path may, every option comes first and "--" ends them, so the value is not read as an option.
42
46
  #: (String, *String, ?options: Array[String], ?usage: String?) -> String
43
47
  def in_project(command, *values, options: [], usage: nil) = listed_in_project(command, values, options:, usage:)
44
48
 
45
49
  # The command that answers request request_id in this project: from file, the --file value an answer was
46
- # checked from, as given, or before there is one, from a FILE the agent names (#859).
50
+ # checked from, as given, or before there is one, from a FILE the agent names.
47
51
  #: (String, ?file: String?) -> String
48
52
  def submit_answer(request_id, file: nil)
49
53
  return in_project("submit-answer", request_id, usage: "--file FILE") unless file
@@ -51,7 +55,7 @@ module Principles
51
55
  in_project("submit-answer", request_id, options: ["--file", file])
52
56
  end
53
57
 
54
- # The same command, its values given as one list, as a refusal's repair command holds them (D56).
58
+ # The same command, its values given as one list, as a refusal's repair command holds them.
55
59
  #: (String, Array[String], ?options: Array[String], ?usage: String?) -> String
56
60
  def listed_in_project(command, values, options: [], usage: nil)
57
61
  flags = options.map { |value| shell_word(value) }
@@ -68,6 +72,10 @@ module Principles
68
72
  "--project #{shell_word(@project)}"
69
73
  end
70
74
 
75
+ # What each command starts with: the executable, then --project and the project unless they are left out.
76
+ #: () -> String
77
+ def prefix = [@executable, named_project].compact.join(" ")
78
+
71
79
  private
72
80
 
73
81
  # --project and the project, or nil when the commands leave it out.
@@ -1,26 +1,20 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "json"
4
+ require_relative "printed_json"
5
5
 
6
6
  module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
- # A JSON result printed pretty, but for one array whose entries each print compact on a line of their own.
10
- # list-candidate-files' file entries are that array: pretty-printing cost 17% of a 66 KB result, and one compact
11
- # line of 36 KB is the worst shape to read by lines (#1155). It is the first case of ticket 007's decision on the
12
- # output format; every other result prints pretty.
9
+ # A JSON result printed a field a line, as every result prints, but for one array whose entries each print compact
10
+ # on a line of their own. list-candidate-files' file entries are that array: a field a line costs a third more
11
+ # lines than an entry a line, and one compact line of 27 KB is the worst shape to read by lines.
13
12
  class JsonWithEntriesOnLines
14
- # Stands in for the array while the rest prints pretty. Replacement targets its root object and direct key,
15
- # so an identical project string elsewhere stays untouched regardless of the result's field order.
16
- MARKER = "\u0000entries on lines of their own\u0000"
17
-
18
13
  # The array is result[under][key].
19
14
  #: (Hash[String, untyped], under: String, key: String) -> void
20
15
  def initialize(result, under:, key:)
21
16
  @result = result
22
- @under = under
23
- @key = key
17
+ @path = [under, key] #: Array[String]
24
18
  freeze
25
19
  end
26
20
 
@@ -30,30 +24,7 @@ module Principles
30
24
 
31
25
  # The result as printed.
32
26
  #: () -> String
33
- def text
34
- marked = JSON.pretty_generate(@result.merge(@under => @result.fetch(@under).merge(@key => MARKER)))
35
- marked.sub(array_place) { "#{Regexp.last_match(1)}#{lines(" ")}" }
36
- end
37
-
38
- private
39
-
40
- # The designated array placeholder at its known depth in JSON.pretty_generate's two-space layout.
41
- #: () -> Regexp
42
- def array_place
43
- parent = Regexp.escape(JSON.generate(@under))
44
- child = Regexp.escape(JSON.generate(@key))
45
- marker = Regexp.escape(JSON.generate(MARKER))
46
- /(^ #{parent}: \{.*?^ #{child}: )#{marker}/m
47
- end
48
-
49
- # The array's entries, each compact on its own line, one step in from indent.
50
- #: (String) -> String
51
- def lines(indent)
52
- entries = @result.fetch(@under).fetch(@key)
53
- return "[]" if entries.empty?
54
-
55
- "[\n#{entries.map { |entry| "#{indent} #{JSON.generate(entry)}" }.join(",\n")}\n#{indent}]"
56
- end
27
+ def text = PrintedJson.with_entries_on_lines(@result, @path)
57
28
  end
58
29
  end
59
30
  end
@@ -6,7 +6,7 @@ module Principles
6
6
  module Views
7
7
  # In git, what landed after a completed audit's base commit, as its result prints it: the commits since the base
8
8
  # that touched each member the audit changed, by member id, and the base and HEAD when HEAD differs from the base
9
- # and none touched one (#740). Outside git a completed audit has none, so it is given only in git.
9
+ # and none touched one. Outside git a completed audit has none, so it is given only in git.
10
10
  class LandedSinceBase
11
11
  #: (commits_by_member: Hash[String, Array[Hash[String, String]]], ?head_past_base: [String, String]?) -> void
12
12
  def initialize(commits_by_member:, head_past_base: nil)
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "shell_word"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # The command that shows each commit's edits to a member's own lines since the last full audit's base commit, as
10
+ # git traces those lines back from the commit now, so a short member of a long file is read without the rest of
11
+ # the file's edits. Each commit is named by its short id and subject, and each word is quoted for the shell.
12
+ class LineHistorySinceLastAudit
13
+ # last_audited_commit is the last full audit's base commit; path is the member's file, at the same path then
14
+ # and now; first_line and last_line are the lines it spans now, 1-based; to is the commit the history ends at,
15
+ # or nil for HEAD, where git reads those lines, so it must hold the file as it is now, as HEAD does once an audit
16
+ # has refused a member file that differs from it.
17
+ #: (last_audited_commit: String, path: String, first_line: Integer, last_line: Integer, ?to: String?) -> void
18
+ def initialize(last_audited_commit:, path:, first_line:, last_line:, to: nil)
19
+ @last_audited_commit = last_audited_commit
20
+ @path = path
21
+ @first_line = first_line
22
+ @last_line = last_line
23
+ @to = to
24
+ freeze
25
+ end
26
+
27
+ #: () -> String
28
+ def to_s
29
+ range = "#{@last_audited_commit}..#{@to || "HEAD"}"
30
+ words = ["--format=%h %s", "-L", "#{@first_line},#{@last_line}:#{@path}", range]
31
+ "git log #{words.map { |word| ShellWord.new(word).to_s }.join(" ")}"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -7,15 +7,15 @@ module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
9
  # What add-member's result says of the members sharing a line with the member it added, show-principle
10
- # beside each member it shows (#541), and a full audit's request beside each member, of other maps only (#719):
10
+ # beside each member it shows, and a full audit's request beside each member, of other maps only:
11
11
  # those in its map (overlaps), those of them spanning exactly its lines
12
- # (same_lines_as, #442), and those in other maps, with their roles there and same_lines when they span exactly
12
+ # (same_lines_as), and those in other maps, with their roles there and same_lines when they span exactly
13
13
  # its lines, spans_these_lines when their lines include all of its and within_these_lines when its lines
14
- # include theirs (mapped_elsewhere, #383, #718). Each field is printed only when there are some; add-member
14
+ # include theirs (mapped_elsewhere). Each field is printed only when there are some; add-member
15
15
  # also prints the sentences that say what it means for the agent.
16
16
  class LinesSharedWithMember
17
17
  # Why the agent checks the text where the lines meet, unless each member holding another's lines is a whole
18
- # file, which holds every line's text (#756).
18
+ # file, which holds every line's text.
19
19
  TEXT_CHECK = "Lines are not text: where two share a first or last line, a passage can start or end partway " \
20
20
  "through it, so check the text there before deciding which edit reaches which member. " #: String
21
21
 
@@ -61,7 +61,7 @@ module Principles
61
61
  end
62
62
 
63
63
  # Which of them span all of this member's lines and which lie within them, so the agent can work out which
64
- # member an edit reaches (#718). Lines are not text, so the agent checks where they share a first or last line.
64
+ # member an edit reaches. Lines are not text, so the agent checks where they share a first or last line.
65
65
  #: () -> String
66
66
  def spans_note
67
67
  spans = @mapped_elsewhere.filter_map do |each|
@@ -99,7 +99,7 @@ module Principles
99
99
  "meant, say why in this member's role. "
100
100
  end
101
101
 
102
- # Each member spanning exactly these lines, by id, with its principle when it is in another (#445).
102
+ # Each member spanning exactly these lines, by id, with its principle when it is in another.
103
103
  #: () -> Array[String]
104
104
  def same_lines_named
105
105
  elsewhere = @mapped_elsewhere.select { |each| each["same_lines"] }
@@ -8,15 +8,18 @@ require_relative "request_part"
8
8
  module Principles
9
9
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
10
  module Views
11
- # How a full audit's request shows the members to check against the principle's activation (#355 slice 3).
11
+ # How a full audit's request shows the members to check against the principle's activation.
12
12
  class LoadsToCheckResult
13
- # What a decision may be, as the answer printed alone says where it is written (#746).
13
+ # The part this lists, by the name the request prints it under and start-audit --part takes.
14
+ PART = "loads_to_check_against_activation" #: String
15
+
16
+ # What a decision may be, as the answer printed alone says where it is written.
14
17
  DECISION = "accepted, with reason saying why the member loads as it does; kept, with no reason, where " \
15
18
  "last_accepted.since_accepted is unchanged; if the activation is wrong instead, change it and " \
16
19
  "start the audit again" #: String
17
20
 
18
21
  # listed is the members to check, nil when there are none, and id the principle they belong to; placeholders
19
- # is the text the template alone prints in each field of a decision beside it, which left is not given (#994).
22
+ # is the text the template alone prints in each field of a decision beside it, which left is not given.
20
23
  #: (Invocation, Hash[String, untyped]?, String, placeholders: Hash[String, String]) -> void
21
24
  def initialize(invocation, listed, id, placeholders:)
22
25
  @placeholders = placeholders
@@ -33,7 +36,7 @@ module Principles
33
36
  listed = @listed or return
34
37
 
35
38
  decisions = listed.fetch("rows").map { |row| { "member_id" => row.fetch("member_id"), "decision" => nil } }
36
- RequestPart.new(shown: { "loads_to_check_against_activation" => listed },
39
+ RequestPart.new(shown: { PART => listed },
37
40
  instructions: [Instruction.of_paragraphs("loads_to_check_instruction", instruction) { true }],
38
41
  slots: { "loading_decisions" => decisions },
39
42
  help: { "loading_decisions" => { "decision" => DECISION, **@placeholders } })
@@ -42,7 +45,7 @@ module Principles
42
45
  private
43
46
 
44
47
  # How to decide each listed member, naming the activation change for a principle whose work is in hand in
45
- # every session (#509).
48
+ # every session.
46
49
  #: () -> String
47
50
  def instruction
48
51
  always = @invocation.in_project("change-activation", @id, options: ["--always"])
@@ -8,10 +8,10 @@ module Principles
8
8
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
9
  module Views
10
10
  # What add-member's result needs to know of the map a member joined, beyond the map itself: whether its
11
- # principle keeps the others held, which changes the step after mapping (D71), and whether a full audit's
12
- # correction may be open on it, so that the member may fix one of its findings (D72, #1023), and whether to repeat
11
+ # principle keeps the others held, which changes the step after mapping, and whether a full audit's
12
+ # correction may be open on it, so that the member may fix one of its findings, and whether to repeat
13
13
  # what to do after mapping: with a principle's first member, or in git the first since the map's last commit, so
14
- # members mapped in one sitting do not each repeat it (#1025).
14
+ # members mapped in one sitting do not each repeat it.
15
15
  class MapAddedTo
16
16
  COMPLETENESS_QUESTION = "Is every carrier of the same rule mapped, and should any member belong to another " \
17
17
  "principle? "
@@ -29,7 +29,7 @@ module Principles
29
29
  "material the members govern."
30
30
 
31
31
  # in_git says whether the project is in git, where a committed map is each member's baseline until its first
32
- # full audit (#623).
32
+ # full audit.
33
33
  #: (Invocation, in_git: bool) -> void
34
34
  def initialize(invocation, in_git:)
35
35
  @invocation = invocation
@@ -59,14 +59,14 @@ module Principles
59
59
  end
60
60
 
61
61
  # What this tool recorded of when the work is in hand, and what a full audit lists against it, as
62
- # Models::Activation#full_audit_lists names it (#355, #523).
62
+ # Models::Activation#full_audit_lists names it.
63
63
  #: (PrintedPrinciple, lists: String) -> Hash[String, untyped]
64
64
  def activation_changed(principle, lists:)
65
65
  question(principle, ActivationInHand.new(principle.activation || {}).recorded(principle.id, lists),
66
66
  start_audit(principle.id), shown: { "activation" => principle.activation })
67
67
  end
68
68
 
69
- # change-activation when the map already held that activation, so it wrote nothing (#474).
69
+ # change-activation when the map already held that activation, so it wrote nothing.
70
70
  #: (PrintedPrinciple) -> Hash[String, untyped]
71
71
  def activation_unchanged(principle)
72
72
  question(principle, ActivationInHand.new(principle.activation || {}).unchanged(principle.id),
@@ -89,7 +89,7 @@ module Principles
89
89
  end
90
90
 
91
91
  # add-member's report of the map it started, with the description and activation it wrote, which the agent
92
- # never typed (#929).
92
+ # never typed.
93
93
  #: (PrintedPrinciple) -> Hash[String, untyped]
94
94
  def map_created(principle)
95
95
  { "map_created" => { "description" => principle.description, "activation" => principle.activation } }
@@ -106,8 +106,8 @@ module Principles
106
106
  end
107
107
 
108
108
  # change-member-check: the stored command is the member's check in the map printed beside this, so the
109
- # agent can see it byte for byte; the question names that field rather than quoting project text (#227).
110
- # hidden names each character in the check that prints escaped or not at all (#260).
109
+ # agent can see it byte for byte; the question names that field rather than quoting project text.
110
+ # hidden names each character in the check that prints escaped or not at all.
111
111
  #: (PrintedPrinciple, member: String, hidden: Array[String]) -> Hash[String, untyped]
112
112
  def check_changed(principle, member:, hidden:)
113
113
  done = "#{member} is now enforced by the check named in its map entry. The next audit marks it new or " \
@@ -122,8 +122,8 @@ module Principles
122
122
  end
123
123
 
124
124
  # change-member-role, change-member-check and remove-member-check: done says what changed. This tool cannot
125
- # tell in git whether a full audit's correction is open, so the next step names both cases (D40, #461), and
126
- # the other case by what the agent holds: a correction request (second alpha user on 8e5b3f9).
125
+ # tell in git whether a full audit's correction is open, so the next step names both cases, and
126
+ # the other case by what the agent holds: a correction request (one user on 8e5b3f9).
127
127
  #: (PrintedPrinciple, member: String, done: String) -> Hash[String, untyped]
128
128
  def member_replaced(principle, member:, done:)
129
129
  question(principle, "#{done} Check the other members, then start the audit.\nIf you hold a correction " \
@@ -143,7 +143,7 @@ module Principles
143
143
  private
144
144
 
145
145
  # shown is what the result prints of the map: the whole map unless the caller names less, as add-member
146
- # does (#400).
146
+ # does.
147
147
  #: (PrintedPrinciple, String, String, ?shown: Hash[String, untyped]) -> Hash[String, untyped]
148
148
  def question(principle, text, answer_with, shown: { "map" => principle.map })
149
149
  { "status" => "question", "principle_id" => principle.id, "map_file" => principle.file, **shown,
@@ -1,32 +1,31 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "shell_word"
4
+ require_relative "read_the_change"
5
5
 
6
6
  module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
9
  # One member's change since its baseline, as a one-member audit's request shows it: the member's id, role and
10
10
  # evidence, the commit its baseline text is at, the commit the audit is based on, the member's own lines at
11
- # each (#379), and the command that shows its file's change between them, following a move (D33, #551).
11
+ # each, and the command that shows its change between them.
12
12
  class MemberChangeSinceBaseline
13
13
  # member holds the member's id, role and evidence; commits holds "base", HEAD, and "baseline", the commit
14
14
  # the member's baseline text is at, and "audit_base" when the baseline is later than the audit's base;
15
- # member_lines holds its own lines at each, or their counts when too long; paths holds the paths the change
16
- # spans, its path at the baseline first; first_changed_lines the first line on each side the other lacks.
15
+ # member_lines holds its own lines at each, or their counts when too long; first_changed_lines the first line
16
+ # on each side the other lacks; read_the_change the command that shows the change from baseline to base.
17
17
  #: (member: Hash[String, untyped], commits: Hash[String, String], member_lines: Hash[String, untyped],
18
- #| first_changed_lines: Hash[String, String], paths: Array[String]) -> void
19
- def initialize(member:, commits:, member_lines:, first_changed_lines:, paths:)
18
+ #| first_changed_lines: Hash[String, String], read_the_change: ReadTheChange) -> void
19
+ def initialize(member:, commits:, member_lines:, first_changed_lines:, read_the_change:)
20
20
  @member = member
21
21
  @commits = commits
22
22
  @member_lines = member_lines
23
23
  @first_changed_lines = first_changed_lines
24
- @paths = paths
24
+ @read_the_change = read_the_change
25
25
  freeze
26
26
  end
27
27
 
28
- # The first line on each side the other lacks, which an answer leaving its quotes out reads them as (#1111,
29
- # #1166).
28
+ # The first line on each side the other lacks, which an answer leaving its quotes out reads them as.
30
29
  #: Hash[String, String]
31
30
  attr_reader :first_changed_lines
32
31
 
@@ -40,36 +39,58 @@ module Principles
40
39
  @commits.fetch("base")
41
40
  end
42
41
 
42
+ # Whether other prints the same change as this one: the same lines and first changed lines, as one
43
+ # member mapped by two principles does from baselines holding the same text, whatever commit each is at.
44
+ #: (MemberChangeSinceBaseline) -> bool
45
+ def same_change_as?(other) = other.change == change
46
+
47
+ # The fields as the request prints them, but the change, which another principle's entry prints under
48
+ # principle_id.
49
+ #: (String) -> Hash[String, untyped]
50
+ def shown_under(principle_id)
51
+ shown = change
52
+ to_h.reject { |field, _| shown.key?(field) }.merge("change_shown_under" => principle_id)
53
+ end
54
+
43
55
  # The fields as the request prints them. Lines left out for their length point at read_the_change instead,
44
- # so the request is never silently partial (D38).
56
+ # so the request is never silently partial.
45
57
  #: () -> Hash[String, untyped]
46
58
  def to_h
47
- read = read_the_change
59
+ read = @read_the_change.to_s
48
60
  lines = @member_lines.key?("omitted") ? @member_lines.merge("read_instead" => read) : with_read_instead(read)
49
61
  { "member" => @member, "baseline_commit" => @commits.fetch("baseline"), "base_commit" => base_commit,
50
62
  **@commits.slice("audit_base").transform_keys { "audit_base_commit" },
51
63
  "member_lines" => lines, "first_changed_lines" => @first_changed_lines, "read_the_change" => read }
52
64
  end
53
65
 
66
+ protected
67
+
68
+ # The fields that print the change itself, as the request prints them, which a request across principles
69
+ # prints once for a shared member.
70
+ #: () -> Hash[String, untyped]
71
+ def change = to_h.slice("member_lines", "first_changed_lines")
72
+
54
73
  private
55
74
 
56
- # The member's lines, each side of their changed region left out pointing at read, as the whole lines do (#1103).
75
+ # The member's lines, each side of their changed region, or of each of their changed regions, left out pointing
76
+ # at read, as the whole lines do.
57
77
  #: (String) -> Hash[String, untyped]
58
78
  def with_read_instead(read)
59
- region = @member_lines["changed_region"]
60
- return @member_lines unless region
61
-
62
- sides = region.transform_values do |side|
63
- side.is_a?(Hash) && side.key?("omitted") ? side.merge("read_instead" => read) : side
79
+ @member_lines.to_h do |key, value|
80
+ case key
81
+ when "changed_region" then [key, region_reading(value, read)]
82
+ when "changed_regions" then [key, value.map { region_reading(it, read) }]
83
+ else [key, value]
84
+ end
64
85
  end
65
- @member_lines.merge("changed_region" => sides)
66
86
  end
67
87
 
68
- # Each word quoted for the shell, and every path read by git as written, not as a pattern (#558).
69
- #: () -> String
70
- def read_the_change
71
- words = [@commits.fetch("baseline"), base_commit, "--", *@paths].map { |word| ShellWord.new(word).to_s }
72
- "git --literal-pathspecs diff -M #{words.join(" ")}"
88
+ # region with each side left out pointing at read.
89
+ #: (Hash[String, untyped], String) -> Hash[String, untyped]
90
+ def region_reading(region, read)
91
+ region.transform_values do |side|
92
+ side.is_a?(Hash) && side.key?("omitted") ? side.merge("read_instead" => read) : side
93
+ end
73
94
  end
74
95
  end
75
96
  end
@@ -0,0 +1,43 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # A member's lines at its last full audit and now, as AcknowledgedSinceLastAudit prints them, beside the member's
8
+ # text printed whole, as its start-audit --part prints it: each side now names where it starts in the text and
9
+ # how many of its lines it spans, so the part carries each line now once.
10
+ class MemberLinesBesideText
11
+ #: (Hash[String, untyped]) -> void
12
+ def initialize(member_lines)
13
+ @member_lines = member_lines
14
+ freeze
15
+ end
16
+
17
+ # The lines as printed, each side now that lists its lines pointing at the text instead.
18
+ #: () -> Hash[String, untyped]
19
+ def shown
20
+ lines = @member_lines
21
+ return lines.merge("now" => in_text(1, lines.fetch("now"))) if lines["now"].is_a?(Array)
22
+ return lines.merge("changed_region" => region(lines.fetch("changed_region"))) if lines["changed_region"]
23
+ return lines.merge("changed_regions" => lines.fetch("changed_regions").map { region(it) }) if
24
+ lines["changed_regions"]
25
+
26
+ lines
27
+ end
28
+
29
+ private
30
+
31
+ # A changed region, its side now pointing at the text when it lists its lines.
32
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
33
+ def region(changed)
34
+ now = changed.fetch("now")
35
+ now["lines"] ? changed.merge("now" => in_text(now.fetch("from_line"), now.fetch("lines"))) : changed
36
+ end
37
+
38
+ # Where lines start in the text, and how many they are.
39
+ #: (Integer, Array[String]) -> Hash[String, Integer]
40
+ def in_text(from_line, lines) = { "from_line" => from_line, "lines_in_text" => lines.length }
41
+ end
42
+ end
43
+ end
@@ -31,7 +31,7 @@ module Principles
31
31
  end
32
32
 
33
33
  # member, as show-principle prints it, with its repairs as repair_with when moves, its moves, are given, as the
34
- # controller gives them for a member an audit would refuse (#272).
34
+ # controller gives them for a member an audit would refuse.
35
35
  #: (String, Hash[String, untyped], Array[Hash[String, untyped]]?) -> Hash[String, untyped]
36
36
  def beside(id, member, moves)
37
37
  return member unless moves
@@ -44,7 +44,8 @@ module Principles
44
44
  #: (String, String, Hash[String, untyped]) -> String
45
45
  def move(id, member_id, move)
46
46
  kept = move.fetch("keep").flat_map { |field, value| [FLAGS.fetch(field), value] }
47
- usage = move.fetch("fill").map { "#{FLAGS.fetch(it)} #{PLACEHOLDERS.fetch(it)}" }.join(" ")
47
+ fill = move.fetch("fill")
48
+ usage = fill.map { "#{FLAGS.fetch(it)} #{PLACEHOLDERS.fetch(it)}" }.join(" ") unless fill.empty?
48
49
  @invocation.in_project("move-member", id, member_id, options: kept, usage: usage)
49
50
  end
50
51
  end