principles 0.0.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +10 -2
  3. data/lib/principles/command_line.rb +46 -35
  4. data/lib/principles/command_routes.rb +4 -3
  5. data/lib/principles/controllers/acknowledgement.rb +84 -18
  6. data/lib/principles/controllers/answer.rb +56 -125
  7. data/lib/principles/controllers/answer_phase.rb +54 -0
  8. data/lib/principles/controllers/assessment.rb +132 -0
  9. data/lib/principles/controllers/audit.rb +45 -140
  10. data/lib/principles/controllers/audit_completion.rb +8 -8
  11. data/lib/principles/controllers/command.rb +29 -14
  12. data/lib/principles/controllers/correction.rb +23 -13
  13. data/lib/principles/controllers/full_audit_request.rb +190 -0
  14. data/lib/principles/controllers/inventory.rb +46 -79
  15. data/lib/principles/controllers/mapping.rb +3 -3
  16. data/lib/principles/controllers/member_entries.rb +24 -12
  17. data/lib/principles/controllers/member_problems_report.rb +79 -0
  18. data/lib/principles/controllers/members_a_commit_changed.rb +12 -3
  19. data/lib/principles/controllers/members_to_assess.rb +35 -20
  20. data/lib/principles/controllers/meta_principle_setup.rb +5 -5
  21. data/lib/principles/controllers/repoint.rb +19 -23
  22. data/lib/principles/controllers/running_tool.rb +1 -1
  23. data/lib/principles/data/audit_files.rb +11 -7
  24. data/lib/principles/data/bounded_file.rb +20 -4
  25. data/lib/principles/data/command-steps.json +14 -13
  26. data/lib/principles/data/map_files.rb +2 -2
  27. data/lib/principles/data/principles_subfolder.rb +8 -1
  28. data/lib/principles/data/project_files.rb +12 -15
  29. data/lib/principles/data/project_root.rb +48 -0
  30. data/lib/principles/data/schema_check.rb +39 -11
  31. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
  32. data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
  33. data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
  34. data/lib/principles/data/schemas/audit-record.schema.json +13 -1
  35. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  36. data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
  37. data/lib/principles/invocation_options.rb +1 -1
  38. data/lib/principles/models/acknowledgement.rb +73 -84
  39. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  40. data/lib/principles/models/answer_place.rb +4 -0
  41. data/lib/principles/models/assessment_answer.rb +19 -17
  42. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  43. data/lib/principles/models/audit.rb +24 -15
  44. data/lib/principles/models/audit_record.rb +19 -20
  45. data/lib/principles/models/audit_records.rb +77 -4
  46. data/lib/principles/models/audit_start.rb +3 -3
  47. data/lib/principles/models/candidate_files.rb +30 -7
  48. data/lib/principles/models/candidate_inventory.rb +23 -6
  49. data/lib/principles/models/candidate_listing.rb +12 -3
  50. data/lib/principles/models/candidate_outline.rb +195 -0
  51. data/lib/principles/models/carried_assessments.rb +1 -1
  52. data/lib/principles/models/carried_member.rb +42 -0
  53. data/lib/principles/models/check_since_last_audit.rb +22 -9
  54. data/lib/principles/models/command_steps.rb +17 -1
  55. data/lib/principles/models/correction_basis.rb +1 -1
  56. data/lib/principles/models/decided_prior_findings.rb +9 -19
  57. data/lib/principles/models/declared_map_changes.rb +13 -12
  58. data/lib/principles/models/disposition.rb +28 -24
  59. data/lib/principles/models/evidence_replacements.rb +8 -1
  60. data/lib/principles/models/fix_only_fields.rb +67 -0
  61. data/lib/principles/models/frontmatter_fields.rb +9 -8
  62. data/lib/principles/models/instruction_named.rb +35 -0
  63. data/lib/principles/models/kept_prior_finding.rb +12 -7
  64. data/lib/principles/models/left_as_printed.rb +39 -0
  65. data/lib/principles/models/loaded_files.rb +5 -3
  66. data/lib/principles/models/loading_decision.rb +9 -2
  67. data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
  68. data/lib/principles/models/member.rb +1 -1
  69. data/lib/principles/models/member_assessments.rb +32 -9
  70. data/lib/principles/models/member_file.rb +35 -11
  71. data/lib/principles/models/member_grounds.rb +2 -2
  72. data/lib/principles/models/member_hashes_as_written.rb +44 -0
  73. data/lib/principles/models/member_lines.rb +63 -15
  74. data/lib/principles/models/member_moves.rb +3 -3
  75. data/lib/principles/models/member_problems.rb +50 -24
  76. data/lib/principles/models/member_repair_moves.rb +54 -0
  77. data/lib/principles/models/members_sharing_lines.rb +3 -3
  78. data/lib/principles/models/missing_files.rb +2 -2
  79. data/lib/principles/models/new_findings.rb +55 -0
  80. data/lib/principles/models/open_finding.rb +23 -13
  81. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  82. data/lib/principles/models/other_principles.rb +1 -1
  83. data/lib/principles/models/other_templates_placeholders.rb +113 -0
  84. data/lib/principles/models/outline_budget.rb +127 -0
  85. data/lib/principles/models/outline_group.rb +31 -0
  86. data/lib/principles/models/outline_section.rb +56 -0
  87. data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
  88. data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
  89. data/lib/principles/models/{map_members.rb → principle_members.rb} +15 -4
  90. data/lib/principles/models/prior_decision_fields.rb +47 -0
  91. data/lib/principles/models/prior_finding_decision.rb +38 -7
  92. data/lib/principles/models/prior_finding_outcomes.rb +10 -3
  93. data/lib/principles/models/prior_findings.rb +1 -1
  94. data/lib/principles/models/problem_report.rb +7 -3
  95. data/lib/principles/models/project.rb +22 -17
  96. data/lib/principles/models/project_history.rb +2 -2
  97. data/lib/principles/models/quoted_change.rb +137 -0
  98. data/lib/principles/models/recent_decision.rb +90 -0
  99. data/lib/principles/models/record_format.rb +109 -0
  100. data/lib/principles/models/recorded_entry.rb +6 -0
  101. data/lib/principles/models/recorded_finding.rb +4 -0
  102. data/lib/principles/models/recorded_hashes.rb +43 -0
  103. data/lib/principles/models/recorded_members.rb +33 -16
  104. data/lib/principles/models/refusal_before_shape.rb +21 -0
  105. data/lib/principles/models/repoint.rb +13 -0
  106. data/lib/principles/models/reported_check.rb +66 -24
  107. data/lib/principles/models/request_id.rb +24 -4
  108. data/lib/principles/models/sent_answer.rb +51 -0
  109. data/lib/principles/models/sent_prior_decisions.rb +31 -0
  110. data/lib/principles/models/shape_problems_beside.rb +40 -0
  111. data/lib/principles/models/still_holds_restatement.rb +7 -10
  112. data/lib/principles/models/submitted_answer.rb +34 -0
  113. data/lib/principles/models/template_placeholders.rb +71 -0
  114. data/lib/principles/models/text_within.rb +55 -0
  115. data/lib/principles/models/unchecked_members.rb +76 -0
  116. data/lib/principles/models/write_up_opening.rb +21 -4
  117. data/lib/principles/session_start_options.rb +29 -0
  118. data/lib/principles/start_audit_options.rb +52 -0
  119. data/lib/principles/version.rb +2 -2
  120. data/lib/principles/views/acknowledgement_result.rb +15 -7
  121. data/lib/principles/views/answer_head.rb +29 -0
  122. data/lib/principles/views/assessed_members.rb +129 -0
  123. data/lib/principles/views/assessment_request.rb +139 -78
  124. data/lib/principles/views/audit_result.rb +55 -42
  125. data/lib/principles/views/candidate_files_result.rb +41 -19
  126. data/lib/principles/views/check_notes.rb +44 -0
  127. data/lib/principles/views/check_result_template.rb +42 -30
  128. data/lib/principles/views/correction_request.rb +64 -0
  129. data/lib/principles/views/first_audit.rb +71 -0
  130. data/lib/principles/views/help.rb +3 -2
  131. data/lib/principles/views/instruction.rb +74 -0
  132. data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
  133. data/lib/principles/views/loads_to_check_result.rb +13 -6
  134. data/lib/principles/views/map_added_to.rb +31 -0
  135. data/lib/principles/views/map_result.rb +38 -23
  136. data/lib/principles/views/member_change_since_baseline.rb +22 -5
  137. data/lib/principles/views/member_repairs.rb +21 -52
  138. data/lib/principles/views/members_a_commit_changed.rb +40 -10
  139. data/lib/principles/views/meta_principle_result.rb +3 -14
  140. data/lib/principles/views/one_member_check_result_template.rb +43 -0
  141. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  142. data/lib/principles/views/open_findings_line.rb +77 -23
  143. data/lib/principles/views/principle_read_result.rb +37 -28
  144. data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
  145. data/lib/principles/views/prior_findings_result.rb +30 -18
  146. data/lib/principles/views/problem_lines.rb +14 -11
  147. data/lib/principles/views/problem_result.rb +30 -16
  148. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  149. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  150. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
  151. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  152. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  153. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +6 -17
  154. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
  155. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  156. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  157. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  158. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  159. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  160. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  161. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  162. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
  163. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  164. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -4
  165. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  166. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  167. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
  168. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  169. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  170. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  171. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
  172. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
  173. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +21 -6
  174. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +25 -23
  175. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +18 -16
  176. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +4 -2
  177. data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
  178. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +7 -1
  179. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
  180. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +7 -6
  181. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
  182. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +30 -30
  183. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +39 -39
  184. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
  185. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  186. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
  187. data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
  188. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  189. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  190. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +11 -7
  191. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  192. data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
  193. data/lib/principles/views/request_part.rb +26 -6
  194. data/lib/principles/views/request_parts.rb +8 -0
  195. metadata +69 -9
  196. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  197. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -0,0 +1,190 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/audit"
6
+ require_relative "../models/evidence_lines_since"
7
+ require_relative "../models/instruction_named"
8
+ require_relative "../models/loading_decision"
9
+ require_relative "../models/meta_principle"
10
+ require_relative "../models/other_principles"
11
+ require_relative "../models/prior_decision_fields"
12
+ require_relative "../models/recent_decision"
13
+ require_relative "../models/reported_check"
14
+ require_relative "../models/uncommitted_outside_the_map"
15
+ require_relative "../views/assessment_request"
16
+ require_relative "../views/loads_to_check_result"
17
+ require_relative "../views/open_findings_elsewhere_result"
18
+ require_relative "../views/other_principles_unjudged_result"
19
+ require_relative "../views/outside_the_map_result"
20
+ require_relative "../views/package_since_last_audit_result"
21
+ require_relative "../views/prior_findings_result"
22
+ require_relative "members_to_assess"
23
+
24
+ module Principles
25
+ # Each runs one command: reads models, applies their rules and prints through a view.
26
+ # controllers/CLAUDE.md owns the boundary.
27
+ module Controllers
28
+ # The request a full audit of one principle asks as the project stands, which Audit hands over for start-audit:
29
+ # the commit it is based on, its id and what it asks. Starting writes nothing: the request id is a digest of what
30
+ # the request depends on, so Answer checks the answer against the project as it is then (D25).
31
+ class FullAuditRequest < Command
32
+ # principle_id names the principle whose full audit is asked for; its map is refused unless it can be audited.
33
+ #: (Models::Project, tool: RunningTool, principle_id: String) -> void
34
+ def initialize(project, tool:, principle_id:)
35
+ super(project, tool: tool)
36
+ @id = principle_id
37
+ map = @principles.auditable(principle_id)
38
+ @base = @history.base_commit(principle_id, audited_files(map)) #: String?
39
+ current = @project.snapshots(map)
40
+ @audit = Models::Audit.new(map: map, now: current.hashes) #: Models::Audit
41
+ listing = handed(MembersToAssess, principle_id: principle_id).listed(@audit, current)
42
+ @listing = listing #: MembersToAssess::Listing
43
+ end
44
+
45
+ # The request as start-audit prints it, with a notice when the last audit's record was left uncommitted.
46
+ #: () -> Hash[String, untyped]
47
+ def printed
48
+ audit_result.present(with_record_notice(audit_result.assessment_request(asked))).merge("wrote" => [])
49
+ end
50
+
51
+ # The answer alone, as start-audit --as template prints it, to fill and submit under the request's id (D81).
52
+ #: () -> Hash[String, untyped]
53
+ def to_fill
54
+ audit_result.answer_to_fill(asked)
55
+ end
56
+
57
+ # The instruction field this request prints, read on its own and whole, with the paragraphs for cases the
58
+ # request does not hold (D81 step 2); refused when it prints none by that name.
59
+ #: (String) -> Hash[String, untyped]
60
+ def instruction(field)
61
+ request = asked
62
+ named = Models::InstructionNamed.new(field, principle_id: @id, printed: request.instruction_fields).field
63
+ { "request_id" => request.request_id, named => request.whole_instruction(named), "wrote" => [] }
64
+ end
65
+
66
+ private
67
+
68
+ # The request and what it asks, listing the findings the last completed audit left to decide, under an id that
69
+ # digests them (D35) and the revision of that audit's record (#653), but not the findings other principles leave
70
+ # open on members sharing these lines (D62).
71
+ #: () -> Views::AssessmentRequest
72
+ def asked
73
+ record = @audit_records.find(@id)
74
+ prior = @audit.prior_findings(record)
75
+ loads = loads_to_check(@audit).listed
76
+ basis = Models::AssessmentBasis.printed(@base, record)
77
+ head = Views::AnswerHead.new(request_id: @audit.assessment_id(basis, prior.digested, loads).to_s,
78
+ basis: basis.to_h)
79
+ request_to_assess(head, parts_to_read(prior, loads))
80
+ end
81
+
82
+ # What the agent assesses: the members, with what else it reads beside them (D60).
83
+ #: (Views::AnswerHead, Array[Views::RequestPart]) -> Views::AssessmentRequest
84
+ def request_to_assess(head, parts)
85
+ Views::AssessmentRequest.new(principle: { "principle_id" => @id, "description" => @audit.map.description },
86
+ members: assessed_members, head: head,
87
+ placeholders: { "recent_decision" => Models::RecentDecision::PLACEHOLDERS.to_h,
88
+ "collective_assessment" =>
89
+ Models::AssessmentAnswer::COLLECTIVE_PLACEHOLDER,
90
+ "new_finding" => Models::NewFindings::TEMPLATE,
91
+ "left_as_printed_rule" =>
92
+ Models::AssessmentAnswer::LEFT_AS_PRINTED_RULE },
93
+ parts: parts)
94
+ end
95
+
96
+ # The members the request lists, each checked one's template printing the placeholders an answer leaves as
97
+ # printed to give none (#993).
98
+ #: () -> Views::AssessedMembers
99
+ def assessed_members
100
+ Views::AssessedMembers.new(@listing.members,
101
+ reviewed_check_placeholders: Models::ReportedCheck::PLACEHOLDERS.to_h,
102
+ unchanged_check_placeholders: Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h,
103
+ assessment_placeholder: Models::MemberAssessments::PLACEHOLDER,
104
+ sighting_placeholders: Models::MemberAssessments::SIGHTING.to_h)
105
+ end
106
+
107
+ # The part listing the members to check against the activation, each decision's template printing the
108
+ # placeholders an answer leaves as printed to give none (#994); nil when none is listed.
109
+ #: (Hash[String, untyped]?) -> Views::RequestPart?
110
+ def loads_part(loads)
111
+ Views::LoadsToCheckResult.new(invocation, loads, @id, placeholders: Models::LoadingDecision::PLACEHOLDERS.to_h)
112
+ .part
113
+ end
114
+
115
+ # What the agent reads beside the members, in order (D60): the files outside the map that differ from the
116
+ # base commit, which a check and the answer's evidence read as they are now (#409); the prior findings
117
+ # (D35); the findings other principles leave open on members sharing these lines (D62); and the members to
118
+ # check against the activation (#355); each when it lists any; and, on the meta-principle's audit, the release
119
+ # since its last audit (D68) and the other principles with members no audit has judged (D71).
120
+ #: (Models::PriorFindings, Hash[String, untyped]?) -> Array[Views::RequestPart]
121
+ def parts_to_read(prior, loads)
122
+ map = @audit.map
123
+ [outside_the_map, prior_findings_part(prior),
124
+ Views::OpenFindingsElsewhereResult.new(@listing.open_findings_elsewhere).part,
125
+ loads_part(loads), package_since_last_audit(map),
126
+ other_principles_unjudged(map)].compact
127
+ end
128
+
129
+ # The part listing each other principle with members no audit has judged as they are now, as
130
+ # list-member-problems reports them, for the principle whose audit states them; nil for any other (D71).
131
+ #: (Models::Principle) -> Views::RequestPart?
132
+ def other_principles_unjudged(map)
133
+ return unless map.keeps_others_held?
134
+
135
+ listed = Models::OtherPrinciples.of(@project, but: map.id).unjudged.map do |other, members|
136
+ Views::PrincipleWithChangedMembers.new(principle_id: other, members: members)
137
+ end
138
+ Views::OtherPrinciplesUnjudgedResult.new(listed).part
139
+ end
140
+
141
+ # The part stating the release of principles the last completed audit ran under beside the one now, and
142
+ # whether the passage changed since, for a principle whose audit keeps one; nil for any other (D68).
143
+ #: (Models::Principle) -> Views::RequestPart?
144
+ def package_since_last_audit(map)
145
+ now = @tool.release_kept_by(map) or return
146
+ last = @audit_records.find(map.id)&.last_completed&.package
147
+ Views::PackageSinceLastAuditResult.new(invocation, at_last_audit: last&.version, now: now.version,
148
+ passage_changed: last && now.passage_changed_since?(last))
149
+ .part
150
+ end
151
+
152
+ # The part listing the prior findings, in git with each evidence item saying whether its text changed since the
153
+ # commit the audit that left them open was based on, and whether it is found now (#858, #877); nil when there are
154
+ # none.
155
+ #: (Models::PriorFindings) -> Views::RequestPart?
156
+ def prior_findings_part(prior)
157
+ shown = prior.shown { |item, base| Models::EvidenceLinesSince.of(item, since: base, project: @project).facts }
158
+ Views::PriorFindingsResult.new(shown, placeholders: Models::PriorDecisionFields::TEMPLATE_PLACEHOLDERS,
159
+ last_audited_commit: prior.last_audited_commit).part
160
+ end
161
+
162
+ # The part naming the files outside the map that differ from the base commit, or nil when none do.
163
+ #: () -> Views::RequestPart?
164
+ def outside_the_map
165
+ outside = @history.uncommitted_outside(audited_files(@audit.map))
166
+ Views::OutsideTheMapResult.new(outside && Models::UncommittedOutsideTheMap.new(outside).shown).part
167
+ end
168
+
169
+ # The map's file and every member's file, which the base commit is judged over.
170
+ #: (Models::Principle) -> Array[String]
171
+ def audited_files(map)
172
+ [@principles.file(@id), *map.members.map(&:path)]
173
+ end
174
+
175
+ # The request, with a notice when the last audit's record was left uncommitted.
176
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
177
+ def with_record_notice(output)
178
+ return output unless @base && uncommitted_record?
179
+
180
+ output.merge("notice" => audit_result.uncommitted_record_notice(@audit_records.file(@id)))
181
+ end
182
+
183
+ # Whether the last audit's record exists but differs from the last commit, so it may be left behind.
184
+ #: () -> bool
185
+ def uncommitted_record?
186
+ @audit_records.exist?(@id) && @history.uncommitted([@audit_records.file(@id)]).any?
187
+ end
188
+ end
189
+ end
190
+ end
@@ -2,14 +2,10 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
- require_relative "members_a_commit_changed"
6
- require_relative "../models/member_problems"
7
5
  require_relative "../models/member_state"
8
6
  require_relative "../models/meta_principle"
9
- require_relative "../models/problem_report"
10
- require_relative "../views/problem_result"
11
- require_relative "../views/problem_lines"
12
7
  require_relative "../views/candidate_files_result"
8
+ require_relative "../views/json_with_entries_on_lines"
13
9
  require_relative "../views/principle_read_result"
14
10
 
15
11
  module Principles
@@ -20,12 +16,11 @@ module Principles
20
16
  # member and how fresh it is against the last audit. None changes anything on disk.
21
17
  class Inventory < Command
22
18
  #: (String, String?, Hash[String, untyped]) -> untyped
23
- def call(command, id, options)
19
+ def call(command, id, _options)
24
20
  naming_the_executable do
25
21
  case command
26
- when "list-candidate-files" then list_candidate_files.merge("wrote" => [])
22
+ when "list-candidate-files" then list_candidate_files
27
23
  when "list-principles" then listing.merge("wrote" => [])
28
- when "list-member-problems" then problems_printed(id, options)
29
24
  when "show-principle" then members(required_id(id)).merge("wrote" => [])
30
25
  else unknown(command)
31
26
  end
@@ -41,21 +36,28 @@ module Principles
41
36
 
42
37
  #: () -> untyped
43
38
  def list_candidate_files
44
- found = @project.candidate_files
39
+ found = @project.candidate_files.within_budget { |inventory| candidate_files_result(inventory).text.bytesize }
40
+ candidate_files_result(found)
41
+ end
42
+
43
+ # list-candidate-files' result for one inventory, as it prints.
44
+ #: (Models::CandidateInventory) -> Views::JsonWithEntriesOnLines
45
+ def candidate_files_result(found)
45
46
  listed = Views::CandidateFilesResult::Found.new(inventory: found.to_h, untracked: found.untracked,
46
47
  owner_asks: found.owner_asks)
47
- Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @member_maps.ids,
48
- map_file: @member_maps.file("ID"), set_up: set_up?)
48
+ question = Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
49
+ map_file: @principles.file("ID"))
50
+ Views::JsonWithEntriesOnLines.new(question.merge("wrote" => []), under: "inventory", key: "files")
49
51
  end
50
52
 
51
53
  #: (String) -> untyped
52
54
  def members(id)
53
- principle = @member_maps.find(id)
55
+ principle = @principles.find(id)
54
56
  audit = @audit_records.find(id)
55
57
  hooks = @project.hook_commands
56
58
  members = shown_members(principle, audit, hooks)
57
59
  shown = read_result.shown(printed_principle(principle, members: members),
58
- broken: broken_ids(members), hook_settings_not_read: hooks.not_read,
60
+ repairs: repairs(principle, members), hook_settings_not_read: hooks.not_read,
59
61
  loaded_files: @project.loaded_files(principle.members, hooks).to_h)
60
62
  return shown unless audit
61
63
 
@@ -63,7 +65,7 @@ module Principles
63
65
  end
64
66
 
65
67
  # Each member as show-principle prints it, with its loads read once for the whole map, from hooks.
66
- #: (Models::MemberMap, Models::AuditRecord?, Models::HookCommands) -> Array[Hash[String, untyped]]
68
+ #: (Models::Principle, Models::AuditRecord?, Models::HookCommands) -> Array[Hash[String, untyped]]
67
69
  def shown_members(principle, audit, hooks)
68
70
  loads = member_loads(principle, hooks)
69
71
  principle.members_shown.map do |member|
@@ -75,34 +77,37 @@ module Principles
75
77
  # The span sits beside the id too, as in add-member's and move-member's results (alpha friction).
76
78
  #: (Hash[String, untyped], Models::AuditRecord?, Models::MemberLoads) -> Hash[String, untyped]
77
79
  def shown_member(member, audit, loads)
78
- now = fresh(member, audit)
80
+ now = fresh(member, audit&.members&.hashes || Models::RecordedHashes::NONE)
79
81
  member.merge(now.fetch("snapshot", {}).slice("first_line", "last_line"), now,
80
82
  "loads" => loads.to_h)
81
83
  end
82
84
 
83
- # The id of each shown member whose reference is broken, so an audit would refuse it, in the map's order.
84
- #: (Array[Hash[String, untyped]]) -> Array[String]
85
- def broken_ids(members)
85
+ # The moves that may repair each shown member whose reference is broken, so an audit would refuse it, by id in the
86
+ # map's order.
87
+ #: (Models::Principle, Array[Hash[String, untyped]]) -> Hash[String, Array[Hash[String, untyped]]]
88
+ def repairs(principle, members)
86
89
  members.select { |member| Models::MemberState.new(member.fetch("id"), member.fetch("freshness")).broken? }
87
- .map { |member| member.fetch("id") }
90
+ .to_h do |member|
91
+ id = member.fetch("id")
92
+ [id, Models::MemberRepairMoves.new(principle.member(id), code: member.dig("error", "code")).to_a]
93
+ end
88
94
  end
89
95
 
90
96
  # The members sharing a line with this one, in its map and in others, as add-member names them, so a member
91
97
  # whose lines others hold too does not look as if its member_bytes were its alone (#541). A member this tool
92
98
  # cannot find now shares nothing it can name.
93
- #: (Hash[String, untyped], map: Models::MemberMap) -> Hash[String, untyped]
99
+ #: (Hash[String, untyped], map: Models::Principle) -> Hash[String, untyped]
94
100
  def shared(member, map:)
95
101
  lines_shared(Models::Member.new(member), map).to_h
96
102
  rescue Error
97
103
  {}
98
104
  end
99
105
 
100
- # Where the member is now and whether it changed since the last audit assessed it.
101
- #: (Hash[String, untyped], Models::AuditRecord?) -> Hash[String, untyped]
102
- def fresh(member, audit)
103
- @project.freshness(Models::Member.new(member).locator) do |sha|
104
- audit ? audit.members.freshness(Models::Member.new(member).key, sha) : "unassessed"
105
- end
106
+ # Where the member is now and whether it changed since the record holding hashes assessed it.
107
+ #: (Hash[String, untyped], Models::RecordedHashes) -> Hash[String, untyped]
108
+ def fresh(member, hashes)
109
+ found = Models::Member.new(member)
110
+ @project.freshness(found.locator) { |sha| hashes.freshness(found.key, sha) }
106
111
  end
107
112
 
108
113
  #: () -> Views::PrincipleReadResult
@@ -110,71 +115,33 @@ module Principles
110
115
  Views::PrincipleReadResult.new(invocation)
111
116
  end
112
117
 
118
+ # Its next_action offers an audit while one principle's audits do not wait on an upgrade; a map listed with its
119
+ # refusal counts, since repairing it leaves it to audit (#1067).
113
120
  #: () -> untyped
114
121
  def listing
115
- read_result.listing(rows(@member_maps.ids), set_up: set_up?)
116
- end
117
-
118
- # Whether principles is set up, as MemberMaps decides it (D68, D75).
119
- #: () -> bool
120
- def set_up? = @member_maps.set_up?
121
-
122
- # list-member-problems' JSON result, or with --short its lines for a trigger (#291), or with --hook-event the
123
- # after-commit hook's JSON, which MembersACommitChanged prints (D73).
124
- #: (String?, Hash[String, untyped]) -> untyped
125
- def problems_printed(id, options)
126
- if (event = options["hook_event"])
127
- return handed(MembersACommitChanged, report: -> { checked_report(id) })
128
- .printed(after: options.fetch("commits_after"), event: event)
129
- end
130
-
131
- problems = Models::ProblemReport.new(problems_of(id), history: @history)
132
- report = member_problems(problems)
133
- return report.merge("wrote" => []) unless options["short"]
134
-
135
- Views::ProblemLines.new(invocation).short(report, nothing_changed: Views::ProblemResult::NOTHING_CHANGED,
136
- assessed_change: problems.assessed_change?)
137
- end
138
-
139
- # list-member-problems' JSON result for map id, or every map, without the files it wrote.
140
- #: (String?) -> Hash[String, untyped]
141
- def checked_report(id) = member_problems(Models::ProblemReport.new(problems_of(id), history: @history))
142
-
143
- # The result for problems, every member of map id or of every map that is broken or whose own text changed
144
- # (#187).
145
- #: (Models::ProblemReport) -> untyped
146
- def member_problems(problems)
147
- report = problems.checked do |map_id, member, baseline, now|
148
- map_history(map_id).member_history(member, baseline: baseline, now: now)
149
- end
150
- Views::ProblemResult.new(invocation).checked(report, not_read: @project.unread_older_files,
151
- no_baseline_files: problems.files_to_commit(@member_maps),
152
- acknowledgeable: problems.acknowledgeable)
153
- end
154
-
155
- # Map id's members against their baselines, or every map's, listing a map it cannot read among them.
156
- #: (String?) -> Array[Models::MemberProblems]
157
- def problems_of(id)
158
- return [Models::MemberProblems.for(@project, id)] if id
159
-
160
- @member_maps.ids.map { Models::MemberProblems.for(@project, it, listing_all: true) }
122
+ ids = @principles.ids
123
+ waiting = ids.filter_map { waiting_on_an_upgrade(it) }
124
+ read_result.listing(rows(ids), waiting: waiting, one_to_audit: waiting.size < ids.size)
161
125
  end
162
126
 
163
- # One map's row; a map this tool cannot read is listed with its refusal, so the others still show (D29).
127
+ # One map's row; a map this tool cannot read is listed with its refusal, so the others still show (D29), and one
128
+ # whose record a later copy wrote says its audits wait on an upgrade, as show-audit does (#1067).
164
129
  #: (String) -> Hash[String, untyped]
165
130
  def entry(id)
166
- map = @member_maps.find(id)
131
+ map = @principles.find(id)
167
132
  row = { "id" => id, "description" => map.description, "members_by_freshness" => members_by_freshness(map) }
168
- map.unstarted? ? row.merge(read_result.no_members(@member_maps.file(id))) : row
133
+ row = row.merge(read_result.no_members(@principles.file(id))) if map.unstarted?
134
+ row.merge(waiting_on_an_upgrade(id)&.marker || {})
169
135
  rescue Error => e
170
136
  { "id" => id, "refusal" => e.payload }
171
137
  end
172
138
 
173
- # How many of map's members are in each freshness state, against its principle's last audit.
174
- #: (Models::MemberMap) -> Hash[String, Integer]
139
+ # How many of map's members are in each freshness state, against its principle's last audit, or the hashes a
140
+ # record a later copy wrote holds, read-only, when this copy cannot read the rest of it (#1067).
141
+ #: (Models::Principle) -> Hash[String, Integer]
175
142
  def members_by_freshness(map)
176
- audit = @audit_records.find(map.id)
177
- map.members_shown.map { |member| fresh(member, audit).fetch("freshness") }.tally.sort.to_h
143
+ hashes = @audit_records.hashes_to_compare(map.id)
144
+ map.members_shown.map { |member| fresh(member, hashes).fetch("freshness") }.tally.sort.to_h
178
145
  end
179
146
  end
180
147
  end
@@ -30,13 +30,13 @@ module Principles
30
30
 
31
31
  #: (String, Hash[String, untyped]) -> untyped
32
32
  def create_principle(id, options)
33
- map = @member_maps.create(id) { text(options["description"], "--description") }
33
+ map = @principles.create(id) { text(options["description"], "--description") }
34
34
  write_map(map) { |printed| map_result.created(printed) }
35
35
  end
36
36
 
37
37
  #: (String, Hash[String, untyped]) -> untyped
38
38
  def change_description(id, options)
39
- map = @member_maps.find(id).describing(text(options["description"], "--description"))
39
+ map = @principles.find(id).describing(text(options["description"], "--description"))
40
40
  write_map(map) { |printed| map_result.description_changed(printed) }
41
41
  end
42
42
 
@@ -45,7 +45,7 @@ module Principles
45
45
  def change_activation(id, options)
46
46
  activation = Models::Activation.declared(when_files: options["when_files"],
47
47
  when_invoked: options["when_invoked"], always: options["always"])
48
- map = @member_maps.find(id)
48
+ map = @principles.find(id)
49
49
  activated = map.activating(activation)
50
50
  return map_result.activation_unchanged(printed_principle(map)).merge("wrote" => []) if activated.same_as?(map)
51
51
 
@@ -45,22 +45,34 @@ module Principles
45
45
 
46
46
  #: (String, Hash[String, untyped]) -> untyped
47
47
  def add_member(id, options)
48
- started = !@member_maps.mapped?(id)
49
- map = @member_maps.addable(id)
48
+ started = !@principles.mapped?(id)
49
+ map = @principles.addable(id)
50
50
  member = located(options, { "path" => text(options["path"], "PATH") }).merge(played(options))
51
+ facts = joined(map)
51
52
  write_map(map.adding(member)) do |printed|
52
- added = member_added(printed, map, member)
53
+ added = member_added(printed, map, member, facts)
53
54
  started ? added.merge(map_result.map_created(printed)) : added
54
55
  end
55
56
  end
56
57
 
57
58
  # What add-member reports of the member it added to map: its id, lines and check, and the members, in
58
- # this map or another, that share a line with it, so the agent sees an edit there shows on each (#383).
59
- #: (Views::PrintedPrinciple, Models::MemberMap, Hash[String, untyped]) -> Hash[String, untyped]
60
- def member_added(printed, map, member)
59
+ # this map or another, that share a line with it, so the agent sees an edit there shows on each (#383), and,
60
+ # when a correction may be open on map, how a fix claims the member (D72, #1023).
61
+ #: (Views::PrintedPrinciple, Models::Principle, Hash[String, untyped], Views::MapAddedTo) -> Hash[String, untyped]
62
+ def member_added(printed, map, member, joined)
61
63
  added = Models::Member.new(member)
62
64
  map_result.member_added(printed, added: span(member).merge(member.slice("check")),
63
- shared: lines_shared(added, map))
65
+ shared: lines_shared(added, map), joined: joined)
66
+ end
67
+
68
+ # What add-member says of map, read before the member joins it and the map is saved, so the history can say
69
+ # whether this is the first add-member since the map was last committed (#1025).
70
+ #: (Models::Principle) -> Views::MapAddedTo
71
+ def joined(map)
72
+ history = principle_history(map.id)
73
+ Views::MapAddedTo.new(keeps_others_held: map.keeps_others_held?,
74
+ correction_may_be_open: history.startable_at_head?,
75
+ reminded: history.first_add_since_commit?(map))
64
76
  end
65
77
 
66
78
  # The part a new member plays, and the check that enforces it when one is named (D30).
@@ -82,7 +94,7 @@ module Principles
82
94
  # its audit (#268).
83
95
  #: (String, Hash[String, untyped]) -> untyped
84
96
  def move_member(id, options)
85
- map = @member_maps.find(id)
97
+ map = @principles.find(id)
86
98
  old = map.member(text(options["member"], "MEMBER"))
87
99
  member = located(options, { "path" => new_path(options, old) })
88
100
  moved = span(member)
@@ -99,7 +111,7 @@ module Principles
99
111
 
100
112
  #: (String, Hash[String, untyped]) -> untyped
101
113
  def change_member_role(id, options)
102
- map = @member_maps.find(id)
114
+ map = @principles.find(id)
103
115
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
104
116
  write_map(map.changing_role(target, text(options["role"], "--role"))) do |printed|
105
117
  map_result.member_replaced(printed, member: target, done: "Changed the role of #{target}.")
@@ -109,7 +121,7 @@ module Principles
109
121
  # Names the command that enforces a member, which the audit asks the agent to run (D30).
110
122
  #: (String, Hash[String, untyped]) -> untyped
111
123
  def change_member_check(id, options)
112
- map = @member_maps.find(id)
124
+ map = @principles.find(id)
113
125
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
114
126
  check = text(options["check"], "--check")
115
127
  changed = map.changing_check(target, check)
@@ -119,7 +131,7 @@ module Principles
119
131
 
120
132
  #: (String, Hash[String, untyped]) -> untyped
121
133
  def remove_member_check(id, options)
122
- map = @member_maps.find(id)
134
+ map = @principles.find(id)
123
135
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
124
136
  write_map(map.removing_check(target)) do |printed|
125
137
  map_result.member_replaced(printed, member: target,
@@ -130,7 +142,7 @@ module Principles
130
142
 
131
143
  #: (String, Hash[String, untyped]) -> untyped
132
144
  def remove_member(id, options)
133
- map = @member_maps.find(id)
145
+ map = @principles.find(id)
134
146
  target = text(options["member"], "MEMBER")
135
147
  write_map(map.removing(target)) { |printed| map_result.member_removed(printed, removed: target) }
136
148
  end
@@ -0,0 +1,79 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "members_a_commit_changed"
6
+ require_relative "../models/member_problems"
7
+ require_relative "../models/problem_report"
8
+ require_relative "../views/record_waiting_on_an_upgrade"
9
+ require_relative "../views/problem_result"
10
+ require_relative "../views/problem_lines"
11
+
12
+ module Principles
13
+ # Each runs one command: reads models, applies their rules and prints through a view.
14
+ # controllers/CLAUDE.md owns the boundary.
15
+ module Controllers
16
+ # list-member-problems: each member of one map or every map checked against its baseline, printed as JSON, as
17
+ # --short's lines, or for the after-commit hook through MembersACommitChanged.
18
+ class MemberProblemsReport < Command
19
+ #: (String, String?, Hash[String, untyped]) -> untyped
20
+ def call(command, id, options)
21
+ naming_the_executable do
22
+ command == "list-member-problems" ? printed(id, options) : unknown(command)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ # list-member-problems' JSON result, or with --short its lines for a trigger (#291), or with --hook-event the
29
+ # after-commit hook's JSON, which MembersACommitChanged prints (D73).
30
+ #: (String?, Hash[String, untyped]) -> untyped
31
+ def printed(id, options)
32
+ if (event = options["hook_event"])
33
+ return handed(MembersACommitChanged, report: -> { checked_report(id) })
34
+ .printed(after: options.fetch("commits_after"), event: event)
35
+ end
36
+
37
+ problems, report = checked(id)
38
+ return report.merge("wrote" => []) unless options["short"]
39
+
40
+ Views::ProblemLines.new(invocation).short(report, nothing_changed: Views::ProblemResult::NOTHING_CHANGED,
41
+ assessed_change: problems.assessed_change?,
42
+ unassessed_change: problems.unassessed_change?)
43
+ end
44
+
45
+ # list-member-problems' JSON result for map id, or every map, without the files it wrote.
46
+ #: (String?) -> Hash[String, untyped]
47
+ def checked_report(id) = checked(id).last
48
+
49
+ # The problems of map id, or every map, and list-member-problems' JSON result for them, naming each principle
50
+ # whose record a later copy wrote as waiting on an upgrade, its members compared read-only (D85 V8, #1066).
51
+ #: (String?) -> [Models::ProblemReport, Hash[String, untyped]]
52
+ def checked(id)
53
+ waiting = (id ? [id] : @principles.ids).filter_map { waiting_on_an_upgrade(it) }
54
+ problems = Models::ProblemReport.new(problems_of(id), history: @history)
55
+ [problems, member_problems(problems, waiting)]
56
+ end
57
+
58
+ # The result for problems, every member of map id or of every map that is broken or whose own text changed
59
+ # (#187), and each principle waiting on an upgrade.
60
+ #: (Models::ProblemReport, Array[Views::RecordWaitingOnAnUpgrade]) -> untyped
61
+ def member_problems(problems, waiting)
62
+ report = problems.checked do |map_id, member, baseline, now|
63
+ principle_history(map_id).member_history(member, baseline: baseline, now: now)
64
+ end
65
+ Views::ProblemResult.new(invocation).checked(report, not_read: @project.unread_older_files,
66
+ no_baseline_files: problems.files_to_commit(@principles),
67
+ acknowledgeable: problems.acknowledgeable, waiting:)
68
+ end
69
+
70
+ # Map id's members against their baselines, or every map's, listing a map it cannot read among them.
71
+ #: (String?) -> Array[Models::MemberProblems]
72
+ def problems_of(id)
73
+ return [Models::MemberProblems.for(@project, id)] if id
74
+
75
+ @principles.ids.map { Models::MemberProblems.for(@project, it, listing_all: true) }
76
+ end
77
+ end
78
+ end
79
+ end
@@ -13,7 +13,8 @@ module Principles
13
13
  # exits 0 whatever it finds, since the host shows the user an error for any other status, and reports a refusal
14
14
  # only when those commits could have caused it, so a broken setup does not repeat at every commit (review R8).
15
15
  class MembersACommitChanged < Command
16
- # report gives list-member-problems' result for every map, as Inventory checks it, or raises its refusal.
16
+ # report gives list-member-problems' result for every map, as MemberProblemsReport checks it, or raises its
17
+ # refusal.
17
18
  #: (Models::Project, tool: RunningTool, report: ^() -> Hash[String, untyped]) -> void
18
19
  def initialize(project, tool:, report:)
19
20
  super(project, tool: tool)
@@ -27,15 +28,23 @@ module Principles
27
28
  changed = @history.commits_brought_in(after).changed_by(members)
28
29
  return Views::MembersACommitChanged::NOTHING if changed.empty?
29
30
 
30
- view.changed(event, changed, others: members.size - changed.size)
31
+ changed_lines(event, changed, others: members.size - changed.size)
31
32
  rescue Error => e
32
- return Views::MembersACommitChanged::NOTHING unless @history.touched_since?(after, @member_maps.readable_paths)
33
+ return Views::MembersACommitChanged::NOTHING unless @history.touched_since?(after, @principles.readable_paths)
33
34
 
34
35
  view.refused(event, e.payload.fetch("code"))
35
36
  end
36
37
 
37
38
  private
38
39
 
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 (D85 V8, #1066).
42
+ #: (String, Array[Hash[String, untyped]], others: Integer) -> Views::Lines
43
+ def changed_lines(event, changed, others:)
44
+ waits = changed.map { it.fetch("principle") }.uniq.filter_map { waiting_on_an_upgrade(it) }
45
+ view.changed(event, changed, others:, waits:)
46
+ end
47
+
39
48
  #: () -> Views::MembersACommitChanged
40
49
  def view = Views::MembersACommitChanged.new(invocation)
41
50
  end