principles 0.1.2 → 0.1.4

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 (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +132 -0
  3. data/README.md +10 -6
  4. data/lib/principles/command_line.rb +15 -6
  5. data/lib/principles/command_routes.rb +11 -1
  6. data/lib/principles/controllers/acknowledgement.rb +19 -4
  7. data/lib/principles/controllers/acknowledgements.rb +43 -12
  8. data/lib/principles/controllers/after_commit_report.rb +15 -2
  9. data/lib/principles/controllers/assessment.rb +7 -3
  10. data/lib/principles/controllers/audit.rb +17 -8
  11. data/lib/principles/controllers/audit_completion.rb +34 -9
  12. data/lib/principles/controllers/carrier_practices.rb +26 -0
  13. data/lib/principles/controllers/command.rb +31 -3
  14. data/lib/principles/controllers/correction.rb +15 -5
  15. data/lib/principles/controllers/full_audit_request.rb +38 -42
  16. data/lib/principles/controllers/inventory.rb +77 -71
  17. data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
  18. data/lib/principles/controllers/member_acknowledgement.rb +21 -11
  19. data/lib/principles/controllers/member_addition.rb +19 -4
  20. data/lib/principles/controllers/member_entries.rb +25 -6
  21. data/lib/principles/controllers/member_problems_report.rb +26 -6
  22. data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
  23. data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
  24. data/lib/principles/controllers/members_to_assess.rb +24 -7
  25. data/lib/principles/controllers/meta_principle_setup.rb +2 -2
  26. data/lib/principles/controllers/open_correction.rb +3 -2
  27. data/lib/principles/controllers/parts_to_read.rb +46 -5
  28. data/lib/principles/controllers/plugin_member_addition.rb +48 -0
  29. data/lib/principles/controllers/principle_listing.rb +84 -0
  30. data/lib/principles/controllers/request_logging.rb +52 -0
  31. data/lib/principles/controllers/running_tool.rb +45 -17
  32. data/lib/principles/data/branches_bringing_in.rb +52 -0
  33. data/lib/principles/data/changes_since.rb +56 -0
  34. data/lib/principles/data/claude_code_home.rb +58 -0
  35. data/lib/principles/data/command-steps.json +91 -15
  36. data/lib/principles/data/decoded_leaf.rb +63 -0
  37. data/lib/principles/data/head_reflog.rb +13 -2
  38. data/lib/principles/data/kept_line.rb +32 -0
  39. data/lib/principles/data/known_marketplaces.rb +50 -0
  40. data/lib/principles/data/logged_request_matches.rb +138 -0
  41. data/lib/principles/data/logged_request_scan.rb +120 -0
  42. data/lib/principles/data/map_files.rb +18 -4
  43. data/lib/principles/data/plugin_folder.rb +85 -0
  44. data/lib/principles/data/plugin_registry.rb +73 -0
  45. data/lib/principles/data/principles_store.rb +49 -0
  46. data/lib/principles/data/ran.rb +25 -0
  47. data/lib/principles/data/raw_request_filter.rb +61 -0
  48. data/lib/principles/data/repository.rb +34 -27
  49. data/lib/principles/data/request_logging_folder.rb +167 -0
  50. data/lib/principles/data/running_version.rb +1 -1
  51. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
  52. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
  53. data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
  54. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  55. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  56. data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
  57. data/lib/principles/data/schemas/member-map.schema.json +10 -1
  58. data/lib/principles/data/string_counts.rb +39 -0
  59. data/lib/principles/data/tools_on_path.rb +25 -0
  60. data/lib/principles/invocation_options.rb +4 -2
  61. data/lib/principles/launch.rb +14 -4
  62. data/lib/principles/models/acknowledged_check.rb +11 -1
  63. data/lib/principles/models/acknowledgement.rb +15 -0
  64. data/lib/principles/models/acknowledgement_placeholders.rb +43 -18
  65. data/lib/principles/models/acknowledgement_refusal.rb +20 -11
  66. data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
  67. data/lib/principles/models/after_commit_input.rb +5 -0
  68. data/lib/principles/models/answer_fields.rb +3 -0
  69. data/lib/principles/models/assessment_basis.rb +10 -3
  70. data/lib/principles/models/audit.rb +10 -10
  71. data/lib/principles/models/audit_record.rb +10 -0
  72. data/lib/principles/models/audit_records.rb +4 -3
  73. data/lib/principles/models/audit_start.rb +9 -0
  74. data/lib/principles/models/authored_locator.rb +33 -0
  75. data/lib/principles/models/candidate_files.rb +23 -3
  76. data/lib/principles/models/candidate_outline.rb +18 -125
  77. data/lib/principles/models/captured_sessions.rb +128 -0
  78. data/lib/principles/models/carrier_kind.rb +79 -0
  79. data/lib/principles/models/cited_files.rb +12 -3
  80. data/lib/principles/models/decided_prior_findings.rb +5 -0
  81. data/lib/principles/models/disposition.rb +38 -7
  82. data/lib/principles/models/disposition_placeholders.rb +27 -7
  83. data/lib/principles/models/disposition_text_field.rb +4 -0
  84. data/lib/principles/models/feature.rb +53 -0
  85. data/lib/principles/models/finding_outcomes.rb +55 -0
  86. data/lib/principles/models/findings_left_open.rb +9 -11
  87. data/lib/principles/models/head_moves.rb +27 -10
  88. data/lib/principles/models/installed_component.rb +55 -0
  89. data/lib/principles/models/installed_plugins.rb +174 -0
  90. data/lib/principles/models/kept_sessions.rb +34 -0
  91. data/lib/principles/models/locator.rb +8 -0
  92. data/lib/principles/models/logged_request_reach.rb +44 -0
  93. data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
  94. data/lib/principles/models/mapped_baseline.rb +46 -0
  95. data/lib/principles/models/maps_holding_file_whole.rb +42 -0
  96. data/lib/principles/models/markdown_text.rb +143 -0
  97. data/lib/principles/models/member.rb +14 -1
  98. data/lib/principles/models/member_entry.rb +56 -0
  99. data/lib/principles/models/member_lines.rb +11 -0
  100. data/lib/principles/models/member_loads.rb +17 -2
  101. data/lib/principles/models/member_problems.rb +45 -42
  102. data/lib/principles/models/member_reach.rb +36 -0
  103. data/lib/principles/models/member_snapshots.rb +23 -4
  104. data/lib/principles/models/member_text_as_sent.rb +31 -0
  105. data/lib/principles/models/member_texts.rb +45 -0
  106. data/lib/principles/models/members_in_logged_requests.rb +240 -0
  107. data/lib/principles/models/missing_files.rb +41 -16
  108. data/lib/principles/models/named_placeholder.rb +17 -7
  109. data/lib/principles/models/nearly_matching_maps.rb +56 -0
  110. data/lib/principles/models/open_correction.rb +5 -0
  111. data/lib/principles/models/open_finding.rb +4 -3
  112. data/lib/principles/models/outline_budget.rb +10 -1
  113. data/lib/principles/models/outline_item.rb +25 -0
  114. data/lib/principles/models/outline_section.rb +15 -4
  115. data/lib/principles/models/part_named.rb +16 -2
  116. data/lib/principles/models/plugin_component.rb +37 -0
  117. data/lib/principles/models/plugin_install.rb +33 -0
  118. data/lib/principles/models/plugin_name.rb +23 -0
  119. data/lib/principles/models/plugin_reference.rb +53 -0
  120. data/lib/principles/models/principle_members.rb +15 -0
  121. data/lib/principles/models/prior_finding_decision.rb +1 -1
  122. data/lib/principles/models/prior_finding_outcomes.rb +12 -1
  123. data/lib/principles/models/problem_report.rb +14 -25
  124. data/lib/principles/models/project.rb +35 -29
  125. data/lib/principles/models/project_history.rb +23 -0
  126. data/lib/principles/models/recorded_members.rb +7 -0
  127. data/lib/principles/models/request_logging.rb +196 -0
  128. data/lib/principles/models/runs_from.rb +0 -5
  129. data/lib/principles/models/script_comments.rb +58 -0
  130. data/lib/principles/models/stale_request.rb +9 -0
  131. data/lib/principles/models/template_placeholders.rb +10 -9
  132. data/lib/principles/models/unfixed_part.rb +82 -0
  133. data/lib/principles/models/unresolved_plugin_members.rb +35 -0
  134. data/lib/principles/models/whole_file_member_read.rb +48 -0
  135. data/lib/principles/models/without_prose.rb +20 -0
  136. data/lib/principles/models/workflow_jobs.rb +92 -0
  137. data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
  138. data/lib/principles/show_principle_options.rb +32 -0
  139. data/lib/principles/version.rb +2 -2
  140. data/lib/principles/views/acknowledged_result.rb +31 -12
  141. data/lib/principles/views/acknowledgement_result.rb +41 -29
  142. data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
  143. data/lib/principles/views/acknowledgements_offered.rb +54 -0
  144. data/lib/principles/views/added_member.rb +22 -6
  145. data/lib/principles/views/answer_in_a_file.rb +16 -16
  146. data/lib/principles/views/assessed_members.rb +18 -7
  147. data/lib/principles/views/assessment_request.rb +8 -3
  148. data/lib/principles/views/audit_changes.rb +14 -8
  149. data/lib/principles/views/audit_findings.rb +34 -0
  150. data/lib/principles/views/audit_result.rb +14 -19
  151. data/lib/principles/views/carrier_checks.rb +40 -0
  152. data/lib/principles/views/carrier_practices_page.rb +49 -0
  153. data/lib/principles/views/completed_audit_findings.rb +33 -0
  154. data/lib/principles/views/completed_audit_next_step.rb +12 -4
  155. data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
  156. data/lib/principles/views/context_parts.rb +129 -25
  157. data/lib/principles/views/correction_request.rb +22 -17
  158. data/lib/principles/views/disposition_template.rb +35 -0
  159. data/lib/principles/views/first_audit.rb +29 -15
  160. data/lib/principles/views/first_audit_brief.rb +0 -1
  161. data/lib/principles/views/first_audit_line.rb +4 -5
  162. data/lib/principles/views/invocation.rb +16 -6
  163. data/lib/principles/views/last_record_notice.rb +41 -0
  164. data/lib/principles/views/lines_shared_with_member.rb +16 -22
  165. data/lib/principles/views/logged_request_status_meanings.rb +29 -0
  166. data/lib/principles/views/logged_requests_evidence.rb +69 -0
  167. data/lib/principles/views/map_added_to.rb +14 -12
  168. data/lib/principles/views/map_result.rb +39 -17
  169. data/lib/principles/views/member_change_since_baseline.rb +4 -0
  170. data/lib/principles/views/member_row.rb +13 -4
  171. data/lib/principles/views/member_sets_overlap.rb +31 -0
  172. data/lib/principles/views/members_a_commit_changed.rb +42 -25
  173. data/lib/principles/views/members_changed_during_audit.rb +27 -0
  174. data/lib/principles/views/members_in_logged_requests_result.rb +68 -0
  175. data/lib/principles/views/members_too_short_to_scan.rb +45 -0
  176. data/lib/principles/views/members_with_no_baseline.rb +6 -6
  177. data/lib/principles/views/meta_principle_result.rb +14 -2
  178. data/lib/principles/views/open_findings_line.rb +31 -92
  179. data/lib/principles/views/parts_index_result.rb +9 -5
  180. data/lib/principles/views/principle_read_result.rb +52 -11
  181. data/lib/principles/views/prior_findings_result.rb +9 -1
  182. data/lib/principles/views/problem_facts.rb +5 -3
  183. data/lib/principles/views/problem_lines.rb +32 -6
  184. data/lib/principles/views/problem_result.rb +7 -15
  185. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  186. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
  187. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
  188. data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
  189. data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
  190. data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
  191. data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
  192. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  193. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -0
  194. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +1 -1
  195. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
  196. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
  197. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
  198. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
  199. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
  200. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
  201. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
  202. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
  203. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +50 -51
  204. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
  205. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
  206. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
  207. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  208. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
  209. data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +16 -0
  210. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
  211. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +2 -2
  212. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +3 -3
  213. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
  214. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
  215. data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
  216. data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +20 -0
  217. data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +48 -0
  218. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +1 -1
  219. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +14 -14
  220. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
  221. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +11 -11
  222. data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +10 -0
  223. data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +32 -0
  224. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
  225. data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
  226. data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
  227. data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
  228. data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
  229. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
  230. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
  231. data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
  232. data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
  233. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
  234. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
  235. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
  236. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  237. data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
  238. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
  239. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
  240. data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
  241. data/lib/principles/views/request_logging_result.rb +62 -0
  242. data/lib/principles/views/request_part.rb +10 -4
  243. data/lib/principles/views/request_parts.rb +9 -0
  244. data/lib/principles/views/whole_file_elsewhere.rb +30 -0
  245. metadata +101 -4
  246. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
  247. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
@@ -22,12 +22,13 @@ module Principles
22
22
  # template prints, and the record with the acknowledgement in it once the answer holds.
23
23
  class MemberAcknowledgement < Command
24
24
  # The text the template prints in each field the agent writes: its judgement's placeholders, meaning_kept's
25
- # chosen by whether the change's first_changed_lines is a pure insertion, and check_result's for a
26
- # checked member. The quotes the answer reads as first_changed_lines when left out are not printed.
27
- #: (Hash[String, untyped]?, ?Views::MemberChangeSinceBaseline?) -> Hash[String, untyped]
28
- def self.placeholders(check_result, change = nil)
25
+ # chosen by whether the change's first_changed_lines is a pure insertion and file_unchanged, whether the
26
+ # member's file text is as at its baseline, and check_result's for a checked member. The quotes the answer
27
+ # reads as first_changed_lines when left out are not printed.
28
+ #: (Hash[String, untyped]?, ?Views::MemberChangeSinceBaseline?, ?file_unchanged: bool) -> Hash[String, untyped]
29
+ def self.placeholders(check_result, change = nil, file_unchanged: false)
29
30
  quotes = change&.first_changed_lines.to_h
30
- { **Models::AcknowledgementPlaceholders.beside(quotes),
31
+ { **Models::AcknowledgementPlaceholders.beside(quotes, file_unchanged:),
31
32
  **(check_result ? { "check_result" => check_result } : {}) }
32
33
  end
33
34
 
@@ -57,13 +58,11 @@ module Principles
57
58
  def asked
58
59
  baseline, lines = since_baseline
59
60
  check = check_template
60
- change = Views::MemberChangeSinceBaseline.new(
61
- member: shown(baseline), member_lines: lines.shown(taken: bytes_of(check)),
62
- first_changed_lines: @acknowledgement.first_changed_lines(lines), commits: commits(baseline),
63
- read_the_change: read_the_change(baseline)
64
- )
61
+ change = change_since(baseline, lines, check)
65
62
  { change:, context: { **@acknowledgement.open_findings, **instruction_for(check) },
66
- placeholders: MemberAcknowledgement.placeholders(check&.to_h, change) }
63
+ placeholders: MemberAcknowledgement.placeholders(
64
+ check&.to_h, change, file_unchanged: @acknowledgement.file_unchanged_since?(baseline, @project)
65
+ ) }
67
66
  end
68
67
 
69
68
  # The record with the acknowledgement in it, once its quotes are found at the baseline and now, made to into
@@ -79,6 +78,17 @@ module Principles
79
78
 
80
79
  private
81
80
 
81
+ # The member's change since baseline as the request shows it, its lines giving up the bytes check takes.
82
+ #: (Models::Placement, Models::MemberLines, Views::OneMemberCheckResultTemplate?)
83
+ #| -> Views::MemberChangeSinceBaseline
84
+ def change_since(baseline, lines, check)
85
+ Views::MemberChangeSinceBaseline.new(
86
+ member: shown(baseline), member_lines: lines.shown(taken: bytes_of(check)),
87
+ first_changed_lines: @acknowledgement.first_changed_lines(lines), commits: commits(baseline),
88
+ read_the_change: read_the_change(baseline)
89
+ )
90
+ end
91
+
82
92
  # What the member's check lists now beside the members the answer acknowledges, when the check is this
83
93
  # tool's own list-member-problems --short; nil for any other check.
84
94
  #: (Array[[String, String]]) -> Models::ListedMembers?
@@ -4,9 +4,13 @@
4
4
  require_relative "command"
5
5
  require_relative "../models/member"
6
6
  require_relative "../models/members_in_consecutive_sections"
7
+ require_relative "../models/maps_holding_file_whole"
8
+ require_relative "../models/nearly_matching_maps"
7
9
  require_relative "../models/member_loading_scopes"
8
10
  require_relative "../views/map_added_to"
9
11
  require_relative "../views/consecutive_sections_elsewhere"
12
+ require_relative "../views/whole_file_elsewhere"
13
+ require_relative "../views/member_sets_overlap"
10
14
  require_relative "../views/new_loading_scope"
11
15
 
12
16
  module Principles
@@ -27,13 +31,24 @@ module Principles
27
31
  added = located_member
28
32
  shared = lines_shared(@member, @map)
29
33
  joined = joined_for(added_to)
30
- sections = Models::MembersInConsecutiveSections.new(@project, @member).elsewhere(except: @map.id)
31
- consecutive = Views::ConsecutiveSectionsElsewhere.new(sections)
32
- map_result.member_added(principle, added: added, shared: shared, joined: joined, consecutive: consecutive)
34
+ map_result.member_added(principle, added: added, shared: shared, joined: joined,
35
+ other_maps: other_maps(added_to))
33
36
  end
34
37
 
35
38
  private
36
39
 
40
+ # What other maps hold of the new member that the agent judges: consecutive complete sections, its file held
41
+ # whole, and a member set nearly matching the one it joined, added_to.
42
+ #: (Models::Principle)
43
+ #| -> Array[Views::ConsecutiveSectionsElsewhere | Views::WholeFileElsewhere | Views::MemberSetsOverlap]
44
+ def other_maps(added_to)
45
+ sections = Models::MembersInConsecutiveSections.new(@project, @member).elsewhere(except: @map.id)
46
+ whole = Models::MapsHoldingFileWhole.new(@project, @member).elsewhere(except: @map.id)
47
+ near = Models::NearlyMatchingMaps.new(@project, added_to, @member).elsewhere
48
+ [Views::ConsecutiveSectionsElsewhere.new(sections), Views::WholeFileElsewhere.new(whole),
49
+ Views::MemberSetsOverlap.new(near)]
50
+ end
51
+
37
52
  # The updated map's after-save context, keeping the reminder facts captured before the write.
38
53
  #: (Models::Principle) -> Views::MapAddedTo
39
54
  def joined_for(added_to)
@@ -59,7 +74,7 @@ module Principles
59
74
  #: () -> Views::MapAddedTo
60
75
  def joined
61
76
  history = principle_history(@map.id)
62
- Views::MapAddedTo.new(keeps_others_held: @map.keeps_others_held?,
77
+ Views::MapAddedTo.new(keeps_held: (@principles.ids - [@map.id] if @map.keeps_others_held?),
63
78
  correction_may_be_open: history.startable_at_head?,
64
79
  reminded: history.first_add_since_commit?(@map))
65
80
  end
@@ -3,6 +3,8 @@
3
3
 
4
4
  require_relative "command"
5
5
  require_relative "member_addition"
6
+ require_relative "plugin_member_addition"
7
+ require_relative "../models/authored_locator"
6
8
 
7
9
  module Principles
8
10
  # Each runs one command: reads models, applies their rules and prints through a view.
@@ -46,9 +48,17 @@ module Principles
46
48
 
47
49
  #: (String, Hash[String, untyped]) -> untyped
48
50
  def add_member(id, options)
51
+ return handed(PluginMemberAddition).add(id, options) if options.key?("plugin")
52
+
53
+ add_project_member(id, options)
54
+ end
55
+
56
+ # Adds a member from a project file, the map's own or a new one for the keeping principle.
57
+ #: (String, Hash[String, untyped]) -> untyped
58
+ def add_project_member(id, options)
49
59
  started = !@principles.mapped?(id)
50
60
  map = @principles.addable(id)
51
- member = located(options, { "path" => text(options["path"], "PATH") }).merge(played(options))
61
+ member = new_member(options)
52
62
  addition = handed(MemberAddition, map: map, member: member)
53
63
  updated = map.adding(member)
54
64
  write_map(updated) do |printed|
@@ -57,6 +67,15 @@ module Principles
57
67
  end
58
68
  end
59
69
 
70
+ # The new member the options name: its place in its file, its opening stored as AuthoredLocator says, the part it
71
+ # plays and any check.
72
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
73
+ def new_member(options)
74
+ member = located(options, { "path" => text(options["path"], "PATH") })
75
+ opening = Models::AuthoredLocator.new(@project, Models::Member.new(member).locator).stored.starting_at
76
+ (opening ? member.merge("starting_at" => opening) : member).merge(played(options))
77
+ end
78
+
60
79
  # The part a new member plays, and the check that enforces it when one is named.
61
80
  #: (Hash[String, untyped]) -> Hash[String, untyped]
62
81
  def played(options)
@@ -79,7 +98,7 @@ module Principles
79
98
  map = @principles.find(id)
80
99
  old = map.member(text(options["member"], "MEMBER"))
81
100
  member = located(options, { "path" => new_path(options, old) })
82
- moved = span(member)
101
+ moved = span(member).merge(member)
83
102
  write_map(map.moving(Models::Member.new(old).id, member)) do |printed|
84
103
  map_result.member_moved(printed, from: Models::Member.new(old).id, moved: moved)
85
104
  end
@@ -95,8 +114,9 @@ module Principles
95
114
  def change_member_role(id, options)
96
115
  map = @principles.find(id)
97
116
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
98
- write_map(map.changing_role(target, text(options["role"], "--role"))) do |printed|
99
- map_result.member_replaced(printed, member: target, done: "Changed the role of #{target}.")
117
+ role = text(options["role"], "--role")
118
+ write_map(map.changing_role(target, role)) do |printed|
119
+ map_result.role_changed(printed, member: target, role: role)
100
120
  end
101
121
  end
102
122
 
@@ -116,8 +136,7 @@ module Principles
116
136
  map = @principles.find(id)
117
137
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
118
138
  write_map(map.removing_check(target)) do |printed|
119
- map_result.member_replaced(printed, member: target,
120
- done: "Removed the check of #{target}; the audit no longer asks for " \
139
+ map_result.member_replaced(printed, done: "Removed the check of #{target}; the audit no longer asks for " \
121
140
  "its result.")
122
141
  end
123
142
  end
@@ -4,9 +4,11 @@
4
4
  require_relative "command"
5
5
  require_relative "members_a_commit_changed"
6
6
  require_relative "../models/member_problems"
7
+ require_relative "../models/members_in_logged_requests"
7
8
  require_relative "../models/problem_report"
8
9
  require_relative "../views/record_waiting_on_an_upgrade"
9
10
  require_relative "../views/problem_result"
11
+ require_relative "../views/members_too_short_to_scan"
10
12
  require_relative "../views/problem_lines"
11
13
  require_relative "../views/first_audit_line"
12
14
 
@@ -77,9 +79,9 @@ module Principles
77
79
  lines = view.short(report, nothing_changed: Views::ProblemResult::NOTHING_CHANGED,
78
80
  assessed_change: problems.assessed_change?,
79
81
  never_assessed: problems.never_assessed, names_a_command:)
80
- return lines unless session_start
82
+ return view.at_session_start(lines, changed: problems.assessed_changes) if session_start
81
83
 
82
- view.at_session_start(lines, changed: problems.assessed_changes)
84
+ view.saying_nothing_changed(lines, members: report.fetch("counts").values.sum)
83
85
  end
84
86
 
85
87
  # list-member-problems' JSON result for map id, or every map, without the files it wrote.
@@ -121,10 +123,28 @@ module Principles
121
123
  facts = Views::ProblemFacts.new(not_read: @project.unread_older_files,
122
124
  no_baseline_files: problems.files_to_commit(@principles),
123
125
  audit_files: problems.audit_files_to_commit(@principles),
124
- acknowledgeable: problems.acknowledgeable_together(
125
- except: waiting.map(&:principle)
126
- ), waiting:)
127
- Views::ProblemResult.new(printing).checked_naming_commands(report, facts)
126
+ acknowledgeable: offered(problems, waiting), waiting:)
127
+ result, names_a_command = Views::ProblemResult.new(printing).checked_naming_commands(report, facts)
128
+ nothing_changed = Views::ProblemResult::NOTHING_CHANGED
129
+ Views::MembersTooShortToScan.new(printing, too_short).added_to(result, names_a_command, nothing_changed:)
130
+ end
131
+
132
+ # While requests are logged here, each member of the project's own files too short to find in one, by its
133
+ # principle, id and the move-member options that widen it; none otherwise, since only the scan needs them.
134
+ #: () -> Array[Hash[String, String]]
135
+ def too_short
136
+ return [] unless @project.request_logging.in_use?
137
+
138
+ Models::MembersInLoggedRequests.too_short_in(@project).map do |member|
139
+ { "principle" => member.principle, "id" => member.id, "move" => member.move_placeholders }
140
+ end
141
+ end
142
+
143
+ # The one-member audits problems offers, but for the principles waiting on an upgrade, whose audits wait.
144
+ #: (Models::ProblemReport, Array[Views::RecordWaitingOnAnUpgrade]) -> Views::AcknowledgementsOffered
145
+ def offered(problems, waiting)
146
+ offer = problems.acknowledgements(except: waiting.map(&:principle))
147
+ Views::AcknowledgementsOffered.new(offer.together, last: offer.last)
128
148
  end
129
149
  end
130
150
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
+ require_relative "../models/plugin_reference"
5
6
  require_relative "../views/members_a_commit_changed"
6
7
 
7
8
  module Principles
@@ -28,7 +29,7 @@ module Principles
28
29
  changed = @history.commits_brought_in(after).changed_by(members)
29
30
  return Views::MembersACommitChanged::NOTHING if changed.empty?
30
31
 
31
- changed_lines(event, changed, others: members.size - changed.size)
32
+ changed_lines(event, changed, others: still_listed(members - changed))
32
33
  rescue Error => e
33
34
  return Views::MembersACommitChanged::NOTHING unless @history.touched_since?(after, @principles.readable_paths)
34
35
 
@@ -37,16 +38,24 @@ module Principles
37
38
 
38
39
  private
39
40
 
40
- # The hook's output naming changed, the members the commits changed, beside others still listed, with the wait
41
- # of each of their principles whose record a later copy wrote, which says why their audits wait.
42
- #: (String, Array[Hash[String, untyped]], others: Integer) -> Views::Lines
41
+ # The hook's output naming changed, the members the commits changed, beside others still listed, those in a
42
+ # plugin apart, since no commit changes them, with the wait of each of their principles whose record a later copy
43
+ # wrote, which says why their audits wait.
44
+ #: (String, Array[Hash[String, untyped]], others: Views::MembersACommitChanged::StillListed) -> Views::Lines
43
45
  def changed_lines(event, changed, others:)
44
46
  waits = changed.map { it.fetch("principle") }.uniq.filter_map { waiting_on_an_upgrade(it) }
45
47
  view.changed(event, changed, others:, waits:)
46
48
  end
47
49
 
50
+ # The other members still listed, counted apart when a plugin holds them, which no commit changes.
51
+ #: (Array[Hash[String, untyped]]) -> Views::MembersACommitChanged::StillListed
52
+ def still_listed(others)
53
+ in_plugins, from_commits = others.partition { Models::PluginReference.in(it.fetch("id")) }
54
+ Views::MembersACommitChanged::StillListed.new(from_commits.size, in_plugins.size)
55
+ end
56
+
48
57
  #: () -> Views::MembersACommitChanged
49
- def view = Views::MembersACommitChanged.new(invocation, skill: @tool.runs_from.principles_skill_in_this_session?)
58
+ def view = Views::MembersACommitChanged.new(invocation)
50
59
  end
51
60
  end
52
61
  end
@@ -0,0 +1,52 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/members_in_logged_requests"
6
+ require_relative "../views/members_in_logged_requests_result"
7
+
8
+ module Principles
9
+ # Each runs one command: reads models, applies their rules and prints through a view.
10
+ # controllers/CLAUDE.md owns the boundary.
11
+ module Controllers
12
+ # show-members-in-logged-requests: which mapped members' text reached each request the host captured under
13
+ # .principles/request-logging/requests/, so a principle is tuned from what reached the context. It
14
+ # writes nothing.
15
+ class MembersInLoggedRequests < Command
16
+ # CommandRoutes routes only show-members-in-logged-requests here.
17
+ # Each member's reach, or with --places every place it was seen, or with --member the places of the members it
18
+ # names alone, or with --short the counts and one line a member rather than the JSON.
19
+ #: (String, String?, Hash[String, untyped]) -> untyped
20
+ def call(command, _id, options)
21
+ naming_the_executable do
22
+ @tool.feature(command).refuse_while_off
23
+ view = Views::MembersInLoggedRequestsResult.new
24
+ report = report_for(options)
25
+ options["short"] ? view.short(report) : view.result(report)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ # The scan's report in the form options ask for: every place each member --member names was seen, or each
32
+ # member's, or each member's reach.
33
+ #: (Hash[String, untyped])
34
+ #| -> { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
35
+ #| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
36
+ #| completeness: Hash[String, untyped] }
37
+ def report_for(options)
38
+ named = options["member"]
39
+ return logging.members_seen(mapped.only(named)) if named
40
+
41
+ options["places"] ? logging.members_seen(mapped) : logging.members_reached(mapped)
42
+ end
43
+
44
+ #: () -> Models::RequestLogging
45
+ def logging = @project.request_logging
46
+
47
+ # Every mapped member, to measure.
48
+ #: () -> Models::MembersInLoggedRequests
49
+ def mapped = Models::MembersInLoggedRequests.mapped_in(@project)
50
+ end
51
+ end
52
+ end
@@ -5,6 +5,7 @@ require_relative "command"
5
5
  require_relative "../models/carried_member"
6
6
  require_relative "../models/check_since_last_audit"
7
7
  require_relative "../models/open_findings_elsewhere"
8
+ require_relative "../models/whole_file_member_read"
8
9
  require_relative "../views/acknowledged_since_last_audit"
9
10
  require_relative "../views/read_the_change"
10
11
 
@@ -113,10 +114,12 @@ module Principles
113
114
  open_here: @record&.open_ids_on(member.key) || []).shown
114
115
  end
115
116
 
116
- # Whether member's file changed since the last full audit's base commit; nil with no such commit, as outside git.
117
+ # Whether member's file changed since the last full audit's base commit; nil with no such commit, as outside git,
118
+ # and for a plugin member, whose file git holds no history of.
117
119
  #: (Models::Member) -> bool?
118
120
  def file_changed_outside(member)
119
121
  base = @completed&.base_commit or return
122
+ return if member.plugin_reference
120
123
 
121
124
  @history.commits_since(base, member.path).any?
122
125
  end
@@ -129,26 +132,40 @@ module Principles
129
132
  true
130
133
  end
131
134
 
132
- # The member as the request names and locates it: id, role, evidence and its lines now.
135
+ # The member as the request names and locates it: id, role, evidence and its lines now, and for a plugin
136
+ # member, where it comes from, read-only, at the version installed now.
133
137
  #: (Models::Member, Models::MemberSnapshots) -> Hash[String, untyped]
134
138
  def located(member, current)
139
+ source = @project.installed_plugins.source_of(member)
135
140
  { "id" => member.id, "role" => member.role, "evidence" => [member.reference] }
136
- .merge(current.of(member.id).lines)
141
+ .merge(current.of(member.id).lines, source ? { "source" => source } : {})
137
142
  end
138
143
 
139
144
  # The command that shows the edits to a member judged again since the last full audit's base commit: to its
140
145
  # own lines, where current locates them, for part of a file at the same path then and now; else to its file,
141
146
  # over its path then and now. Nothing for a member carried forward, or with no such commit, as outside git or
142
- # before any full audit.
147
+ # before any full audit, or for a plugin member, whose file git holds no history of.
143
148
  #: (Hash[String, untyped], Hash[String, untyped], Models::MemberSnapshots) -> Hash[String, untyped]
144
149
  def changed_since(fields, judged, current)
145
150
  base = @completed&.base_commit
146
- return {} unless judged["judge_because"] && base
147
-
148
151
  member = Models::Member.new(fields)
152
+ return {} unless judged["judge_because"] && base && !member.plugin_reference
153
+
149
154
  paths = principle_history(@principle_id).paths_from(base, member.key, fields)
150
155
  lines = member.traced_lines(paths, current.of(member.id).lines)
151
- { "read_the_change" => Views::ReadTheChange.new(since: base, paths:, lines:).to_s }
156
+ { "read_the_change" => Views::ReadTheChange.new(since: base, paths:, lines:).to_s,
157
+ **changed_lines(member, judged, base) }
158
+ end
159
+
160
+ # The changed lines of a whole-file member judged for its text changing since base, with no context, as
161
+ # WholeFileMemberRead says, beside the text it reads apart; nothing for another member, or one whose lines at
162
+ # base cannot be found.
163
+ #: (Models::Member, Hash[String, untyped], String) -> Hash[String, untyped]
164
+ def changed_lines(member, judged, base)
165
+ return {} unless Models::WholeFileMemberRead.new(whole_file: member.whole_file?, listed: judged).changed_lines?
166
+
167
+ lines = @project.member_lines(member.locator, since: base) or return {}
168
+ { "changed_lines" => lines.regions(context: 0) }
152
169
  end
153
170
 
154
171
  # The edits to member acknowledged since the last full audit, which this audit judges together, with
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
- require_relative "inventory"
5
+ require_relative "principle_listing"
6
6
  require_relative "../models/entry_files"
7
7
  require_relative "../models/meta_principle"
8
8
  require_relative "../models/text_size"
@@ -49,7 +49,7 @@ module Principles
49
49
 
50
50
  # The project's other principles, as list-principles lists them, which this principle's first audit keeps held.
51
51
  #: () -> Array[Hash[String, untyped]]
52
- def existing_principles = handed(Inventory).rows(@principles.ids - [Models::MetaPrinciple::ID])
52
+ def existing_principles = handed(PrincipleListing).rows(@principles.ids - [Models::MetaPrinciple::ID])
53
53
 
54
54
  # Where the passage can go: how this run was started and whether the hook runs in this session, the project's
55
55
  # entry files, and the passage.
@@ -34,8 +34,9 @@ module Principles
34
34
  kept = Models::OpenCorrection.kept(principle_id, @audit_records.find(principle_id),
35
35
  file: @audit_records.file(principle_id))
36
36
  head = Views::AnswerHead.new(request_id: kept.request_id, basis: kept.basis)
37
- placeholders = Models::DispositionPlaceholders::TEMPLATE_PLACEHOLDERS
38
- Views::CorrectionRequest.new(head:, principle_id:, findings: kept.findings, placeholders:).correction_to_fill
37
+ disposition = Views::DispositionTemplate.new(Models::DispositionPlaceholders::TEMPLATE_PLACEHOLDERS,
38
+ kept.prior_decided.deferrals_raised_again)
39
+ Views::CorrectionRequest.new(head:, principle_id:, findings: kept.findings, disposition:).correction_to_fill
39
40
  end
40
41
  end
41
42
  end
@@ -3,10 +3,13 @@
3
3
 
4
4
  require_relative "command"
5
5
  require_relative "../models/evidence_lines_since"
6
+ require_relative "../models/feature"
7
+ require_relative "../models/members_in_logged_requests"
6
8
  require_relative "../models/loading_decision"
7
9
  require_relative "../models/other_principles"
8
10
  require_relative "../models/prior_decision_fields"
9
11
  require_relative "../models/uncommitted_outside_the_map"
12
+ require_relative "../views/logged_requests_evidence"
10
13
  require_relative "../views/loads_to_check_result"
11
14
  require_relative "../views/open_findings_elsewhere_result"
12
15
  require_relative "../views/other_principles_unjudged_result"
@@ -43,19 +46,57 @@ module Principles
43
46
  # What the agent reads beside the members, in order: the files outside the map that differ from the
44
47
  # base commit, which a check and the answer's evidence read as they are now; the prior findings;
45
48
  # the findings other principles leave open on members sharing these lines; and the members to
46
- # check against the activation; each when it lists any; and, on the meta-principle's audit, the release
47
- # since its last audit and the other principles with members no audit has judged.
48
- #: (Models::PriorFindings, Hash[String, untyped]?) -> Array[Views::RequestPart]
49
- def listed(prior, loads)
49
+ # check against the activation; each when it lists any; on the meta-principle's audit, the release
50
+ # since its last audit and the other principles with members no audit has judged; and what the logged
51
+ # requests show of the members, unless scanned is false, for a read that prints none of it.
52
+ #: (Models::PriorFindings, Hash[String, untyped]?, ?scanned: bool) -> Array[Views::RequestPart]
53
+ def listed(prior, loads, scanned: true)
50
54
  map = @audit.map
51
55
  [outside_the_map, prior_findings_part(prior),
52
56
  Views::OpenFindingsElsewhereResult.new(@listing.open_findings_elsewhere).part,
53
57
  loads_part(loads), package_since_last_audit(map),
54
- other_principles_unjudged(map)].compact
58
+ other_principles_unjudged(map), logged_requests_part(scanned)].compact
55
59
  end
56
60
 
57
61
  private
58
62
 
63
+ # The part saying how far the listed members' text reached the logged requests, or why
64
+ # nothing shows it: the folder unguarded, which is asked first since every other read of it refuses then; none
65
+ # captured; or a tool the scan runs missing. Unless scanned, the scan itself does not run, and the part holds
66
+ # nothing.
67
+ #: (bool) -> Views::RequestPart
68
+ def logged_requests_part(scanned)
69
+ logging = @project.request_logging
70
+ evidence = Views::LoggedRequestsEvidence.new(invocation)
71
+ refusal = logging.unguarded_refusal
72
+ return evidence.unread(refusal.payload) if refusal
73
+ return evidence.none_captured if logging.none_captured?
74
+
75
+ scanned_part(logging, evidence, scanned)
76
+ end
77
+
78
+ # The part from the scan of the captured requests for the listed members, or why the scan cannot run; unless
79
+ # scanned, the part holding nothing.
80
+ #: (Models::RequestLogging, Views::LoggedRequestsEvidence, bool) -> Views::RequestPart
81
+ def scanned_part(logging, evidence, scanned)
82
+ off = @tool.feature(Models::Feature::LOGGED_REQUEST_SCAN).off_refusal
83
+ return evidence.unread(off.payload) if off
84
+ return evidence.not_scanned unless scanned
85
+
86
+ evidence.reached(logging.reach(measured_members, carried: carried_ids).to_h)
87
+ end
88
+
89
+ # The members whose reach the part shows: every one the request lists, carried ones too, each named as it is
90
+ # listed there.
91
+ #: () -> Models::MembersInLoggedRequests
92
+ def measured_members
93
+ Models::MembersInLoggedRequests.listed_in(@project, @audit.map, @listing.members.map { it.fetch("id") })
94
+ end
95
+
96
+ # The ids of the members the audit carries forward, which the part marks.
97
+ #: () -> Array[String]
98
+ def carried_ids = @listing.members.select { it["carried_forward"] }.map { it.fetch("id") }
99
+
59
100
  # The part listing the members to check against the activation, each decision's template printing the
60
101
  # placeholders an answer leaves as printed to give none; nil when none is listed.
61
102
  #: (Hash[String, untyped]?) -> Views::RequestPart?
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../error"
6
+ require_relative "../prose_list"
7
+ require_relative "../models/plugin_component"
8
+
9
+ module Principles
10
+ module Controllers
11
+ # add-member --plugin: a member read from a plugin Claude Code installed, which the project maps but never edits.
12
+ class PluginMemberAddition < Command
13
+ # Maps the file options name in an installed plugin whole, pinning the version installed and the hash of its
14
+ # text, in principle id's map, which it starts when there is none.
15
+ #: (String, Hash[String, untyped]) -> untyped
16
+ def add(id, options)
17
+ refuse_location(options)
18
+ found = installed(options)
19
+ started = !@principles.mapped?(id)
20
+ write_map(@principles.addable(id).adding(found.member(text(options["role"], "--role")))) do |printed|
21
+ added = map_result.plugin_member_added(printed, added: found.added)
22
+ started ? added.merge(map_result.map_created(printed)) : added
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ # Refuses the location flags a plugin member would ignore, before anything is read: its file is mapped whole.
29
+ #: (Hash[String, untyped]) -> void
30
+ def refuse_location(options)
31
+ given = MemberEntries::LOCATION_OPTIONS.filter_map { |name, flag| flag if options.key?(name) }
32
+ return if given.empty?
33
+
34
+ raise Error.new("plugin_member_located", "#{ProseList.new(given)} cannot locate a plugin member",
35
+ "A plugin's file is mapped whole, so run add-member --plugin again without " \
36
+ "#{ProseList.new(given)}.")
37
+ end
38
+
39
+ # The file PATH names inside the plugin --plugin names, checked to be a plain path before anything installed
40
+ # is read, then found among the plugins installed for the project.
41
+ #: (Hash[String, untyped]) -> Models::InstalledComponent
42
+ def installed(options)
43
+ component = Models::PluginComponent.new(text(options["path"], "PATH"))
44
+ @project.installed_plugins.holding(text(options["plugin"], "--plugin"), component)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,84 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../views/principle_read_result"
6
+
7
+ module Principles
8
+ # Each runs one command: reads models, applies their rules and prints through a view.
9
+ # controllers/CLAUDE.md owns the boundary.
10
+ module Controllers
11
+ # list-principles: each mapped principle with its members counted by freshness against its last audit, or the
12
+ # refusal that kept its map from being read. It changes nothing on disk. Inventory shows one principle.
13
+ class PrincipleListing < Command
14
+ #: (String, String?, Hash[String, untyped]) -> untyped
15
+ def call(command, _id, options)
16
+ naming_the_executable do
17
+ case command
18
+ when "list-principles" then listed(options)
19
+ else unknown(command)
20
+ end
21
+ end
22
+ end
23
+
24
+ # Each principle id names as list-principles lists it: its description and its members by freshness, or the
25
+ # refusal that kept its map from being read.
26
+ #: (Array[String]) -> Array[Hash[String, untyped]]
27
+ def rows(ids) = ids.map { entry(it) }
28
+
29
+ private
30
+
31
+ #: () -> Views::PrincipleReadResult
32
+ def read_result
33
+ Views::PrincipleReadResult.new(invocation)
34
+ end
35
+
36
+ # list-principles as options ask: each id on a line with --lines, else the rows as JSON.
37
+ #: (Hash[String, untyped]) -> untyped
38
+ def listed(options)
39
+ return read_result.ids(@principles.ids) if options["lines"]
40
+
41
+ listing(open_findings: options["open_findings"]).merge("wrote" => [])
42
+ end
43
+
44
+ # Its next_action offers an audit while one principle's audits do not wait on an upgrade; a map listed with its
45
+ # refusal counts, since repairing it leaves it to audit. With open_findings, each row lists its open findings.
46
+ #: (open_findings: bool?) -> untyped
47
+ def listing(open_findings:)
48
+ ids = @principles.ids
49
+ waiting = ids.filter_map { waiting_on_an_upgrade(it) }
50
+ listed = open_findings ? read_result.with_open_findings(rows(ids), open_by_principle(ids)) : rows(ids)
51
+ read_result.listing(listed, waiting: waiting, one_to_audit: waiting.size < ids.size)
52
+ end
53
+
54
+ # Each principle's open findings, from every record this copy can read, as list-open-findings reads them,
55
+ # aged until now, by principle id.
56
+ #: (Array[String]) -> Hash[String, Array[Hash[String, untyped]]]
57
+ def open_by_principle(ids)
58
+ now = Time.now.utc
59
+ @audit_records.readable_of(ids).flat_map(&:left_open).map { it.waited_at(now) }
60
+ .group_by { it.fetch("principle") }
61
+ end
62
+
63
+ # One map's row; a map this tool cannot read is listed with its refusal, so the others still show, and one
64
+ # whose record a later copy wrote says its audits wait on an upgrade, as show-audit does.
65
+ #: (String) -> Hash[String, untyped]
66
+ def entry(id)
67
+ map = @principles.find(id)
68
+ row = map.description_with_id.merge("members_by_freshness" => members_by_freshness(map))
69
+ row = row.merge(read_result.no_members(@principles.file(id))) if map.unstarted?
70
+ row.merge(waiting_on_an_upgrade(id)&.marker || {})
71
+ rescue Error => e
72
+ { "id" => id, "refusal" => e.payload }
73
+ end
74
+
75
+ # How many of map's members are in each freshness state, against its principle's last audit, or the hashes a
76
+ # record a later copy wrote holds, read-only, when this copy cannot read the rest of it.
77
+ #: (Models::Principle) -> Hash[String, Integer]
78
+ def members_by_freshness(map)
79
+ hashes = @audit_records.hashes_to_compare(map.id)
80
+ map.members_shown.map { |member| fresh(member, hashes).fetch("freshness") }.tally.sort.to_h
81
+ end
82
+ end
83
+ end
84
+ end