principles 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/principles/cli.rb +7 -1
- data/lib/principles/command_line.rb +12 -29
- data/lib/principles/controllers/acknowledgement.rb +4 -4
- data/lib/principles/controllers/answer.rb +64 -100
- data/lib/principles/controllers/assessment.rb +108 -0
- data/lib/principles/controllers/audit.rb +29 -135
- data/lib/principles/controllers/audit_completion.rb +2 -4
- data/lib/principles/controllers/command.rb +27 -13
- data/lib/principles/controllers/correction.rb +4 -4
- data/lib/principles/controllers/full_audit_request.rb +180 -0
- data/lib/principles/controllers/inventory.rb +32 -70
- data/lib/principles/controllers/mapping.rb +3 -3
- data/lib/principles/controllers/member_entries.rb +24 -12
- data/lib/principles/controllers/member_problems_report.rb +72 -0
- data/lib/principles/controllers/members_a_commit_changed.rb +10 -2
- data/lib/principles/controllers/members_to_assess.rb +16 -9
- data/lib/principles/controllers/meta_principle_setup.rb +5 -5
- data/lib/principles/controllers/repoint.rb +1 -1
- data/lib/principles/controllers/running_tool.rb +1 -1
- data/lib/principles/data/audit_files.rb +11 -7
- data/lib/principles/data/bounded_file.rb +11 -0
- data/lib/principles/data/command-steps.json +7 -6
- data/lib/principles/data/map_files.rb +2 -2
- data/lib/principles/data/principles_subfolder.rb +8 -1
- data/lib/principles/data/project_files.rb +1 -7
- data/lib/principles/data/project_root.rb +48 -0
- data/lib/principles/data/schema_check.rb +23 -5
- data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
- data/lib/principles/data/schemas/audit-record.schema.json +3 -0
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
- data/lib/principles/invocation_options.rb +1 -1
- data/lib/principles/models/assessment_answer.rb +64 -17
- data/lib/principles/models/audit.rb +24 -15
- data/lib/principles/models/audit_record.rb +10 -3
- data/lib/principles/models/audit_records.rb +74 -4
- data/lib/principles/models/audit_start.rb +3 -3
- data/lib/principles/models/carried_assessments.rb +1 -1
- data/lib/principles/models/check_since_last_audit.rb +6 -6
- data/lib/principles/models/correction_basis.rb +1 -1
- data/lib/principles/models/decided_prior_findings.rb +9 -19
- data/lib/principles/models/declared_map_changes.rb +8 -8
- data/lib/principles/models/disposition.rb +28 -24
- data/lib/principles/models/evidence_replacements.rb +8 -1
- data/lib/principles/models/fix_only_fields.rb +67 -0
- data/lib/principles/models/kept_prior_finding.rb +12 -7
- data/lib/principles/models/loaded_files.rb +5 -3
- data/lib/principles/models/loading_decision.rb +9 -2
- data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
- data/lib/principles/models/member.rb +1 -1
- data/lib/principles/models/member_assessments.rb +48 -3
- data/lib/principles/models/member_grounds.rb +2 -2
- data/lib/principles/models/member_hashes_as_written.rb +40 -0
- data/lib/principles/models/member_moves.rb +3 -3
- data/lib/principles/models/member_problems.rb +38 -18
- data/lib/principles/models/members_sharing_lines.rb +3 -3
- data/lib/principles/models/new_findings.rb +55 -0
- data/lib/principles/models/open_finding.rb +23 -13
- data/lib/principles/models/other_principles.rb +1 -1
- data/lib/principles/models/other_templates_placeholders.rb +74 -0
- data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
- data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
- data/lib/principles/models/{map_members.rb → principle_members.rb} +4 -4
- data/lib/principles/models/prior_decision_fields.rb +46 -0
- data/lib/principles/models/prior_finding_decision.rb +24 -3
- data/lib/principles/models/prior_finding_outcomes.rb +10 -3
- data/lib/principles/models/prior_findings.rb +1 -1
- data/lib/principles/models/problem_report.rb +7 -3
- data/lib/principles/models/project.rb +27 -13
- data/lib/principles/models/project_history.rb +2 -2
- data/lib/principles/models/recent_decision.rb +90 -0
- data/lib/principles/models/record_format.rb +105 -0
- data/lib/principles/models/recorded_finding.rb +4 -0
- data/lib/principles/models/recorded_hashes.rb +39 -0
- data/lib/principles/models/recorded_members.rb +17 -12
- data/lib/principles/models/reported_check.rb +63 -11
- data/lib/principles/models/request_id.rb +24 -4
- data/lib/principles/models/sent_prior_decisions.rb +31 -0
- data/lib/principles/models/still_holds_restatement.rb +7 -10
- data/lib/principles/models/template_placeholders.rb +41 -0
- data/lib/principles/session_start_options.rb +29 -0
- data/lib/principles/start_audit_options.rb +37 -0
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/answer_head.rb +29 -0
- data/lib/principles/views/assessed_members.rb +96 -0
- data/lib/principles/views/assessment_request.rb +51 -49
- data/lib/principles/views/audit_result.rb +38 -42
- data/lib/principles/views/check_result_template.rb +31 -10
- data/lib/principles/views/correction_request.rb +64 -0
- data/lib/principles/views/first_audit.rb +71 -0
- data/lib/principles/views/help.rb +3 -2
- data/lib/principles/views/loads_to_check_result.rb +11 -4
- data/lib/principles/views/map_added_to.rb +31 -0
- data/lib/principles/views/map_result.rb +37 -22
- data/lib/principles/views/members_a_commit_changed.rb +30 -10
- data/lib/principles/views/meta_principle_result.rb +3 -14
- data/lib/principles/views/principle_read_result.rb +27 -10
- data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
- data/lib/principles/views/prior_findings_result.rb +7 -3
- data/lib/principles/views/problem_lines.rb +14 -11
- data/lib/principles/views/problem_result.rb +30 -16
- data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +3 -2
- data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
- data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
- data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +22 -20
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +8 -5
- data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +3 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +6 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +37 -37
- data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
- data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +1 -0
- data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
- data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +2 -1
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
- data/lib/principles/views/request_part.rb +14 -2
- data/lib/principles/views/request_parts.rb +4 -0
- metadata +33 -7
|
@@ -2,33 +2,20 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "command"
|
|
5
|
-
require_relative "../models/audit"
|
|
6
|
-
require_relative "../models/evidence_lines_since"
|
|
7
5
|
require_relative "../models/findings_left_open"
|
|
8
|
-
require_relative "../models/meta_principle"
|
|
9
|
-
require_relative "../models/other_principles"
|
|
10
6
|
require_relative "../models/finding_write_ups"
|
|
11
|
-
require_relative "../models/uncommitted_outside_the_map"
|
|
12
|
-
require_relative "../views/assessment_request"
|
|
13
7
|
require_relative "../views/findings_result"
|
|
14
|
-
require_relative "../views/loads_to_check_result"
|
|
15
|
-
require_relative "../views/open_findings_elsewhere_result"
|
|
16
8
|
require_relative "../views/open_findings_line"
|
|
17
|
-
require_relative "../views/other_principles_unjudged_result"
|
|
18
|
-
require_relative "../views/outside_the_map_result"
|
|
19
|
-
require_relative "../views/package_since_last_audit_result"
|
|
20
|
-
require_relative "../views/prior_findings_result"
|
|
21
9
|
require_relative "acknowledgement"
|
|
22
|
-
require_relative "
|
|
10
|
+
require_relative "full_audit_request"
|
|
23
11
|
require_relative "repoint"
|
|
24
12
|
|
|
25
13
|
module Principles
|
|
26
14
|
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
27
15
|
# controllers/CLAUDE.md owns the boundary.
|
|
28
16
|
module Controllers
|
|
29
|
-
# Starting and showing an audit: start-audit hands the agent the assessment request,
|
|
30
|
-
#
|
|
31
|
-
# depends on, so Answer checks the answer against the project as it is then (D25).
|
|
17
|
+
# Starting and showing an audit: start-audit hands the agent the assessment request, which FullAuditRequest
|
|
18
|
+
# builds for a full audit, and show-audit prints the committed record.
|
|
32
19
|
class Audit < Command
|
|
33
20
|
#: (String, String?, Hash[String, untyped]) -> untyped
|
|
34
21
|
def call(command, id, options)
|
|
@@ -46,21 +33,26 @@ module Principles
|
|
|
46
33
|
private
|
|
47
34
|
|
|
48
35
|
# The audit start-audit's options ask for: a one-member audit with --member, a repoint of the open
|
|
49
|
-
# findings' write-ups with --write-ups (D59), else a full audit.
|
|
36
|
+
# findings' write-ups with --write-ups (D59), else a full audit, its answer alone with --as template (D81).
|
|
50
37
|
#: (String, Hash[String, untyped]) -> Hash[String, untyped]
|
|
51
38
|
def started_audit(id, options)
|
|
39
|
+
naming_the_executable { @audit_records.refuse_newer(id, version: @tool.version) }
|
|
52
40
|
return acknowledge(id, options["member"]) if options["member"]
|
|
53
41
|
return handed(Repoint).start(id) if options["write_ups"]
|
|
54
42
|
|
|
55
|
-
naming_the_executable
|
|
43
|
+
naming_the_executable do
|
|
44
|
+
full = handed(FullAuditRequest, principle_id: id)
|
|
45
|
+
options["as"] ? full.to_fill : full.printed
|
|
46
|
+
end
|
|
56
47
|
end
|
|
57
48
|
|
|
58
49
|
# id's committed record. With none, an id no map has is refused as show-principle refuses it, since
|
|
59
|
-
# starting its audit would be refused too; a record kept after its map was removed still shows (#577).
|
|
50
|
+
# starting its audit would be refused too; a record kept after its map was removed still shows (#577). One a
|
|
51
|
+
# later copy wrote says its audits wait on an upgrade (D85, V8).
|
|
60
52
|
#: (String) -> Hash[String, untyped]
|
|
61
53
|
def shown_audit(id)
|
|
62
|
-
@
|
|
63
|
-
@audit_records.fetch(id).shown.merge("wrote" => [])
|
|
54
|
+
@principles.find(id) unless @audit_records.exist?(id)
|
|
55
|
+
@audit_records.fetch(id).shown.merge(waiting_beside(id), "wrote" => [])
|
|
64
56
|
end
|
|
65
57
|
|
|
66
58
|
# A one-member audit of member_id (D33).
|
|
@@ -69,11 +61,16 @@ module Principles
|
|
|
69
61
|
handed(Acknowledgement).start(id, member_id)
|
|
70
62
|
end
|
|
71
63
|
|
|
72
|
-
# The findings the last completed audit of map id, or of every map, deferred or accepted (#292, D35).
|
|
64
|
+
# The findings the last completed audit of map id, or of every map, deferred or accepted (#292, D35). Across
|
|
65
|
+
# every map, it names each principle whose record a later copy wrote, so a list left without one that cannot be
|
|
66
|
+
# read does not look whole (D85, V8).
|
|
73
67
|
#: (String?) -> Hash[String, untyped]
|
|
74
68
|
def open_findings(id)
|
|
75
|
-
listed = Models::FindingWriteUps.of(@project,
|
|
76
|
-
Views::FindingsResult.new(invocation).open(listed)
|
|
69
|
+
listed = Models::FindingWriteUps.of(@project, open_records(id)).listed
|
|
70
|
+
result = Views::FindingsResult.new(invocation).open(listed)
|
|
71
|
+
waiting = id ? [] : @principles.ids.filter_map { waiting_on_an_upgrade(it) }
|
|
72
|
+
result = result.merge("records_waiting_on_an_upgrade" => waiting.map(&:to_h)) unless waiting.empty?
|
|
73
|
+
result.merge("wrote" => [])
|
|
77
74
|
end
|
|
78
75
|
|
|
79
76
|
# The one line saying how many findings are open and how long the oldest has waited until now, and which
|
|
@@ -81,122 +78,19 @@ module Principles
|
|
|
81
78
|
# worded for the session's start, startup unless --session-start names another (#717).
|
|
82
79
|
#: (String?, Hash[String, untyped]) -> Views::Lines
|
|
83
80
|
def open_findings_line(id, options)
|
|
84
|
-
records =
|
|
81
|
+
records = open_records(id)
|
|
85
82
|
waiting = Models::FindingsLeftOpen.of(records).waiting_at(Time.now.utc)
|
|
86
83
|
Views::OpenFindingsLine.new(invocation).short(waiting, Models::FindingWriteUps.of(@project, records).not_found,
|
|
87
84
|
source: options["session_start"] || "startup")
|
|
88
85
|
end
|
|
89
86
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
output = assessment_request(audit, base, listing)
|
|
98
|
-
audit_result.present(with_record_notice(output, id, base)).merge("wrote" => [])
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# The request, listing the findings the last completed audit left to decide, and with an id that digests them
|
|
102
|
-
# (D35) and the revision of that audit's record (#653), but not the findings other principles leave open on
|
|
103
|
-
# members sharing these lines (D62).
|
|
104
|
-
#: (Models::Audit, String?, MembersToAssess::Listing) -> Hash[String, untyped]
|
|
105
|
-
def assessment_request(audit, base, listing)
|
|
106
|
-
record = @audit_records.find(audit.id)
|
|
107
|
-
prior = audit.prior_findings(record)
|
|
108
|
-
loads = loads_to_check(audit).listed
|
|
109
|
-
basis = Models::AssessmentBasis.printed(base, record)
|
|
110
|
-
audit_result.assessment_request(request_id: audit.assessment_id(basis, prior.digested, loads).to_s,
|
|
111
|
-
request: request_to_assess(audit, basis, listing.members,
|
|
112
|
-
parts_to_read(audit, prior, listing, loads)))
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# What the agent assesses: the members, with what else it reads beside them (D60).
|
|
116
|
-
#: (Models::Audit, Models::AssessmentBasis, Array[Hash[String, untyped]], Array[Views::RequestPart])
|
|
117
|
-
#| -> Views::AssessmentRequest
|
|
118
|
-
def request_to_assess(audit, basis, members, parts)
|
|
119
|
-
Views::AssessmentRequest.new(principle_id: audit.id, description: audit.map.description, members: members,
|
|
120
|
-
basis: basis.to_h, parts: parts)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# What the agent reads beside the members, in order (D60): the files outside the map that differ from the
|
|
124
|
-
# base commit, which a check and the answer's evidence read as they are now (#409); the prior findings
|
|
125
|
-
# (D35); the findings other principles leave open on members sharing these lines (D62); and the members to
|
|
126
|
-
# check against the activation (#355); each when it lists any; and, on the meta-principle's audit, the release
|
|
127
|
-
# since its last audit (D68) and the other principles with members no audit has judged (D71).
|
|
128
|
-
#: (Models::Audit, Models::PriorFindings, MembersToAssess::Listing, Hash[String, untyped]?)
|
|
129
|
-
#| -> Array[Views::RequestPart]
|
|
130
|
-
def parts_to_read(audit, prior, listing, loads)
|
|
131
|
-
[outside_the_map(audit), prior_findings_part(prior),
|
|
132
|
-
Views::OpenFindingsElsewhereResult.new(listing.open_findings_elsewhere).part,
|
|
133
|
-
Views::LoadsToCheckResult.new(invocation, loads, audit.id).part, package_since_last_audit(audit.map),
|
|
134
|
-
other_principles_unjudged(audit.map)].compact
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# The part listing each other principle with members no audit has judged as they are now, as
|
|
138
|
-
# list-member-problems reports them, for the principle whose audit states them; nil for any other (D71).
|
|
139
|
-
#: (Models::MemberMap) -> Views::RequestPart?
|
|
140
|
-
def other_principles_unjudged(map)
|
|
141
|
-
return unless map.keeps_others_held?
|
|
142
|
-
|
|
143
|
-
listed = Models::OtherPrinciples.of(@project, but: map.id).unjudged.map do |other, members|
|
|
144
|
-
Views::PrincipleWithChangedMembers.new(principle_id: other, members: members)
|
|
145
|
-
end
|
|
146
|
-
Views::OtherPrinciplesUnjudgedResult.new(listed).part
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# The part stating the release of principles the last completed audit ran under beside the one now, and
|
|
150
|
-
# whether the passage changed since, for a principle whose audit keeps one; nil for any other (D68).
|
|
151
|
-
#: (Models::MemberMap) -> Views::RequestPart?
|
|
152
|
-
def package_since_last_audit(map)
|
|
153
|
-
now = @tool.release_kept_by(map) or return
|
|
154
|
-
last = @audit_records.find(map.id)&.last_completed&.package
|
|
155
|
-
Views::PackageSinceLastAuditResult.new(invocation, at_last_audit: last&.version, now: now.version,
|
|
156
|
-
passage_changed: last && now.passage_changed_since?(last))
|
|
157
|
-
.part
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# The part listing the prior findings, in git with each evidence item saying whether its text changed since the
|
|
161
|
-
# commit the audit that left them open was based on, and whether it is found now (#858, #877); nil when there are
|
|
162
|
-
# none.
|
|
163
|
-
#: (Models::PriorFindings) -> Views::RequestPart?
|
|
164
|
-
def prior_findings_part(prior)
|
|
165
|
-
shown = prior.shown { |item, base| Models::EvidenceLinesSince.of(item, since: base, project: @project).facts }
|
|
166
|
-
Views::PriorFindingsResult.new(shown, last_audited_commit: prior.last_audited_commit).part
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
# The part naming the files outside the map that differ from the base commit, or nil when none do.
|
|
170
|
-
#: (Models::Audit) -> Views::RequestPart?
|
|
171
|
-
def outside_the_map(audit)
|
|
172
|
-
outside = @history.uncommitted_outside(audited_files(audit.id, audit.map))
|
|
173
|
-
Views::OutsideTheMapResult.new(outside && Models::UncommittedOutsideTheMap.new(outside).shown).part
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
# The commit the audit is judged against, over the map and every member's file; nil outside git.
|
|
177
|
-
#: (String, Models::MemberMap) -> String?
|
|
178
|
-
def base_commit(id, map)
|
|
179
|
-
@history.base_commit(id, audited_files(id, map))
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# The map's file and every member's file.
|
|
183
|
-
#: (String, Models::MemberMap) -> Array[String]
|
|
184
|
-
def audited_files(id, map)
|
|
185
|
-
[@member_maps.file(id), *map.members.map(&:path)]
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
# The request, with a notice when the last audit's record was left uncommitted.
|
|
189
|
-
#: (Hash[String, untyped], String, String?) -> Hash[String, untyped]
|
|
190
|
-
def with_record_notice(output, id, base)
|
|
191
|
-
return output unless base && uncommitted_record?(id)
|
|
192
|
-
|
|
193
|
-
output.merge("notice" => audit_result.uncommitted_record_notice(@audit_records.file(id)))
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
# Whether the last audit's record exists but differs from the last commit, so it may be left behind.
|
|
197
|
-
#: (String) -> bool
|
|
198
|
-
def uncommitted_record?(id)
|
|
199
|
-
@audit_records.exist?(id) && @history.uncommitted([@audit_records.file(id)]).any?
|
|
87
|
+
# The records whose open findings list-open-findings reads: id's, refused when a later copy wrote it in a
|
|
88
|
+
# form this copy cannot read, since an empty list would say it has none; or every principle's this copy can
|
|
89
|
+
# read, so one such record does not refuse the rest (D85, V8).
|
|
90
|
+
#: (String?) -> Array[Models::AuditRecord]
|
|
91
|
+
def open_records(id)
|
|
92
|
+
ids = @principles.ids_of(id)
|
|
93
|
+
id ? @audit_records.of(ids) : @audit_records.readable_of(ids)
|
|
200
94
|
end
|
|
201
95
|
end
|
|
202
96
|
end
|
|
@@ -59,9 +59,7 @@ module Principles
|
|
|
59
59
|
#| Models::AuditRecord) -> untyped
|
|
60
60
|
def completion_result(start, audit, dispositions, decided, written)
|
|
61
61
|
decisions = Views::PriorFindingDecisionsResult.new(kept_ids: decided.kept_ids, closed: decided.closed,
|
|
62
|
-
|
|
63
|
-
waits_on_dropped: decided.waits_on_dropped,
|
|
64
|
-
evidence_replaced: decided.evidence_replaced)
|
|
62
|
+
changed: decided.changed)
|
|
65
63
|
audit_result.completion(principle_id: audit.id, resolved: written.resolved_ids(decided),
|
|
66
64
|
open: written.open_ids, changes: changes(start, audit, dispositions, written),
|
|
67
65
|
decisions: decisions)
|
|
@@ -73,7 +71,7 @@ module Principles
|
|
|
73
71
|
def changes(start, audit, dispositions, written)
|
|
74
72
|
changed = audit.changed_files(dispositions)
|
|
75
73
|
added = start.added(now: audit.now)
|
|
76
|
-
map = @map_changes&.files_to_commit(@
|
|
74
|
+
map = @map_changes&.files_to_commit(@principles.file(audit.id), added: added) || []
|
|
77
75
|
files = @audit_records.files_to_commit(written, changed + map, start.reported)
|
|
78
76
|
Views::AuditChanges.new(files_to_commit: files, landed: landed_since_base(start, audit), added: added,
|
|
79
77
|
other_changed: other_changed(audit, changed),
|
|
@@ -8,14 +8,16 @@ require_relative "../models/audit"
|
|
|
8
8
|
require_relative "../models/carried_assessments"
|
|
9
9
|
require_relative "../models/member"
|
|
10
10
|
require_relative "../models/member_grounds"
|
|
11
|
-
require_relative "../models/
|
|
11
|
+
require_relative "../models/principle_history"
|
|
12
12
|
require_relative "../models/members_sharing_lines"
|
|
13
13
|
require_relative "../models/project"
|
|
14
|
+
require_relative "../models/record_format"
|
|
14
15
|
require_relative "../models/record_judged_against"
|
|
15
16
|
require_relative "../views/audit_result"
|
|
16
17
|
require_relative "../views/lines_shared_with_member"
|
|
17
18
|
require_relative "../views/map_result"
|
|
18
19
|
require_relative "../views/member_repairs"
|
|
20
|
+
require_relative "../views/record_waiting_on_an_upgrade"
|
|
19
21
|
require_relative "running_tool"
|
|
20
22
|
|
|
21
23
|
module Principles
|
|
@@ -37,7 +39,7 @@ module Principles
|
|
|
37
39
|
def initialize(project, tool:)
|
|
38
40
|
@project = project
|
|
39
41
|
@tool = tool
|
|
40
|
-
@
|
|
42
|
+
@principles = @project.principles #: Models::MappedPrinciples
|
|
41
43
|
@audit_records = @project.audit_records #: Models::AuditRecords
|
|
42
44
|
@history = @project.history #: Models::ProjectHistory
|
|
43
45
|
end
|
|
@@ -51,15 +53,15 @@ module Principles
|
|
|
51
53
|
private
|
|
52
54
|
|
|
53
55
|
# The history of principle_id's map, read through the collaborators this controller already holds.
|
|
54
|
-
#: (String) -> Models::
|
|
55
|
-
def
|
|
56
|
-
Models::
|
|
56
|
+
#: (String) -> Models::PrincipleHistory
|
|
57
|
+
def principle_history(principle_id)
|
|
58
|
+
Models::PrincipleHistory.new(id: principle_id, history: @history, principles: @principles)
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
# Saves the map, and nothing else, then prints the result the block builds from the map as written.
|
|
60
|
-
#: (Models::
|
|
62
|
+
#: (Models::Principle) { (Views::PrintedPrinciple) -> Hash[String, untyped] } -> untyped
|
|
61
63
|
def write_map(map, &)
|
|
62
|
-
wrote = @
|
|
64
|
+
wrote = @principles.save(map)
|
|
63
65
|
yield(printed_principle(map)).merge("wrote" => [wrote])
|
|
64
66
|
end
|
|
65
67
|
|
|
@@ -94,7 +96,7 @@ module Principles
|
|
|
94
96
|
def repaired(entry, repairs)
|
|
95
97
|
principle = entry["principle"] or return entry
|
|
96
98
|
id = entry["id"] or return entry
|
|
97
|
-
fields = @
|
|
99
|
+
fields = @principles.find(principle).member(id).merge(entry.slice("code")).merge("id" => id)
|
|
98
100
|
entry.merge("repair_with" => repairs.commands(principle, fields))
|
|
99
101
|
rescue Error
|
|
100
102
|
entry
|
|
@@ -118,6 +120,18 @@ module Principles
|
|
|
118
120
|
Views::Invocation.new(executable: @tool.executable, project: @project.root)
|
|
119
121
|
end
|
|
120
122
|
|
|
123
|
+
# Principle id as waiting on an upgrade, when a later copy wrote its record (D85, V8).
|
|
124
|
+
#: (String) -> Views::RecordWaitingOnAnUpgrade?
|
|
125
|
+
def waiting_on_an_upgrade(id)
|
|
126
|
+
format = @audit_records.newer_format(id) or return
|
|
127
|
+
Views::RecordWaitingOnAnUpgrade.new(principle: id, format: format.number, first_release: format.first_release,
|
|
128
|
+
newest: Models::RecordFormat::NEWEST, update: format.update_either_way)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# The line saying principle id's audits wait on an upgrade, as a field to print beside it, or none (#1067).
|
|
132
|
+
#: (String) -> Hash[String, String]
|
|
133
|
+
def waiting_beside(id) = waiting_on_an_upgrade(id)&.beside || {}
|
|
134
|
+
|
|
121
135
|
#: () -> Views::AuditResult
|
|
122
136
|
def audit_result
|
|
123
137
|
Views::AuditResult.new(invocation)
|
|
@@ -142,19 +156,19 @@ module Principles
|
|
|
142
156
|
def text(value, field) = Models::AnswerText.new(value).required(field)
|
|
143
157
|
|
|
144
158
|
# The principle as the view prints it, with each member's id beside its locator.
|
|
145
|
-
#: (Models::
|
|
159
|
+
#: (Models::Principle, ?members: Array[Hash[String, untyped]]) -> Views::PrintedPrinciple
|
|
146
160
|
def printed_principle(map, members: map.members_shown)
|
|
147
|
-
Views::PrintedPrinciple.new(id: map.id, file: @
|
|
161
|
+
Views::PrintedPrinciple.new(id: map.id, file: @principles.file(map.id), description: map.description,
|
|
148
162
|
members: members, activation: map.activation)
|
|
149
163
|
end
|
|
150
164
|
|
|
151
165
|
# Each member's hash at base, or nil outside git.
|
|
152
|
-
#: (String?, Models::
|
|
166
|
+
#: (String?, Models::Principle) -> Hash[String, String]?
|
|
153
167
|
def committed(base, map) = base ? @history.hashes_at(base, map.members) : nil
|
|
154
168
|
|
|
155
169
|
# When each of the map's members loads, by id, which a full audit's request lists against the activation and
|
|
156
170
|
# show-principle prints, from the project's hooks as hooks read them.
|
|
157
|
-
#: (Models::
|
|
171
|
+
#: (Models::Principle, ?Models::HookCommands) -> Hash[String, Models::MemberLoads]
|
|
158
172
|
def member_loads(map, hooks = @project.hook_commands) = @project.member_loads(map.members, hooks)
|
|
159
173
|
|
|
160
174
|
# The members a full audit lists to check against its activation, each with the decision its last completed
|
|
@@ -192,7 +206,7 @@ module Principles
|
|
|
192
206
|
|
|
193
207
|
# The members sharing a line with member where it is now, in map and in the other maps, as add-member and
|
|
194
208
|
# show-principle print them (#383, #541).
|
|
195
|
-
#: (Models::Member, Models::
|
|
209
|
+
#: (Models::Member, Models::Principle) -> Views::LinesSharedWithMember
|
|
196
210
|
def lines_shared(member, map)
|
|
197
211
|
Views::LinesSharedWithMember.new(**Models::MembersSharingLines.of(@project, member).facts_beside(map))
|
|
198
212
|
end
|
|
@@ -66,17 +66,17 @@ module Principles
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# The map the audit began from, read from the base commit when the answer declares changes to the map.
|
|
69
|
-
#: (Models::CorrectionBasis, Models::Audit, Models::DeclaredMapChanges) -> Models::
|
|
69
|
+
#: (Models::CorrectionBasis, Models::Audit, Models::DeclaredMapChanges) -> Models::Principle
|
|
70
70
|
def started_from(basis, audit, changes)
|
|
71
|
-
audit.map_started_from(basis, changes, map_file: @
|
|
71
|
+
audit.map_started_from(basis, changes, map_file: @principles.file(audit.id)) do |base|
|
|
72
72
|
committed_map(base, audit.id)
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
# The map id as the base commit holds it.
|
|
77
|
-
#: (String, String) -> Models::
|
|
77
|
+
#: (String, String) -> Models::Principle
|
|
78
78
|
def committed_map(base, id)
|
|
79
|
-
|
|
79
|
+
principle_history(id).map_at(base)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# Each member's hash when the audit began, checked against the request id: from the map it started from at the
|
|
@@ -0,0 +1,180 @@
|
|
|
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/loading_decision"
|
|
8
|
+
require_relative "../models/meta_principle"
|
|
9
|
+
require_relative "../models/other_principles"
|
|
10
|
+
require_relative "../models/prior_decision_fields"
|
|
11
|
+
require_relative "../models/recent_decision"
|
|
12
|
+
require_relative "../models/reported_check"
|
|
13
|
+
require_relative "../models/uncommitted_outside_the_map"
|
|
14
|
+
require_relative "../views/assessment_request"
|
|
15
|
+
require_relative "../views/loads_to_check_result"
|
|
16
|
+
require_relative "../views/open_findings_elsewhere_result"
|
|
17
|
+
require_relative "../views/other_principles_unjudged_result"
|
|
18
|
+
require_relative "../views/outside_the_map_result"
|
|
19
|
+
require_relative "../views/package_since_last_audit_result"
|
|
20
|
+
require_relative "../views/prior_findings_result"
|
|
21
|
+
require_relative "members_to_assess"
|
|
22
|
+
|
|
23
|
+
module Principles
|
|
24
|
+
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
25
|
+
# controllers/CLAUDE.md owns the boundary.
|
|
26
|
+
module Controllers
|
|
27
|
+
# The request a full audit of one principle asks as the project stands, which Audit hands over for start-audit:
|
|
28
|
+
# the commit it is based on, its id and what it asks. Starting writes nothing: the request id is a digest of what
|
|
29
|
+
# the request depends on, so Answer checks the answer against the project as it is then (D25).
|
|
30
|
+
class FullAuditRequest < Command
|
|
31
|
+
# principle_id names the principle whose full audit is asked for; its map is refused unless it can be audited.
|
|
32
|
+
#: (Models::Project, tool: RunningTool, principle_id: String) -> void
|
|
33
|
+
def initialize(project, tool:, principle_id:)
|
|
34
|
+
super(project, tool: tool)
|
|
35
|
+
@id = principle_id
|
|
36
|
+
map = @principles.auditable(principle_id)
|
|
37
|
+
@base = @history.base_commit(principle_id, audited_files(map)) #: String?
|
|
38
|
+
current = @project.snapshots(map)
|
|
39
|
+
@audit = Models::Audit.new(map: map, now: current.hashes) #: Models::Audit
|
|
40
|
+
listing = handed(MembersToAssess, principle_id: principle_id).listed(@audit, current)
|
|
41
|
+
@listing = listing #: MembersToAssess::Listing
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The request as start-audit prints it, with a notice when the last audit's record was left uncommitted.
|
|
45
|
+
#: () -> Hash[String, untyped]
|
|
46
|
+
def printed
|
|
47
|
+
audit_result.present(with_record_notice(audit_result.assessment_request(asked))).merge("wrote" => [])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The answer alone, as start-audit --as template prints it, to fill and submit under the request's id (D81).
|
|
51
|
+
#: () -> Hash[String, untyped]
|
|
52
|
+
def to_fill
|
|
53
|
+
audit_result.answer_to_fill(asked)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# The request and what it asks, listing the findings the last completed audit left to decide, under an id that
|
|
59
|
+
# digests them (D35) and the revision of that audit's record (#653), but not the findings other principles leave
|
|
60
|
+
# open on members sharing these lines (D62).
|
|
61
|
+
#: () -> Views::AssessmentRequest
|
|
62
|
+
def asked
|
|
63
|
+
record = @audit_records.find(@id)
|
|
64
|
+
prior = @audit.prior_findings(record)
|
|
65
|
+
loads = loads_to_check(@audit).listed
|
|
66
|
+
basis = Models::AssessmentBasis.printed(@base, record)
|
|
67
|
+
head = Views::AnswerHead.new(request_id: @audit.assessment_id(basis, prior.digested, loads).to_s,
|
|
68
|
+
basis: basis.to_h)
|
|
69
|
+
request_to_assess(head, parts_to_read(prior, loads))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# What the agent assesses: the members, with what else it reads beside them (D60).
|
|
73
|
+
#: (Views::AnswerHead, Array[Views::RequestPart]) -> Views::AssessmentRequest
|
|
74
|
+
def request_to_assess(head, parts)
|
|
75
|
+
Views::AssessmentRequest.new(principle: { "principle_id" => @id, "description" => @audit.map.description },
|
|
76
|
+
members: assessed_members, head: head,
|
|
77
|
+
placeholders: { "recent_decision" => Models::RecentDecision::PLACEHOLDERS.to_h,
|
|
78
|
+
"collective_assessment" =>
|
|
79
|
+
Models::AssessmentAnswer::COLLECTIVE_PLACEHOLDER,
|
|
80
|
+
"new_finding" => Models::NewFindings::TEMPLATE,
|
|
81
|
+
"left_as_printed_rule" =>
|
|
82
|
+
Models::AssessmentAnswer::LEFT_AS_PRINTED_RULE },
|
|
83
|
+
parts: parts)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The members the request lists, each checked one's template printing the placeholders an answer leaves as
|
|
87
|
+
# printed to give none (#993).
|
|
88
|
+
#: () -> Views::AssessedMembers
|
|
89
|
+
def assessed_members
|
|
90
|
+
Views::AssessedMembers.new(@listing.members,
|
|
91
|
+
reviewed_check_placeholders: Models::ReportedCheck::PLACEHOLDERS.to_h,
|
|
92
|
+
unchanged_check_placeholders: Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h,
|
|
93
|
+
assessment_placeholder: Models::MemberAssessments::PLACEHOLDER,
|
|
94
|
+
sighting_placeholders: Models::MemberAssessments::SIGHTING.to_h)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# The part listing the members to check against the activation, each decision's template printing the
|
|
98
|
+
# placeholders an answer leaves as printed to give none (#994); nil when none is listed.
|
|
99
|
+
#: (Hash[String, untyped]?) -> Views::RequestPart?
|
|
100
|
+
def loads_part(loads)
|
|
101
|
+
Views::LoadsToCheckResult.new(invocation, loads, @id, placeholders: Models::LoadingDecision::PLACEHOLDERS.to_h)
|
|
102
|
+
.part
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# What the agent reads beside the members, in order (D60): the files outside the map that differ from the
|
|
106
|
+
# base commit, which a check and the answer's evidence read as they are now (#409); the prior findings
|
|
107
|
+
# (D35); the findings other principles leave open on members sharing these lines (D62); and the members to
|
|
108
|
+
# check against the activation (#355); each when it lists any; and, on the meta-principle's audit, the release
|
|
109
|
+
# since its last audit (D68) and the other principles with members no audit has judged (D71).
|
|
110
|
+
#: (Models::PriorFindings, Hash[String, untyped]?) -> Array[Views::RequestPart]
|
|
111
|
+
def parts_to_read(prior, loads)
|
|
112
|
+
map = @audit.map
|
|
113
|
+
[outside_the_map, prior_findings_part(prior),
|
|
114
|
+
Views::OpenFindingsElsewhereResult.new(@listing.open_findings_elsewhere).part,
|
|
115
|
+
loads_part(loads), package_since_last_audit(map),
|
|
116
|
+
other_principles_unjudged(map)].compact
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# The part listing each other principle with members no audit has judged as they are now, as
|
|
120
|
+
# list-member-problems reports them, for the principle whose audit states them; nil for any other (D71).
|
|
121
|
+
#: (Models::Principle) -> Views::RequestPart?
|
|
122
|
+
def other_principles_unjudged(map)
|
|
123
|
+
return unless map.keeps_others_held?
|
|
124
|
+
|
|
125
|
+
listed = Models::OtherPrinciples.of(@project, but: map.id).unjudged.map do |other, members|
|
|
126
|
+
Views::PrincipleWithChangedMembers.new(principle_id: other, members: members)
|
|
127
|
+
end
|
|
128
|
+
Views::OtherPrinciplesUnjudgedResult.new(listed).part
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# The part stating the release of principles the last completed audit ran under beside the one now, and
|
|
132
|
+
# whether the passage changed since, for a principle whose audit keeps one; nil for any other (D68).
|
|
133
|
+
#: (Models::Principle) -> Views::RequestPart?
|
|
134
|
+
def package_since_last_audit(map)
|
|
135
|
+
now = @tool.release_kept_by(map) or return
|
|
136
|
+
last = @audit_records.find(map.id)&.last_completed&.package
|
|
137
|
+
Views::PackageSinceLastAuditResult.new(invocation, at_last_audit: last&.version, now: now.version,
|
|
138
|
+
passage_changed: last && now.passage_changed_since?(last))
|
|
139
|
+
.part
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# The part listing the prior findings, in git with each evidence item saying whether its text changed since the
|
|
143
|
+
# commit the audit that left them open was based on, and whether it is found now (#858, #877); nil when there are
|
|
144
|
+
# none.
|
|
145
|
+
#: (Models::PriorFindings) -> Views::RequestPart?
|
|
146
|
+
def prior_findings_part(prior)
|
|
147
|
+
shown = prior.shown { |item, base| Models::EvidenceLinesSince.of(item, since: base, project: @project).facts }
|
|
148
|
+
Views::PriorFindingsResult.new(shown, placeholders: Models::PriorDecisionFields::TEMPLATE_PLACEHOLDERS,
|
|
149
|
+
last_audited_commit: prior.last_audited_commit).part
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# The part naming the files outside the map that differ from the base commit, or nil when none do.
|
|
153
|
+
#: () -> Views::RequestPart?
|
|
154
|
+
def outside_the_map
|
|
155
|
+
outside = @history.uncommitted_outside(audited_files(@audit.map))
|
|
156
|
+
Views::OutsideTheMapResult.new(outside && Models::UncommittedOutsideTheMap.new(outside).shown).part
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# The map's file and every member's file, which the base commit is judged over.
|
|
160
|
+
#: (Models::Principle) -> Array[String]
|
|
161
|
+
def audited_files(map)
|
|
162
|
+
[@principles.file(@id), *map.members.map(&:path)]
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# The request, with a notice when the last audit's record was left uncommitted.
|
|
166
|
+
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
167
|
+
def with_record_notice(output)
|
|
168
|
+
return output unless @base && uncommitted_record?
|
|
169
|
+
|
|
170
|
+
output.merge("notice" => audit_result.uncommitted_record_notice(@audit_records.file(@id)))
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Whether the last audit's record exists but differs from the last commit, so it may be left behind.
|
|
174
|
+
#: () -> bool
|
|
175
|
+
def uncommitted_record?
|
|
176
|
+
@audit_records.exist?(@id) && @history.uncommitted([@audit_records.file(@id)]).any?
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|