principles 0.1.3 → 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 (237) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +120 -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 +29 -2
  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_addition.rb +19 -4
  19. data/lib/principles/controllers/member_entries.rb +25 -6
  20. data/lib/principles/controllers/member_problems_report.rb +26 -6
  21. data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
  22. data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
  23. data/lib/principles/controllers/members_to_assess.rb +24 -7
  24. data/lib/principles/controllers/meta_principle_setup.rb +2 -2
  25. data/lib/principles/controllers/open_correction.rb +3 -2
  26. data/lib/principles/controllers/parts_to_read.rb +46 -5
  27. data/lib/principles/controllers/plugin_member_addition.rb +48 -0
  28. data/lib/principles/controllers/principle_listing.rb +84 -0
  29. data/lib/principles/controllers/request_logging.rb +52 -0
  30. data/lib/principles/controllers/running_tool.rb +39 -13
  31. data/lib/principles/data/branches_bringing_in.rb +52 -0
  32. data/lib/principles/data/changes_since.rb +56 -0
  33. data/lib/principles/data/claude_code_home.rb +58 -0
  34. data/lib/principles/data/command-steps.json +91 -15
  35. data/lib/principles/data/decoded_leaf.rb +63 -0
  36. data/lib/principles/data/head_reflog.rb +13 -2
  37. data/lib/principles/data/kept_line.rb +32 -0
  38. data/lib/principles/data/known_marketplaces.rb +50 -0
  39. data/lib/principles/data/logged_request_matches.rb +138 -0
  40. data/lib/principles/data/logged_request_scan.rb +120 -0
  41. data/lib/principles/data/map_files.rb +18 -4
  42. data/lib/principles/data/plugin_folder.rb +85 -0
  43. data/lib/principles/data/plugin_registry.rb +73 -0
  44. data/lib/principles/data/principles_store.rb +49 -0
  45. data/lib/principles/data/ran.rb +25 -0
  46. data/lib/principles/data/raw_request_filter.rb +61 -0
  47. data/lib/principles/data/repository.rb +29 -27
  48. data/lib/principles/data/request_logging_folder.rb +167 -0
  49. data/lib/principles/data/running_version.rb +1 -1
  50. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
  51. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
  52. data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
  53. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  54. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  55. data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
  56. data/lib/principles/data/schemas/member-map.schema.json +10 -1
  57. data/lib/principles/data/string_counts.rb +39 -0
  58. data/lib/principles/data/tools_on_path.rb +25 -0
  59. data/lib/principles/invocation_options.rb +4 -2
  60. data/lib/principles/launch.rb +14 -4
  61. data/lib/principles/models/acknowledged_check.rb +11 -1
  62. data/lib/principles/models/acknowledgement.rb +5 -0
  63. data/lib/principles/models/acknowledgement_refusal.rb +20 -11
  64. data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
  65. data/lib/principles/models/after_commit_input.rb +5 -0
  66. data/lib/principles/models/answer_fields.rb +3 -0
  67. data/lib/principles/models/assessment_basis.rb +10 -3
  68. data/lib/principles/models/audit.rb +10 -10
  69. data/lib/principles/models/audit_record.rb +10 -0
  70. data/lib/principles/models/audit_records.rb +4 -3
  71. data/lib/principles/models/audit_start.rb +9 -0
  72. data/lib/principles/models/authored_locator.rb +33 -0
  73. data/lib/principles/models/candidate_files.rb +23 -3
  74. data/lib/principles/models/candidate_outline.rb +18 -125
  75. data/lib/principles/models/captured_sessions.rb +128 -0
  76. data/lib/principles/models/carrier_kind.rb +79 -0
  77. data/lib/principles/models/cited_files.rb +12 -3
  78. data/lib/principles/models/decided_prior_findings.rb +5 -0
  79. data/lib/principles/models/disposition.rb +37 -6
  80. data/lib/principles/models/disposition_placeholders.rb +12 -0
  81. data/lib/principles/models/disposition_text_field.rb +4 -0
  82. data/lib/principles/models/feature.rb +53 -0
  83. data/lib/principles/models/finding_outcomes.rb +55 -0
  84. data/lib/principles/models/findings_left_open.rb +9 -11
  85. data/lib/principles/models/head_moves.rb +27 -10
  86. data/lib/principles/models/installed_component.rb +55 -0
  87. data/lib/principles/models/installed_plugins.rb +174 -0
  88. data/lib/principles/models/kept_sessions.rb +34 -0
  89. data/lib/principles/models/locator.rb +8 -0
  90. data/lib/principles/models/logged_request_reach.rb +44 -0
  91. data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
  92. data/lib/principles/models/mapped_baseline.rb +46 -0
  93. data/lib/principles/models/maps_holding_file_whole.rb +42 -0
  94. data/lib/principles/models/markdown_text.rb +143 -0
  95. data/lib/principles/models/member.rb +14 -1
  96. data/lib/principles/models/member_entry.rb +56 -0
  97. data/lib/principles/models/member_lines.rb +11 -0
  98. data/lib/principles/models/member_loads.rb +17 -2
  99. data/lib/principles/models/member_problems.rb +45 -42
  100. data/lib/principles/models/member_reach.rb +36 -0
  101. data/lib/principles/models/member_snapshots.rb +23 -4
  102. data/lib/principles/models/member_text_as_sent.rb +31 -0
  103. data/lib/principles/models/member_texts.rb +45 -0
  104. data/lib/principles/models/members_in_logged_requests.rb +240 -0
  105. data/lib/principles/models/missing_files.rb +41 -16
  106. data/lib/principles/models/nearly_matching_maps.rb +56 -0
  107. data/lib/principles/models/open_correction.rb +5 -0
  108. data/lib/principles/models/open_finding.rb +4 -3
  109. data/lib/principles/models/outline_budget.rb +10 -1
  110. data/lib/principles/models/outline_item.rb +25 -0
  111. data/lib/principles/models/outline_section.rb +15 -4
  112. data/lib/principles/models/part_named.rb +16 -2
  113. data/lib/principles/models/plugin_component.rb +37 -0
  114. data/lib/principles/models/plugin_install.rb +33 -0
  115. data/lib/principles/models/plugin_name.rb +23 -0
  116. data/lib/principles/models/plugin_reference.rb +53 -0
  117. data/lib/principles/models/principle_members.rb +15 -0
  118. data/lib/principles/models/prior_finding_decision.rb +1 -1
  119. data/lib/principles/models/prior_finding_outcomes.rb +12 -1
  120. data/lib/principles/models/problem_report.rb +14 -25
  121. data/lib/principles/models/project.rb +35 -29
  122. data/lib/principles/models/project_history.rb +19 -5
  123. data/lib/principles/models/recorded_members.rb +7 -0
  124. data/lib/principles/models/request_logging.rb +196 -0
  125. data/lib/principles/models/runs_from.rb +0 -5
  126. data/lib/principles/models/script_comments.rb +58 -0
  127. data/lib/principles/models/stale_request.rb +9 -0
  128. data/lib/principles/models/unfixed_part.rb +82 -0
  129. data/lib/principles/models/unresolved_plugin_members.rb +35 -0
  130. data/lib/principles/models/whole_file_member_read.rb +48 -0
  131. data/lib/principles/models/without_prose.rb +20 -0
  132. data/lib/principles/models/workflow_jobs.rb +92 -0
  133. data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
  134. data/lib/principles/show_principle_options.rb +32 -0
  135. data/lib/principles/version.rb +2 -2
  136. data/lib/principles/views/acknowledged_result.rb +31 -12
  137. data/lib/principles/views/acknowledgement_result.rb +18 -13
  138. data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
  139. data/lib/principles/views/acknowledgements_offered.rb +54 -0
  140. data/lib/principles/views/added_member.rb +22 -6
  141. data/lib/principles/views/answer_in_a_file.rb +15 -15
  142. data/lib/principles/views/assessed_members.rb +18 -7
  143. data/lib/principles/views/assessment_request.rb +8 -3
  144. data/lib/principles/views/audit_changes.rb +14 -8
  145. data/lib/principles/views/audit_findings.rb +34 -0
  146. data/lib/principles/views/audit_result.rb +14 -19
  147. data/lib/principles/views/carrier_checks.rb +40 -0
  148. data/lib/principles/views/carrier_practices_page.rb +49 -0
  149. data/lib/principles/views/completed_audit_findings.rb +33 -0
  150. data/lib/principles/views/completed_audit_next_step.rb +12 -4
  151. data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
  152. data/lib/principles/views/context_parts.rb +129 -25
  153. data/lib/principles/views/correction_request.rb +21 -16
  154. data/lib/principles/views/disposition_template.rb +35 -0
  155. data/lib/principles/views/first_audit.rb +29 -15
  156. data/lib/principles/views/first_audit_line.rb +4 -5
  157. data/lib/principles/views/invocation.rb +14 -5
  158. data/lib/principles/views/last_record_notice.rb +41 -0
  159. data/lib/principles/views/lines_shared_with_member.rb +16 -22
  160. data/lib/principles/views/logged_request_status_meanings.rb +29 -0
  161. data/lib/principles/views/logged_requests_evidence.rb +69 -0
  162. data/lib/principles/views/map_added_to.rb +14 -12
  163. data/lib/principles/views/map_result.rb +39 -17
  164. data/lib/principles/views/member_change_since_baseline.rb +4 -0
  165. data/lib/principles/views/member_row.rb +13 -4
  166. data/lib/principles/views/member_sets_overlap.rb +31 -0
  167. data/lib/principles/views/members_a_commit_changed.rb +42 -25
  168. data/lib/principles/views/members_changed_during_audit.rb +27 -0
  169. data/lib/principles/views/members_in_logged_requests_result.rb +68 -0
  170. data/lib/principles/views/members_too_short_to_scan.rb +45 -0
  171. data/lib/principles/views/members_with_no_baseline.rb +6 -6
  172. data/lib/principles/views/meta_principle_result.rb +14 -2
  173. data/lib/principles/views/open_findings_line.rb +31 -92
  174. data/lib/principles/views/parts_index_result.rb +9 -5
  175. data/lib/principles/views/principle_read_result.rb +52 -11
  176. data/lib/principles/views/prior_findings_result.rb +9 -1
  177. data/lib/principles/views/problem_facts.rb +5 -3
  178. data/lib/principles/views/problem_lines.rb +32 -6
  179. data/lib/principles/views/problem_result.rb +7 -15
  180. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
  181. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
  182. data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
  183. data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
  184. data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
  185. data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
  186. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  187. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -0
  188. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
  189. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
  190. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
  191. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
  192. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
  193. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
  194. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
  195. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
  196. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +50 -51
  197. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
  198. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
  199. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
  200. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  201. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
  202. data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +16 -0
  203. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
  204. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +2 -2
  205. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
  206. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
  207. data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
  208. data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +20 -0
  209. data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +48 -0
  210. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +14 -14
  211. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
  212. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +10 -10
  213. data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +10 -0
  214. data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +32 -0
  215. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
  216. data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
  217. data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
  218. data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
  219. data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
  220. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
  221. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
  222. data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
  223. data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
  224. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
  225. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
  226. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
  227. data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
  228. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
  229. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
  230. data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
  231. data/lib/principles/views/request_logging_result.rb +62 -0
  232. data/lib/principles/views/request_part.rb +10 -4
  233. data/lib/principles/views/request_parts.rb +9 -0
  234. data/lib/principles/views/whole_file_elsewhere.rb +30 -0
  235. metadata +101 -4
  236. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
  237. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
@@ -6,6 +6,8 @@ require_relative "command"
6
6
  require_relative "../models/audit"
7
7
  require_relative "../models/commits_since_base"
8
8
  require_relative "../models/other_principles"
9
+ require_relative "../views/completed_audit_findings"
10
+ require_relative "../views/members_changed_during_audit"
9
11
  require_relative "../views/prior_finding_decisions_result"
10
12
 
11
13
  require_relative "../views/answered_request"
@@ -58,18 +60,30 @@ module Principles
58
60
 
59
61
  private
60
62
 
61
- # What the completed audit prints: its resolved and open findings, as the record it writes holds them, so they
62
- # agree with list-open-findings; what it changed; each prior finding's decision; and, while
63
+ # What the completed audit prints: its resolved, deferred and accepted findings, as the record it writes holds
64
+ # them, so they agree with list-open-findings; what it changed; each prior finding's decision; and, while
63
65
  # principles is not set up, the offer to set it up.
64
66
  #: (Models::AuditStart, Models::Audit, Array[Models::Disposition], Models::DecidedPriorFindings,
65
67
  #| Models::AuditRecord) -> untyped
66
68
  def completion_result(start, audit, dispositions, decided, written)
67
69
  decisions = Views::PriorFindingDecisionsResult.new(kept_ids: decided.kept_ids, closed: decided.closed,
68
70
  changed: decided.changed)
69
- completed = audit_result.completion(principle_id: audit.id, resolved: written.resolved_ids(decided),
70
- open: written.open_ids,
71
+ findings = Views::CompletedAuditFindings.new(resolved: written.resolved_ids(decided),
72
+ deferred: written.left_open_ids("deferred"),
73
+ accepted: written.left_open_ids("accepted"))
74
+ completed = audit_result.completion(principle_id: audit.id, findings: findings,
71
75
  changes: changes(start, audit, dispositions, written), decisions: decisions)
72
- offering_set_up(completed)
76
+ offering_set_up(offering_request_logging(completed, written))
77
+ end
78
+
79
+ # completed, naming turn-on-request-logging when written is the project's first full audit and requests are not
80
+ # logged here, since logged requests show whether members reach the agent at all.
81
+ #: (Hash[String, untyped], Models::AuditRecord) -> Hash[String, untyped]
82
+ def offering_request_logging(completed, written)
83
+ return completed if @project.request_logging.in_use?
84
+ return completed if @audit_records.of(@principles.ids).any? { it.completed_other_than?(written) }
85
+
86
+ audit_result.offering_request_logging(completed)
73
87
  end
74
88
 
75
89
  # completed, with the offer to set principles up while it is not, and outside the plugin, whose hooks report
@@ -88,11 +102,22 @@ module Principles
88
102
  def changes(start, audit, dispositions, written)
89
103
  changed = audit.changed_files(dispositions)
90
104
  added = start.added(now: audit.now)
91
- map = @map_changes&.files_to_commit(@principles.file(audit.id), added: added) || []
92
- files = @audit_records.files_to_commit(written, changed + map, start.reported)
93
- Views::AuditChanges.new(files_to_commit: files, landed: landed_since_base(start, audit), added: added,
105
+ missing = @audit_records.cited_files_missing(written, @project.installed_plugins)
106
+ Views::AuditChanges.new(files_to_commit: files_to_commit(start, audit, written, changed, added),
107
+ landed: landed_since_base(start, audit),
108
+ members_changed: Views::MembersChangedDuringAudit.new(
109
+ added: added, changed: start.changed(now: audit.now)
110
+ ),
94
111
  other_changed: other_changed(audit, changed),
95
- cited_files_missing: @audit_records.cited_files_missing(written))
112
+ cited_files_missing: missing)
113
+ end
114
+
115
+ # The files the completed audit commits: its record, the files its fixes changed, which are changed, and the
116
+ # map when its correction added members to it, which are added.
117
+ #: (Models::AuditStart, Models::Audit, Models::AuditRecord, Array[String], Array[String]) -> Array[String]
118
+ def files_to_commit(start, audit, written, changed, added)
119
+ map = @map_changes&.files_to_commit(@principles.file(audit.id), added: added) || []
120
+ @audit_records.files_to_commit(written, changed + map, start.reported)
96
121
  end
97
122
 
98
123
  # Each other principle with a member in paths, the files this audit's fixes changed, whose own text now
@@ -0,0 +1,26 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/carrier_kind"
6
+ require_relative "../views/carrier_practices_page"
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-carrier-practices KIND: the page of one carrier kind's practices, for an agent judging or editing a member
13
+ # of that kind to read beyond the check a request prints. It writes nothing.
14
+ class CarrierPractices < Command
15
+ #: (String, String?, Hash[String, untyped]) -> untyped
16
+ def call(command, _id, options)
17
+ naming_the_executable do
18
+ unknown(command) unless command == "show-carrier-practices"
19
+
20
+ named = Models::CarrierKind.named(options.fetch("kind"))
21
+ Views::CarrierPracticesPage.of(named).result(named)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -14,7 +14,9 @@ require_relative "../models/project"
14
14
  require_relative "../models/record_format"
15
15
  require_relative "../models/record_judged_against"
16
16
  require_relative "../views/audit_result"
17
+ require_relative "../views/invocation"
17
18
  require_relative "../views/lines_shared_with_member"
19
+ require_relative "../views/carrier_checks"
18
20
  require_relative "../views/map_result"
19
21
  require_relative "../views/record_waiting_on_an_upgrade"
20
22
  require_relative "broken_member_repairs"
@@ -88,6 +90,13 @@ module Principles
88
90
  "To see every command: #{@tool.executable} --help")
89
91
  end
90
92
 
93
+ # Where member is now and whether it changed since the record holding hashes assessed it.
94
+ #: (Hash[String, untyped], Models::RecordedHashes) -> Hash[String, untyped]
95
+ def fresh(member, hashes)
96
+ found = Models::Member.new(member)
97
+ @project.freshness(found.locator) { |sha| hashes.freshness(found.key, sha) }
98
+ end
99
+
91
100
  # The controller this one hands part of its command to, over the same project and naming the same executable.
92
101
  #: [C < Command] (Class[C], **untyped) -> C
93
102
  def handed(controller, **)
@@ -98,7 +107,8 @@ module Principles
98
107
  # each run and never stored.
99
108
  #: () -> Views::Invocation
100
109
  def invocation
101
- @tool.invocation(@project.root, answer_folder: @history.ignored_tmp_folder)
110
+ answer_folder = @history.ignored_tmp_folder(Views::Invocation.answer_name("ID", "phase"))
111
+ @tool.invocation(@project.root, answer_folder:)
102
112
  end
103
113
 
104
114
  # Principle id as waiting on an upgrade, when a later copy wrote its record.
@@ -145,13 +155,30 @@ module Principles
145
155
 
146
156
  # Each member's hash at base, or nil outside git.
147
157
  #: (String?, Models::Principle) -> Hash[String, String]?
148
- def committed(base, map) = base ? @history.at(base).hashes(map.members) : nil
158
+ def committed(base, map) = base ? @history.at(base).hashes(map.members.in_project) : nil
159
+
160
+ # basis, its assessment id digesting the last commit that changed the map's file or a member's file at its base,
161
+ # so a commit elsewhere leaves the id as it was.
162
+ #: (Models::AssessmentBasis, Models::Principle) -> Models::AssessmentBasis
163
+ def audited_basis(basis, map)
164
+ base = basis.base or return basis
165
+ basis.audited_at(@history.last_change(@principles.audited_files(map.id, map.members.in_project), at: base))
166
+ end
149
167
 
150
168
  # When each of the map's members loads, by id, which a full audit's request lists against the activation and
151
169
  # show-principle prints, from the project's hooks as hooks read them.
152
170
  #: (Models::Principle, ?Models::HookCommands) -> Hash[String, Models::MemberLoads]
153
171
  def member_loads(map, hooks = @project.hook_commands) = @project.member_loads(map.members, hooks)
154
172
 
173
+ # The check for each carrier kind the map's members are in, or only those ids names, in the order given, once
174
+ # each, for a request where the agent judges or edits them.
175
+ #: (Models::Principle, ?Array[String]?) -> Hash[String, untyped]
176
+ def carrier_checks(map, ids = nil)
177
+ kinds = member_loads(map).transform_values { it.carrier_kind.name }
178
+ named = ids&.filter_map { |id| [id, kinds.fetch(id)] if kinds.key?(id) }&.to_h
179
+ Views::CarrierChecks.new(named || kinds, invocation).to_h
180
+ end
181
+
155
182
  # The members a full audit lists to check against its activation, each with the decision its last completed
156
183
  # audit, whose record is given or read now, accepted on the member's loading.
157
184
  #: (Models::Audit, ?Models::AuditRecord?) -> Models::LoadsToCheck
@@ -85,6 +85,7 @@ module Principles
85
85
  def dispositions(response, findings, start, audit)
86
86
  samples = Views::CorrectionRequest.answer_guide(Models::DispositionPlaceholders::PLACEHOLDERS.fetch("reason"))
87
87
  .fetch("disposition")
88
+ start.check_plugin_members_unchanged(now: audit.now)
88
89
  Models::CorrectionAnswer.new(response, findings, samples:) { |locator| snapshot(locator) }
89
90
  .dispositions(changed: start.changed(now: audit.now))
90
91
  end
@@ -103,19 +104,28 @@ module Principles
103
104
  principle_history(id).map_at(base)
104
105
  end
105
106
 
106
- # Each member's hash when the audit began, checked against the request id: from the map it started from at the
107
- # base commit in git, after the declared changes are checked against that map, or from the open record outside
108
- # git.
107
+ # Each member's hash when the audit began, checked against the request id, from the map it started from, after
108
+ # the declared changes are checked against that map.
109
109
  #: (Models::RequestId, Models::CorrectionBasis, Models::Audit, Models::DeclaredMapChanges) -> Hash[String, String]
110
110
  def confirmed_start(request_id, basis, audit, changes)
111
- map = started_from(basis, audit, changes)
112
111
  base = basis.base_commit
113
- found = base ? committed(base, map) : @audit_records.find(audit.id)&.base_members
112
+ found = hashes_started_with(base, started_from(basis, audit, changes))
114
113
  checked = audit.confirmed_start(request_id, basis, found)
115
114
  principle_history(audit.id).confirm_current_id_since(base)
116
115
  checked
117
116
  end
118
117
 
118
+ # Each member's hash when the audit of map began: at the base commit in git, beside each plugin member's from
119
+ # the open record, since no commit holds a plugin's file; or all from the open record outside git; nil when
120
+ # they cannot be found.
121
+ #: (String?, Models::Principle) -> Hash[String, String]?
122
+ def hashes_started_with(base, map)
123
+ record = @audit_records.find(map.id)
124
+ return record&.base_members unless base
125
+
126
+ committed(base, map)&.merge(record&.members&.plugin_hashes(map.members) || {})
127
+ end
128
+
119
129
  # The completion of a correction, which read its assessment back from the audit's record: the open one or, for
120
130
  # an identical retry, the completed one.
121
131
  #: (Models::DeclaredMapChanges, Models::CorrectionBasis, Models::Audit) -> AuditCompletion
@@ -4,12 +4,14 @@
4
4
  require_relative "command"
5
5
  require_relative "../models/audit"
6
6
  require_relative "../models/instruction_named"
7
+ require_relative "../models/member_texts"
7
8
  require_relative "../models/meta_principle"
8
9
  require_relative "../models/part_named"
9
10
  require_relative "../models/recent_decision"
10
11
  require_relative "../models/reported_check"
11
12
  require_relative "../views/assessment_request"
12
13
  require_relative "../views/parts_index_result"
14
+ require_relative "last_record_notice_beside"
13
15
  require_relative "members_to_assess"
14
16
  require_relative "parts_to_read"
15
17
 
@@ -21,6 +23,10 @@ module Principles
21
23
  # the commit it is based on, its id and what it asks. Starting writes nothing: the request id is a digest of what
22
24
  # the request depends on, so Answer checks the answer against the project as it is then.
23
25
  class FullAuditRequest < Command
26
+ # The parts --part prints from the scan of the captured requests: its own alone, since the index, read first to
27
+ # size the reads after it, leaves that part unsized rather than wait on the scan.
28
+ SCANNED = [Views::LoggedRequestsEvidence::PART].freeze #: Array[String]
29
+
24
30
  # principle_id names the principle whose full audit is asked for; its map is refused unless it can be audited.
25
31
  #: (Models::Project, tool: RunningTool, principle_id: String) -> void
26
32
  def initialize(project, tool:, principle_id:)
@@ -40,21 +46,21 @@ module Principles
40
46
  def printed
41
47
  request = asked
42
48
  part_bytes = request_parts(request).part_bytes
43
- audit_result.request(with_record_notice(audit_result.assessment_request(request, part_bytes:)))
44
- .merge("wrote" => [])
49
+ noticed = handed(LastRecordNoticeBeside, principle_id: @id, base: @base)
50
+ audit_result.request(noticed.beside(audit_result.assessment_request(request, part_bytes:))).merge("wrote" => [])
45
51
  end
46
52
 
47
53
  # The answer alone, as start-audit --as template prints it, to fill and submit under the request's id.
48
54
  #: () -> Hash[String, untyped]
49
55
  def to_fill
50
- audit_result.answer_to_fill(asked)
56
+ audit_result.answer_to_fill(asked(scanned: false))
51
57
  end
52
58
 
53
59
  # The instruction field this request prints, read on its own and whole, with the paragraphs for cases the
54
60
  # request does not hold; refused when it prints none by that name.
55
61
  #: (String) -> Hash[String, untyped]
56
62
  def instruction(field)
57
- request = asked
63
+ request = asked(scanned: false)
58
64
  named = Models::InstructionNamed.new(field, principle_id: @id, printed: request.instruction_fields).field
59
65
  { "request_id" => request.request_id, named => request.whole_instruction(named), "wrote" => [] }
60
66
  end
@@ -65,7 +71,7 @@ module Principles
65
71
  # save as it stands; refused when the request has no part by one of the names.
66
72
  #: (Array[String]) -> Hash[String, untyped]
67
73
  def part(names)
68
- request = asked
74
+ request = asked(scanned: names.intersect?(SCANNED))
69
75
  parts = request_parts(request)
70
76
  named = names.map { named_in(parts, it) }
71
77
  return parts.shown(Views::ContextParts::TEMPLATE) if named == [Views::ContextParts::TEMPLATE]
@@ -78,7 +84,7 @@ module Principles
78
84
  # order given, printed together under the request's id; refused when the template has no slot by one name.
79
85
  #: (Array[String]) -> Hash[String, untyped]
80
86
  def slot_to_fill(names)
81
- request = asked
87
+ request = asked(scanned: false)
82
88
  slots = request.slots_to_fill
83
89
  named = names.map { Models::PartNamed.new(it, principle_id: @id, printed: slots.keys, template: true).part }
84
90
  { "request_id" => request.request_id, "member_assessments" => named.map { slots.fetch(it) }, "wrote" => [] }
@@ -86,9 +92,16 @@ module Principles
86
92
 
87
93
  private
88
94
 
89
- # The parts of request that --part prints, each member's with its text now.
95
+ # The parts of request that --part prints, each member's with its text now, or with that text in a part of its
96
+ # own where MemberTexts says.
90
97
  #: (Views::AssessmentRequest) -> Views::ContextParts
91
- def request_parts(request) = request.context_parts(texts: member_texts, optional: PartsToRead::OPTIONAL)
98
+ def request_parts(request)
99
+ read = Models::MemberTexts.new(@project, @audit.map, listed: @listing.members)
100
+ apart = Views::ContextParts::TextsApart.new(read.apart_ids, invocation, principle_id: @id,
101
+ read_whole: read.read_whole)
102
+ texts = Views::ContextParts::MemberTexts.new(read.lines, apart:)
103
+ request.context_parts(texts:, optional: PartsToRead::OPTIONAL)
104
+ end
92
105
 
93
106
  # The part name names in parts, refused when the request neither prints it nor leaves it out as empty.
94
107
  #: (Views::ContextParts, String) -> String
@@ -106,17 +119,24 @@ module Principles
106
119
 
107
120
  # The request and what it asks, listing the findings the last completed audit left to decide, under an id that
108
121
  # digests them and the revision of that audit's record, but not the findings other principles leave
109
- # open on members sharing these lines.
110
- #: () -> Views::AssessmentRequest
111
- def asked
122
+ # open on members sharing these lines. Unless scanned, its logged_requests part holds nothing, for a read that
123
+ # prints none of it, since scanning the captured requests is slow.
124
+ #: (?scanned: bool) -> Views::AssessmentRequest
125
+ def asked(scanned: true)
112
126
  record = @audit_records.find(@id)
113
127
  prior = @audit.prior_findings(record)
114
128
  loads = loads_to_check(@audit).listed
115
- basis = Models::AssessmentBasis.printed(@base, record)
116
- head = Views::AnswerHead.new(request_id: @audit.assessment_id(basis, prior.digested, loads).to_s,
117
- basis: basis.to_h)
118
- request_to_assess(head, handed(PartsToRead, audit: @audit, listing: @listing,
119
- audited_files: audited_files(@audit.map)).listed(prior, loads))
129
+ request_to_assess(answer_head(record, prior, loads),
130
+ handed(PartsToRead, audit: @audit, listing: @listing,
131
+ audited_files: audited_files(@audit.map)).listed(prior, loads, scanned:))
132
+ end
133
+
134
+ # The head of the answer: the request's id, digesting prior, the findings the last completed audit left to
135
+ # decide, and loads, what the request lists to check against the activation, with the basis it was printed on.
136
+ #: (Models::AuditRecord?, Models::PriorFindings, Hash[String, untyped]?) -> Views::AnswerHead
137
+ def answer_head(record, prior, loads)
138
+ basis = audited_basis(Models::AssessmentBasis.printed(@base, record), @audit.map)
139
+ Views::AnswerHead.new(request_id: @audit.assessment_id(basis, prior.digested, loads).to_s, basis: basis.to_h)
120
140
  end
121
141
 
122
142
  # What the agent assesses: the members, with what else it reads beside them.
@@ -140,37 +160,13 @@ module Principles
140
160
  Views::AssessedMembers.new(@listing.members,
141
161
  reviewed_check_placeholders: Models::ReportedCheck::PLACEHOLDERS.to_h,
142
162
  unchanged_check_placeholders: Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h,
143
- assessment_placeholder: Models::MemberAssessments::NAMED_PLACEHOLDER)
144
- end
145
-
146
- # Each member's lines now, by id, without their line endings, so its part carries the text it is judged on.
147
- #: () -> Hash[String, Array[String]]
148
- def member_texts
149
- @audit.map.members.to_h { [it.id, @project.member_file(it.path).lines_of(it.locator).map(&:chomp)] }
163
+ assessment_placeholder: Models::MemberAssessments::NAMED_PLACEHOLDER,
164
+ carrier_checks: carrier_checks(@audit.map))
150
165
  end
151
166
 
152
167
  # The map's file and every member's file, which the base commit is judged over.
153
168
  #: (Models::Principle) -> Array[String]
154
169
  def audited_files(map) = @principles.audited_files(@id, map.members)
155
-
156
- # The request, with a notice when the last audit's record was left uncommitted: a completed one to commit, or an
157
- # open one, which its correction completes, never to commit.
158
- #: (Hash[String, untyped]) -> Hash[String, untyped]
159
- def with_record_notice(output)
160
- return output unless @base && uncommitted_record?
161
-
162
- file = @audit_records.file(@id)
163
- record = @audit_records.find(@id)
164
- left_open = record && !record.completed?
165
- notice = left_open ? audit_result.open_record_notice(file) : audit_result.uncommitted_record_notice(file)
166
- output.merge("notice" => notice)
167
- end
168
-
169
- # Whether the last audit's record exists but differs from the last commit, so it may be left behind.
170
- #: () -> bool
171
- def uncommitted_record?
172
- @audit_records.exist?(@id) && @history.uncommitted([@audit_records.file(@id)]).any?
173
- end
174
170
  end
175
171
  end
176
172
  end
@@ -10,41 +10,87 @@ module Principles
10
10
  # Each runs one command: reads models, applies their rules and prints through a view.
11
11
  # controllers/CLAUDE.md owns the boundary.
12
12
  module Controllers
13
- # The reads that show what a project has mapped: its principles, and each member and how fresh it is against the
14
- # last audit. None changes anything on disk. Survey runs the survey of candidate files.
13
+ # show-principle: each member of one principle and how fresh it is against the last audit. It changes nothing on
14
+ # disk. PrincipleListing lists every principle, and Survey runs the survey of candidate files.
15
15
  class Inventory < Command
16
16
  #: (String, String?, Hash[String, untyped]) -> untyped
17
17
  def call(command, id, options)
18
18
  naming_the_executable do
19
19
  case command
20
- when "list-principles" then listed(options)
21
- when "show-principle" then members(required_id(id)).merge("wrote" => [])
20
+ when "show-principle" then shown(required_id(id), options).merge("wrote" => [])
22
21
  else unknown(command)
23
22
  end
24
23
  end
25
24
  end
26
25
 
27
- # Each principle id names as list-principles lists it: its description and its members by freshness, or the
28
- # refusal that kept its map from being read.
29
- #: (Array[String]) -> Array[Hash[String, untyped]]
30
- def rows(ids) = ids.map { entry(it) }
31
-
32
26
  private
33
27
 
34
- #: (String) -> untyped
35
- def members(id)
28
+ # The principle id names as show-principle prints it, or only the member --member names, refused when its map
29
+ # lacks it.
30
+ #: (String, Hash[String, untyped]) -> untyped
31
+ def shown(id, options)
32
+ member_id = options["member"]&.first
33
+ return members(id, loads: options["loads"]) unless member_id
34
+
35
+ one_member(@principles.find(id), member_id)
36
+ end
37
+
38
+ # The member of principle with member_id, where it is now, how fresh against the last audit, and the last
39
+ # judgements the last completed audit's record keeps of it: its assessment and the last acknowledgement since.
40
+ #: (Models::Principle, String) -> Hash[String, untyped]
41
+ def one_member(principle, member_id)
42
+ member = principle.member(member_id)
43
+ audit = @audit_records.find(principle.id)
44
+ now = fresh(member, audit&.members&.hashes || Models::RecordedHashes::NONE)
45
+ span = now.fetch("snapshot", {}).slice("first_line", "last_line")
46
+ read_result.one_member(principle.id, { "id" => member_id, **member, **span, **now.except("snapshot") },
47
+ *judgements(audit, Models::Member.new(member).key))
48
+ end
49
+
50
+ # The assessment the last completed audit in audit kept for the member known by key, and the last
51
+ # acknowledgement made of it since, each none when the record keeps none.
52
+ #: (Models::AuditRecord?, String) -> [Hash[String, untyped]?, Hash[String, untyped]?]
53
+ def judgements(audit, key)
54
+ completed = audit&.last_completed or return [nil, nil]
55
+ [completed.members.recorded(key)&.assessment, completed.members.acknowledgements_for(key).last]
56
+ end
57
+
58
+ # The principle id names as show-principle prints it, with when each member's file loads only when loads asks.
59
+ #: (String, loads: bool?) -> untyped
60
+ def members(id, loads:)
36
61
  principle = @principles.find(id)
37
62
  audit = @audit_records.find(id)
38
- hooks = @project.hook_commands
39
- members = shown_members(principle, audit, hooks)
40
- shown = read_result.shown(printed_principle(principle, members: members),
41
- repairs: repairs(principle, members), hook_settings_not_read: hooks.not_read,
42
- loaded_files: @project.loaded_files(principle.members, hooks).to_h)
63
+ shown = principle_shown(principle, audit, loads: loads)
43
64
  return shown unless audit
44
65
 
45
66
  shown.merge("last_audit" => audit.last_audit(map_version: principle.version))
46
67
  end
47
68
 
69
+ # The principle with each member and its repairs, and with loads also when each member's file loads, the files
70
+ # they load and the hook settings not read; without, its next_action names --loads.
71
+ #: (Models::Principle, Models::AuditRecord?, loads: bool?) -> Hash[String, untyped]
72
+ def principle_shown(principle, audit, loads:)
73
+ hooks = @project.hook_commands
74
+ members = shown_members(principle, audit, hooks)
75
+ if loads
76
+ return members_listed(principle, members, hook_settings_not_read: hooks.not_read,
77
+ loaded_files: @project.loaded_files(principle.members, hooks).to_h)
78
+ end
79
+
80
+ read_result.without_loads(members_listed(principle, members.map { it.except("loads") }), principle.id)
81
+ end
82
+
83
+ # The principle with members, their repairs and the plugin members no installed plugin gives, beside what
84
+ # show-principle --loads adds: the hook settings not read and the files the members load.
85
+ #: (Models::Principle, Array[Hash[String, untyped]], ?hook_settings_not_read: Array[Hash[String, String]],
86
+ #| ?loaded_files: Hash[String, untyped]) -> Hash[String, untyped]
87
+ def members_listed(principle, members, hook_settings_not_read: [], loaded_files: {})
88
+ unresolved = members.select { unresolved?(it) }.map { it.fetch("id") }
89
+ read_result.shown(printed_principle(principle, members: members), repairs: repairs(principle, members),
90
+ hook_settings_not_read:, loaded_files:,
91
+ unresolved:)
92
+ end
93
+
48
94
  # Each member as show-principle prints it, with its loads read once for the whole map, from hooks.
49
95
  #: (Models::Principle, Models::AuditRecord?, Models::HookCommands) -> Array[Hash[String, untyped]]
50
96
  def shown_members(principle, audit, hooks)
@@ -60,9 +106,23 @@ module Principles
60
106
  def shown_member(member, audit, loads)
61
107
  now = fresh(member, audit&.members&.hashes || Models::RecordedHashes::NONE)
62
108
  member.merge(now.fetch("snapshot", {}).slice("first_line", "last_line"), now,
63
- "loads" => loads.to_h)
109
+ "loads" => loads.to_h, **plugin_source(member, now))
64
110
  end
65
111
 
112
+ # Where a plugin member found now comes from, at the version installed now, read-only; nothing for a project
113
+ # file, or for a plugin member now says no installed plugin gives.
114
+ #: (Hash[String, untyped], Hash[String, untyped]) -> Hash[String, untyped]
115
+ def plugin_source(member, now)
116
+ return {} if unresolved?(now)
117
+
118
+ source = @project.installed_plugins.source_of(Models::Member.new(member))
119
+ source ? { "source" => source } : {}
120
+ end
121
+
122
+ # Whether a member shown is a plugin member no installed plugin gives.
123
+ #: (Hash[String, untyped]) -> bool
124
+ def unresolved?(shown) = shown.fetch("freshness") == "plugin_unresolved"
125
+
66
126
  # The moves that may repair each shown member whose reference is broken, so an audit would refuse it, by id in the
67
127
  # map's order.
68
128
  #: (Models::Principle, Array[Hash[String, untyped]]) -> Hash[String, Array[Views::MemberRepairs::Move]]
@@ -86,64 +146,10 @@ module Principles
86
146
  {}
87
147
  end
88
148
 
89
- # Where the member is now and whether it changed since the record holding hashes assessed it.
90
- #: (Hash[String, untyped], Models::RecordedHashes) -> Hash[String, untyped]
91
- def fresh(member, hashes)
92
- found = Models::Member.new(member)
93
- @project.freshness(found.locator) { |sha| hashes.freshness(found.key, sha) }
94
- end
95
-
96
149
  #: () -> Views::PrincipleReadResult
97
150
  def read_result
98
151
  Views::PrincipleReadResult.new(invocation)
99
152
  end
100
-
101
- # list-principles as options ask: each id on a line with --lines, else the rows as JSON.
102
- #: (Hash[String, untyped]) -> untyped
103
- def listed(options)
104
- return read_result.ids(@principles.ids) if options["lines"]
105
-
106
- listing(open_findings: options["open_findings"]).merge("wrote" => [])
107
- end
108
-
109
- # Its next_action offers an audit while one principle's audits do not wait on an upgrade; a map listed with its
110
- # refusal counts, since repairing it leaves it to audit. With open_findings, each row lists its open findings.
111
- #: (open_findings: bool?) -> untyped
112
- def listing(open_findings:)
113
- ids = @principles.ids
114
- waiting = ids.filter_map { waiting_on_an_upgrade(it) }
115
- listed = open_findings ? read_result.with_open_findings(rows(ids), open_by_principle(ids)) : rows(ids)
116
- read_result.listing(listed, waiting: waiting, one_to_audit: waiting.size < ids.size)
117
- end
118
-
119
- # Each principle's open findings, from every record this copy can read, as list-open-findings reads them,
120
- # aged until now, by principle id.
121
- #: (Array[String]) -> Hash[String, Array[Hash[String, untyped]]]
122
- def open_by_principle(ids)
123
- now = Time.now.utc
124
- @audit_records.readable_of(ids).flat_map(&:left_open).map { it.waited_at(now) }
125
- .group_by { it.fetch("principle") }
126
- end
127
-
128
- # One map's row; a map this tool cannot read is listed with its refusal, so the others still show, and one
129
- # whose record a later copy wrote says its audits wait on an upgrade, as show-audit does.
130
- #: (String) -> Hash[String, untyped]
131
- def entry(id)
132
- map = @principles.find(id)
133
- row = map.description_with_id.merge("members_by_freshness" => members_by_freshness(map))
134
- row = row.merge(read_result.no_members(@principles.file(id))) if map.unstarted?
135
- row.merge(waiting_on_an_upgrade(id)&.marker || {})
136
- rescue Error => e
137
- { "id" => id, "refusal" => e.payload }
138
- end
139
-
140
- # How many of map's members are in each freshness state, against its principle's last audit, or the hashes a
141
- # record a later copy wrote holds, read-only, when this copy cannot read the rest of it.
142
- #: (Models::Principle) -> Hash[String, Integer]
143
- def members_by_freshness(map)
144
- hashes = @audit_records.hashes_to_compare(map.id)
145
- map.members_shown.map { |member| fresh(member, hashes).fetch("freshness") }.tally.sort.to_h
146
- end
147
153
  end
148
154
  end
149
155
  end
@@ -0,0 +1,51 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../views/last_record_notice"
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
+ # The notice a full audit's request prints when the last audit's record of its principle was left uncommitted,
12
+ # which FullAuditRequest hands over: a completed one to commit, or an open one, which its correction completes,
13
+ # never to commit; and, when the open record keeps its correction, how to resume it.
14
+ class LastRecordNoticeBeside < Command
15
+ # principle_id names the principle audited; base is the commit its audit is based on, nil outside git.
16
+ #: (Models::Project, tool: RunningTool, principle_id: String, base: String?) -> void
17
+ def initialize(project, tool:, principle_id:, base:)
18
+ super(project, tool: tool)
19
+ @id = principle_id
20
+ @base = base
21
+ end
22
+
23
+ # output, with the notice when there is one, committed or not, in git or outside.
24
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
25
+ def beside(output)
26
+ record = @audit_records.find(@id)
27
+ notices = Views::LastRecordNotice.new(invocation)
28
+ resume = (notices.resume(@id) if record&.correction)
29
+ notice = [uncommitted_record_notice(record, notices), resume].compact.join(" ")
30
+ notice.empty? ? output : output.merge("notice" => notice)
31
+ end
32
+
33
+ private
34
+
35
+ # What notices says of record when, in git, its file differs from the last commit, or nil when it does not.
36
+ #: (Models::AuditRecord?, Views::LastRecordNotice) -> String?
37
+ def uncommitted_record_notice(record, notices)
38
+ return unless @base && uncommitted_record?
39
+
40
+ file = @audit_records.file(@id)
41
+ record&.open? ? notices.open(file) : notices.uncommitted(file)
42
+ end
43
+
44
+ # Whether the last audit's record exists but differs from the last commit, so it may be left behind.
45
+ #: () -> bool
46
+ def uncommitted_record?
47
+ @audit_records.exist?(@id) && @history.uncommitted([@audit_records.file(@id)]).any?
48
+ end
49
+ end
50
+ end
51
+ end