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.
- checksums.yaml +4 -4
- data/lib/principles/cli.rb +10 -2
- data/lib/principles/command_line.rb +46 -35
- data/lib/principles/command_routes.rb +4 -3
- data/lib/principles/controllers/acknowledgement.rb +84 -18
- data/lib/principles/controllers/answer.rb +56 -125
- data/lib/principles/controllers/answer_phase.rb +54 -0
- data/lib/principles/controllers/assessment.rb +132 -0
- data/lib/principles/controllers/audit.rb +45 -140
- data/lib/principles/controllers/audit_completion.rb +8 -8
- data/lib/principles/controllers/command.rb +29 -14
- data/lib/principles/controllers/correction.rb +23 -13
- data/lib/principles/controllers/full_audit_request.rb +190 -0
- data/lib/principles/controllers/inventory.rb +46 -79
- 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 +79 -0
- data/lib/principles/controllers/members_a_commit_changed.rb +12 -3
- data/lib/principles/controllers/members_to_assess.rb +35 -20
- data/lib/principles/controllers/meta_principle_setup.rb +5 -5
- data/lib/principles/controllers/repoint.rb +19 -23
- 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 +20 -4
- data/lib/principles/data/command-steps.json +14 -13
- 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 +12 -15
- data/lib/principles/data/project_root.rb +48 -0
- data/lib/principles/data/schema_check.rb +39 -11
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
- data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
- data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
- data/lib/principles/data/schemas/audit-record.schema.json +13 -1
- data/lib/principles/data/schemas/command-steps.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
- data/lib/principles/invocation_options.rb +1 -1
- data/lib/principles/models/acknowledgement.rb +73 -84
- data/lib/principles/models/acknowledgement_refusal.rb +90 -0
- data/lib/principles/models/answer_place.rb +4 -0
- data/lib/principles/models/assessment_answer.rb +19 -17
- data/lib/principles/models/assessment_left_as_printed.rb +81 -0
- data/lib/principles/models/audit.rb +24 -15
- data/lib/principles/models/audit_record.rb +19 -20
- data/lib/principles/models/audit_records.rb +77 -4
- data/lib/principles/models/audit_start.rb +3 -3
- data/lib/principles/models/candidate_files.rb +30 -7
- data/lib/principles/models/candidate_inventory.rb +23 -6
- data/lib/principles/models/candidate_listing.rb +12 -3
- data/lib/principles/models/candidate_outline.rb +195 -0
- data/lib/principles/models/carried_assessments.rb +1 -1
- data/lib/principles/models/carried_member.rb +42 -0
- data/lib/principles/models/check_since_last_audit.rb +22 -9
- data/lib/principles/models/command_steps.rb +17 -1
- 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 +13 -12
- 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/frontmatter_fields.rb +9 -8
- data/lib/principles/models/instruction_named.rb +35 -0
- data/lib/principles/models/kept_prior_finding.rb +12 -7
- data/lib/principles/models/left_as_printed.rb +39 -0
- 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 +32 -9
- data/lib/principles/models/member_file.rb +35 -11
- data/lib/principles/models/member_grounds.rb +2 -2
- data/lib/principles/models/member_hashes_as_written.rb +44 -0
- data/lib/principles/models/member_lines.rb +63 -15
- data/lib/principles/models/member_moves.rb +3 -3
- data/lib/principles/models/member_problems.rb +50 -24
- data/lib/principles/models/member_repair_moves.rb +54 -0
- data/lib/principles/models/members_sharing_lines.rb +3 -3
- data/lib/principles/models/missing_files.rb +2 -2
- data/lib/principles/models/new_findings.rb +55 -0
- data/lib/principles/models/open_finding.rb +23 -13
- data/lib/principles/models/open_findings_elsewhere.rb +4 -0
- data/lib/principles/models/other_principles.rb +1 -1
- data/lib/principles/models/other_templates_placeholders.rb +113 -0
- data/lib/principles/models/outline_budget.rb +127 -0
- data/lib/principles/models/outline_group.rb +31 -0
- data/lib/principles/models/outline_section.rb +56 -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} +15 -4
- data/lib/principles/models/prior_decision_fields.rb +47 -0
- data/lib/principles/models/prior_finding_decision.rb +38 -7
- 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 +22 -17
- data/lib/principles/models/project_history.rb +2 -2
- data/lib/principles/models/quoted_change.rb +137 -0
- data/lib/principles/models/recent_decision.rb +90 -0
- data/lib/principles/models/record_format.rb +109 -0
- data/lib/principles/models/recorded_entry.rb +6 -0
- data/lib/principles/models/recorded_finding.rb +4 -0
- data/lib/principles/models/recorded_hashes.rb +43 -0
- data/lib/principles/models/recorded_members.rb +33 -16
- data/lib/principles/models/refusal_before_shape.rb +21 -0
- data/lib/principles/models/repoint.rb +13 -0
- data/lib/principles/models/reported_check.rb +66 -24
- data/lib/principles/models/request_id.rb +24 -4
- data/lib/principles/models/sent_answer.rb +51 -0
- data/lib/principles/models/sent_prior_decisions.rb +31 -0
- data/lib/principles/models/shape_problems_beside.rb +40 -0
- data/lib/principles/models/still_holds_restatement.rb +7 -10
- data/lib/principles/models/submitted_answer.rb +34 -0
- data/lib/principles/models/template_placeholders.rb +71 -0
- data/lib/principles/models/text_within.rb +55 -0
- data/lib/principles/models/unchecked_members.rb +76 -0
- data/lib/principles/models/write_up_opening.rb +21 -4
- data/lib/principles/session_start_options.rb +29 -0
- data/lib/principles/start_audit_options.rb +52 -0
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +15 -7
- data/lib/principles/views/answer_head.rb +29 -0
- data/lib/principles/views/assessed_members.rb +129 -0
- data/lib/principles/views/assessment_request.rb +139 -78
- data/lib/principles/views/audit_result.rb +55 -42
- data/lib/principles/views/candidate_files_result.rb +41 -19
- data/lib/principles/views/check_notes.rb +44 -0
- data/lib/principles/views/check_result_template.rb +42 -30
- 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/instruction.rb +74 -0
- data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
- data/lib/principles/views/loads_to_check_result.rb +13 -6
- data/lib/principles/views/map_added_to.rb +31 -0
- data/lib/principles/views/map_result.rb +38 -23
- data/lib/principles/views/member_change_since_baseline.rb +22 -5
- data/lib/principles/views/member_repairs.rb +21 -52
- data/lib/principles/views/members_a_commit_changed.rb +40 -10
- data/lib/principles/views/meta_principle_result.rb +3 -14
- data/lib/principles/views/one_member_check_result_template.rb +43 -0
- data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
- data/lib/principles/views/open_findings_line.rb +77 -23
- data/lib/principles/views/principle_read_result.rb +37 -28
- data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
- data/lib/principles/views/prior_findings_result.rb +30 -18
- data/lib/principles/views/problem_lines.rb +14 -11
- data/lib/principles/views/problem_result.rb +30 -16
- data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
- data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
- data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
- data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
- data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +6 -17
- 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/judge-the-set-with-carried-assessments.md +5 -10
- data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
- 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/assess-every-member/say-what-observed-means.md +4 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -4
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
- data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
- 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-candidate-files.md +21 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +25 -23
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +18 -16
- data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +4 -2
- 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 +7 -1
- 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 +7 -6
- 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 +30 -30
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +39 -39
- 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-principles-skill-is-where-to-start.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/keep-them-held-between-audits.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +11 -7
- data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
- data/lib/principles/views/request_part.rb +26 -6
- data/lib/principles/views/request_parts.rb +8 -0
- metadata +69 -9
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
- data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require "digest"
|
|
5
5
|
require_relative "../error"
|
|
6
|
+
require_relative "../prose_list"
|
|
6
7
|
require_relative "locator"
|
|
7
8
|
require_relative "write_up_opening"
|
|
8
9
|
|
|
@@ -26,6 +27,10 @@ module Principles
|
|
|
26
27
|
PLACE_LOST = %w[section_not_found passage_not_found passage_end_not_found ambiguous_heading
|
|
27
28
|
ambiguous_passage field_not_found].freeze #: Array[String]
|
|
28
29
|
|
|
30
|
+
# How many openings of an ambiguous passage its refusal names by line, so a one-character opening does not
|
|
31
|
+
# name every line of the file.
|
|
32
|
+
OPENINGS_NAMED = 5 #: Integer
|
|
33
|
+
|
|
29
34
|
# The file name endings read as Markdown, where a # line is a heading and not a comment.
|
|
30
35
|
MARKDOWN = /\.(md|markdown|mdx)\z/i #: Regexp
|
|
31
36
|
|
|
@@ -111,9 +116,10 @@ module Principles
|
|
|
111
116
|
# passage.
|
|
112
117
|
#: (Array[String], Integer, String, String, String?) -> [Integer, Integer, String]
|
|
113
118
|
def passage(lines, first, selected, start_text, end_text)
|
|
114
|
-
|
|
119
|
+
before = lines[0...first].to_a.join.length
|
|
120
|
+
start = only_opening(selected, start_text, before)
|
|
115
121
|
found = selected[start...passage_end(selected, start, start_text, end_text)].to_s
|
|
116
|
-
line = @text[0,
|
|
122
|
+
line = @text[0, before + start].to_s.count("\n")
|
|
117
123
|
[line, line + line_count(found), found]
|
|
118
124
|
end
|
|
119
125
|
|
|
@@ -123,19 +129,37 @@ module Principles
|
|
|
123
129
|
found.count("\n") + (found.end_with?("\n") ? 0 : 1)
|
|
124
130
|
end
|
|
125
131
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
# Where start_text's one occurrence in text begins; text starts before characters into the file.
|
|
133
|
+
#: (String, String, Integer) -> Integer
|
|
134
|
+
def only_opening(text, start_text, before)
|
|
135
|
+
starts = text.enum_for(:scan, start_text).filter_map { Regexp.last_match&.begin(0) }
|
|
136
|
+
return starts.first.to_i if starts.length == 1
|
|
137
|
+
|
|
138
|
+
starts.empty? ? opening_not_found(start_text) : ambiguous_opening(start_text, starts.map { before + it })
|
|
139
|
+
end
|
|
134
140
|
|
|
135
|
-
|
|
141
|
+
#: (String) -> bot
|
|
142
|
+
def opening_not_found(start_text)
|
|
143
|
+
raise Error.new("passage_not_found", "The passage starting #{start_text.inspect} is not in the file",
|
|
144
|
+
"Quote the passage's opening text exactly.", @path)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Names the line of each opening, for the agent to quote more of the one it means (dogfood D5).
|
|
148
|
+
#: (String, Array[Integer]) -> bot
|
|
149
|
+
def ambiguous_opening(start_text, offsets)
|
|
150
|
+
raise Error.new("ambiguous_passage",
|
|
151
|
+
"#{start_text.inspect} occurs #{offsets.length} times, at lines #{lines_named(offsets)}",
|
|
136
152
|
"Quote more of the passage's start so it occurs once.", @path)
|
|
137
153
|
end
|
|
138
154
|
|
|
155
|
+
# The lines, as first_line counts them, of the first OPENINGS_NAMED offsets into the file, and how many more.
|
|
156
|
+
#: (Array[Integer]) -> String
|
|
157
|
+
def lines_named(offsets)
|
|
158
|
+
named = offsets.first(OPENINGS_NAMED).map { (@text[0, it].to_s.count("\n") + 1).to_s }
|
|
159
|
+
more = offsets.length - named.length
|
|
160
|
+
more.zero? ? ProseList.new(named).to_s : "#{named.join(", ")} and #{more} more"
|
|
161
|
+
end
|
|
162
|
+
|
|
139
163
|
#: (String, Integer, String, String?) -> Integer
|
|
140
164
|
def passage_end(text, start, start_text, end_text)
|
|
141
165
|
return (text.index("\n", start) || (text.length - 1)) + 1 unless end_text
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "json_digest"
|
|
5
5
|
require_relative "loading_facts"
|
|
6
|
-
require_relative "
|
|
6
|
+
require_relative "principle_members"
|
|
7
7
|
require_relative "member_loads"
|
|
8
8
|
|
|
9
9
|
module Principles
|
|
@@ -14,7 +14,7 @@ module Principles
|
|
|
14
14
|
# keeps a digest of each with the assessment, and carries the assessment forward only while both match (D49).
|
|
15
15
|
class MemberGrounds
|
|
16
16
|
# members are the map's members; loads is each member's MemberLoads by id.
|
|
17
|
-
#: (
|
|
17
|
+
#: (PrincipleMembers, Hash[String, MemberLoads]) -> void
|
|
18
18
|
def initialize(members, loads)
|
|
19
19
|
@members = members.by_id #: Hash[String, Member]
|
|
20
20
|
@loads = loads
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "recorded_entry"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# The member hashes an audit record holds, read from a record a later copy wrote that this copy's schema refuses,
|
|
10
|
+
# for list-member-problems to compare its members with, read-only (#1066). Only those fields are read, each entry
|
|
11
|
+
# kept only when its hash is text, so nothing else of a shape this copy does not know travels; a member left out
|
|
12
|
+
# is compared with the commit that mapped it instead.
|
|
13
|
+
class MemberHashesAsWritten
|
|
14
|
+
# fields is the record as its file holds it, or anything else JSON may give.
|
|
15
|
+
#: (untyped) -> void
|
|
16
|
+
def initialize(fields)
|
|
17
|
+
members = fields["members"] if fields.is_a?(Hash)
|
|
18
|
+
@by_key = (members.is_a?(Hash) ? kept(members) : {}).freeze #: Hash[String, String]
|
|
19
|
+
freeze
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Each member's hash by the key it was recorded under, as RecordedMembers#hashes_by_key gives a readable one.
|
|
23
|
+
#: Hash[String, String]
|
|
24
|
+
attr_reader :by_key
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
# Each entry whose hash is text and whose key, if it keeps one, is text too, by its key as RecordedEntry#key
|
|
29
|
+
# gives it.
|
|
30
|
+
#: (Hash[untyped, untyped]) -> Hash[String, String]
|
|
31
|
+
def kept(members)
|
|
32
|
+
members.each_with_object({}) do |(id, entry), kept|
|
|
33
|
+
kept[RecordedEntry.new(id, entry).key] = entry["sha256"] if readable?(entry)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Whether entry holds its hash, and any key it keeps, as text, the shape a readable record's schema requires.
|
|
38
|
+
#: (untyped) -> bool
|
|
39
|
+
def readable?(entry)
|
|
40
|
+
entry.is_a?(Hash) && [entry["sha256"], entry["key"]] in [String, String | nil]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -13,9 +13,17 @@ module Principles
|
|
|
13
13
|
# to a whole file. A first guess, for an alpha test to confirm (#379).
|
|
14
14
|
SHOWN_AT_MOST = 80
|
|
15
15
|
|
|
16
|
-
# The
|
|
16
|
+
# The most bytes both sides together show whole: a 4 KB acknowledgement less its 2.7 KB of other fields,
|
|
17
|
+
# so a short file of long lines shows its changed region and not itself twice (D93's review F4, #1069).
|
|
18
|
+
SHOWN_BYTES_AT_MOST = 1300
|
|
19
|
+
|
|
20
|
+
# The most unchanged lines shown on each side of a changed region, as git shows by default (#449); fewer
|
|
21
|
+
# when these would pass SHOWN_BYTES_AT_MOST (#1069).
|
|
17
22
|
CONTEXT_LINES = 3
|
|
18
23
|
|
|
24
|
+
# The most shown around a one-line change, whose edit first_changed_lines already gives (#1146).
|
|
25
|
+
ONE_LINE_CONTEXT_LINES = 1
|
|
26
|
+
|
|
19
27
|
# Each line is kept without its line ending, so a line the agent copies from the request is a whole line it
|
|
20
28
|
# can quote (#451).
|
|
21
29
|
#: (at_baseline: Array[String], now: Array[String]) -> void
|
|
@@ -36,36 +44,76 @@ module Principles
|
|
|
36
44
|
#: () -> bool
|
|
37
45
|
def changed? = @at_baseline != @now
|
|
38
46
|
|
|
39
|
-
# Both sides' lines while each
|
|
40
|
-
#
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
# Both sides' lines while each is at most SHOWN_AT_MOST lines and together at most SHOWN_BYTES_AT_MOST less
|
|
48
|
+
# taken, the bytes a request's other parts take beyond its usual ones, as a checked member's check_result
|
|
49
|
+
# template does (#1119); else their changed region, with where it starts within the member and each side's
|
|
50
|
+
# length; else how many lines each side has.
|
|
51
|
+
#: (?taken: Integer) -> Hash[String, untyped]
|
|
52
|
+
def shown(taken: 0)
|
|
53
|
+
budget = SHOWN_BYTES_AT_MOST - taken
|
|
43
54
|
sides = { "at_baseline" => @at_baseline, "now" => @now }
|
|
44
|
-
return sides if
|
|
55
|
+
return sides if within_line_limit?(sides.values) && bytes(sides.values) <= budget
|
|
45
56
|
|
|
46
57
|
counts = sides.transform_values(&:length)
|
|
47
|
-
region =
|
|
48
|
-
return { "omitted" => "too_long", "lines" => counts } unless
|
|
58
|
+
context, region = region_within(budget)
|
|
59
|
+
return { "omitted" => "too_long", "lines" => counts } unless within_line_limit?(lines_of(region))
|
|
49
60
|
|
|
50
|
-
{ "changed_region" => { "context_lines" =>
|
|
61
|
+
{ "changed_region" => { "context_lines" => context, **region }, "lines" => counts }
|
|
51
62
|
end
|
|
52
63
|
|
|
53
64
|
private
|
|
54
65
|
|
|
66
|
+
# How many bytes the sides' lines hold together.
|
|
67
|
+
#: (Array[Array[String]]) -> Integer
|
|
68
|
+
def bytes(sides) = sides.sum { |lines| lines.sum(&:bytesize) }
|
|
69
|
+
|
|
55
70
|
#: (Array[Array[String]]) -> bool
|
|
56
|
-
def
|
|
71
|
+
def within_line_limit?(sides)
|
|
57
72
|
sides.all? { |lines| lines.length <= SHOWN_AT_MOST }
|
|
58
73
|
end
|
|
59
74
|
|
|
60
|
-
#
|
|
75
|
+
# The changed region with the most context, up to CONTEXT_LINES, whose lines fit budget, and how many lines of
|
|
76
|
+
# context it has; with none when no context fits, since the changed lines are what is judged, and then the sides
|
|
77
|
+
# first_changed_lines' span and read_the_change stand in for left out (#1103, #1144).
|
|
78
|
+
#: (Integer) -> [Integer, Hash[String, Hash[String, untyped]]]
|
|
79
|
+
def region_within(budget)
|
|
80
|
+
regions = most_context.downto(0).map { |context| [context, changed_region(context)] }
|
|
81
|
+
regions.find { |_, region| bytes(lines_of(region)) <= budget } ||
|
|
82
|
+
[0, with_sides_left_out(regions.fetch(-1).last)]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# ONE_LINE_CONTEXT_LINES when each side changed one line at most, else CONTEXT_LINES.
|
|
86
|
+
#: () -> Integer
|
|
87
|
+
def most_context
|
|
88
|
+
one_line = lines_of(changed_region(0)).all? { it.length <= 1 }
|
|
89
|
+
one_line ? ONE_LINE_CONTEXT_LINES : CONTEXT_LINES
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# region with its baseline side's lines left out, saying so, and its side now too when each side holds one line
|
|
93
|
+
# at most, whose change first_changed_lines' span shows whole (#1144); a longer region's other changed lines no
|
|
94
|
+
# hint shows, so its side now stays (#1069).
|
|
95
|
+
#: (Hash[String, Hash[String, untyped]]) -> Hash[String, Hash[String, untyped]]
|
|
96
|
+
def with_sides_left_out(region)
|
|
97
|
+
one_line = lines_of(region).all? { it.length <= 1 }
|
|
98
|
+
left_out = one_line ? %w[at_baseline now] : %w[at_baseline]
|
|
99
|
+
region.to_h do |name, side|
|
|
100
|
+
[name, left_out.include?(name) ? { "from_line" => side.fetch("from_line"), "omitted" => "too_long" } : side]
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Each side's lines in a changed region, none for a side left out.
|
|
105
|
+
#: (Hash[String, Hash[String, untyped]]) -> Array[Array[String]]
|
|
106
|
+
def lines_of(region) = region.values.map { |side| side.fetch("lines", []) }
|
|
107
|
+
|
|
108
|
+
# Each side's lines from context lines before its first difference to context lines after its last, with the
|
|
61
109
|
# 1-based line, within the member, the region starts at.
|
|
62
|
-
#: () -> Hash[String, Hash[String, untyped]]
|
|
63
|
-
def changed_region
|
|
110
|
+
#: (Integer) -> Hash[String, Hash[String, untyped]]
|
|
111
|
+
def changed_region(context)
|
|
64
112
|
same_start = common_length(@at_baseline, @now)
|
|
65
113
|
same_end = common_length(@at_baseline.drop(same_start).reverse, @now.drop(same_start).reverse)
|
|
66
|
-
from = [same_start -
|
|
114
|
+
from = [same_start - context, 0].max
|
|
67
115
|
{ "at_baseline" => @at_baseline, "now" => @now }.transform_values do |lines|
|
|
68
|
-
to = [lines.length - same_end +
|
|
116
|
+
to = [lines.length - same_end + context, lines.length].min
|
|
69
117
|
{ "from_line" => from + 1, "lines" => lines[from...to] || [] }
|
|
70
118
|
end
|
|
71
119
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "member"
|
|
6
|
-
require_relative "
|
|
6
|
+
require_relative "principle"
|
|
7
7
|
|
|
8
8
|
module Principles
|
|
9
9
|
# The domain: maps, audits and command steps, with every rule a schema cannot express.
|
|
@@ -34,7 +34,7 @@ module Principles
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# The base map with each declared member moved to its place in current, each keeping its role.
|
|
37
|
-
#: (
|
|
37
|
+
#: (Principle, Principle) -> Principle
|
|
38
38
|
def applied(base, current)
|
|
39
39
|
@moves.reduce(base) { |map, (from, to)| map.moving(from, located(current, to)) }
|
|
40
40
|
end
|
|
@@ -81,7 +81,7 @@ module Principles
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
# The current member to's place in its file, without its role.
|
|
84
|
-
#: (
|
|
84
|
+
#: (Principle, String) -> Hash[String, untyped]
|
|
85
85
|
def located(current, to)
|
|
86
86
|
unless current.members.taken?(to)
|
|
87
87
|
raise Error.new("unknown_member", "#{to} is not a member of #{current.id}",
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "../error"
|
|
5
|
+
require_relative "acknowledgement_refusal"
|
|
5
6
|
require_relative "audit_record"
|
|
6
|
-
require_relative "
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "principle_members"
|
|
8
|
+
require_relative "principle_history"
|
|
8
9
|
require_relative "member_state"
|
|
9
10
|
require_relative "locate_refusal"
|
|
10
11
|
|
|
@@ -21,26 +22,38 @@ module Principles
|
|
|
21
22
|
class Baselines
|
|
22
23
|
# The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
|
|
23
24
|
# where it is, read with the map as that commit held it; none outside git.
|
|
24
|
-
#: (Project,
|
|
25
|
+
#: (Project, PrincipleMembers) -> Baselines
|
|
25
26
|
def self.of(project, members)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
records = project.audit_records
|
|
28
|
+
mapped = mapped_where_it_is(project, members)
|
|
29
|
+
new(audit: records.readable(members.principle_id), mapped: mapped.transform_values { it.fetch("sha256") },
|
|
30
|
+
mapped_in: mapped.transform_values { it.fetch("commit") }, in_git: project.history.inside_git?,
|
|
31
|
+
hashes: records.hashes_to_compare(members.principle_id))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Each member's hash and commit at the commit that mapped it where it is, read with the map as that commit
|
|
35
|
+
# held it.
|
|
36
|
+
#: (Project, PrincipleMembers) -> Hash[String, Hash[String, String]]
|
|
37
|
+
def self.mapped_where_it_is(project, members)
|
|
38
|
+
PrincipleHistory.new(id: members.principle_id, history: project.history, principles: project.principles)
|
|
39
|
+
.mapped_baselines(members.keys)
|
|
32
40
|
end
|
|
33
41
|
|
|
34
42
|
# Whether the project is in git, so a member with no baseline is one no commit holds yet.
|
|
35
43
|
#: bool
|
|
36
44
|
attr_reader :in_git
|
|
37
45
|
|
|
46
|
+
# Whether a later copy wrote the principle's record, so its audits and acknowledgements wait on an upgrade.
|
|
47
|
+
#: () -> bool
|
|
48
|
+
def waiting? = @hashes.waiting?
|
|
49
|
+
|
|
38
50
|
# audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
|
|
39
|
-
# completed, so a one-member audit is offered only where one would be accepted (#626).
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
# completed, so a one-member audit is offered only where one would be accepted (#626). hashes is the member
|
|
52
|
+
# hashes the record holds, which a later copy may have written, so its members are compared read-only (#1066).
|
|
53
|
+
#: (audit: AuditRecord?, mapped: Hash[String, String], mapped_in: Hash[String, String], in_git: bool,
|
|
54
|
+
#| ?hashes: RecordedHashes) -> void
|
|
55
|
+
def initialize(audit:, mapped:, mapped_in:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE)
|
|
56
|
+
@hashes = hashes
|
|
44
57
|
@audit = audit #: AuditRecord?
|
|
45
58
|
@audit_base = audit&.base_commit #: String?
|
|
46
59
|
@mapped = mapped
|
|
@@ -53,11 +66,11 @@ module Principles
|
|
|
53
66
|
# hash at the commit that mapped it, with why no audit gave one; neither when it has no baseline.
|
|
54
67
|
#: (String) -> [String?, Hash[String, untyped]?]
|
|
55
68
|
def of(key)
|
|
56
|
-
if @
|
|
57
|
-
[
|
|
69
|
+
if (audited = @hashes.hash_for(key))
|
|
70
|
+
[audited, { "baseline" => "audit", "commit" => @audit_base }]
|
|
58
71
|
elsif @mapped.key?(key)
|
|
59
72
|
[@mapped[key], { "baseline" => "mapping_commit", "commit" => @mapped_in[key],
|
|
60
|
-
"no_audit_because" => @
|
|
73
|
+
"no_audit_because" => @hashes.empty? ? "no_audit_record" : "not_in_last_audit" }]
|
|
61
74
|
else
|
|
62
75
|
[nil, nil]
|
|
63
76
|
end
|
|
@@ -82,7 +95,7 @@ module Principles
|
|
|
82
95
|
#: (Member, String?) -> bool
|
|
83
96
|
def acknowledgeable?(member, now_sha256)
|
|
84
97
|
audit = @audit
|
|
85
|
-
@in_git && !audit.nil? &&
|
|
98
|
+
@in_git && !waiting? && !audit.nil? && AcknowledgementRefusal.of(audit, member, now_sha256:).nil?
|
|
86
99
|
end
|
|
87
100
|
end
|
|
88
101
|
|
|
@@ -90,18 +103,18 @@ module Principles
|
|
|
90
103
|
# refused when it was asked for, and listed as broken among every map.
|
|
91
104
|
#: (Project, String, ?listing_all: bool) -> MemberProblems
|
|
92
105
|
def self.for(project, id, listing_all: false)
|
|
93
|
-
members = project.
|
|
106
|
+
members = project.principles.find(id).members
|
|
94
107
|
new(members: members, now: project.current_by_key(members), baselines: Baselines.of(project, members))
|
|
95
108
|
rescue Error => e
|
|
96
109
|
raise unless listing_all
|
|
97
110
|
|
|
98
|
-
none =
|
|
111
|
+
none = PrincipleMembers.new(id, [])
|
|
99
112
|
new(members: none, now: {}, baselines: Baselines.of(project, none), unreadable: e.payload)
|
|
100
113
|
end
|
|
101
114
|
|
|
102
115
|
# now holds, for each member by key, its hash now or the refusal that says why it cannot be found.
|
|
103
116
|
# unreadable is the refusal for a map this tool could not read, which is listed as one broken entry.
|
|
104
|
-
#: (members:
|
|
117
|
+
#: (members: PrincipleMembers, now: Hash[String, untyped],
|
|
105
118
|
#| baselines: Baselines, ?unreadable: Hash[String, untyped]?) -> void
|
|
106
119
|
def initialize(members:, now:, baselines:, unreadable: nil)
|
|
107
120
|
@members = members
|
|
@@ -130,7 +143,12 @@ module Principles
|
|
|
130
143
|
# Whether a member an audit or acknowledgement assessed changed since, rather than only a member edited since
|
|
131
144
|
# the commit that mapped it, which no audit assessed (D44).
|
|
132
145
|
#: () -> bool
|
|
133
|
-
def assessed_change? =
|
|
146
|
+
def assessed_change? = changes_to_act_on.any? { |member| assessed?(member) }
|
|
147
|
+
|
|
148
|
+
# Whether a member no audit assessed was edited since the commit that mapped it, which --short exits 4 for
|
|
149
|
+
# when it is the only kind of change (D44).
|
|
150
|
+
#: () -> bool
|
|
151
|
+
def unassessed_change? = changes_to_act_on.any? { |member| !assessed?(member) }
|
|
134
152
|
|
|
135
153
|
# The entries whose own text changed since this tool last knew it, those an audit assessed first. Given a
|
|
136
154
|
# block, each gains "history", what the block makes of its member, the hash it was compared with, and its
|
|
@@ -188,7 +206,7 @@ module Principles
|
|
|
188
206
|
# one (D58, #731 R7).
|
|
189
207
|
#: () -> bool
|
|
190
208
|
def awaits_first_audit?
|
|
191
|
-
return false
|
|
209
|
+
return false if @baselines.waiting? || !@baselines.no_completed_audit?
|
|
192
210
|
|
|
193
211
|
bases = compared_with.keys
|
|
194
212
|
@baselines.in_git ? bases.any? { it != "no_baseline" } : !bases.empty?
|
|
@@ -222,6 +240,11 @@ module Principles
|
|
|
222
240
|
@members.select { |member| entry(member).fetch("state") == "changed" }
|
|
223
241
|
end
|
|
224
242
|
|
|
243
|
+
# The changed members this copy can act on: none while a later copy's record makes them wait on an upgrade,
|
|
244
|
+
# so they give --short neither exit 3 nor 4 (D85 V8, #1066).
|
|
245
|
+
#: () -> Array[Member]
|
|
246
|
+
def changes_to_act_on = @baselines.waiting? ? [] : changed_members
|
|
247
|
+
|
|
225
248
|
#: (Member) -> bool
|
|
226
249
|
def assessed?(member) = baseline(member.key).last&.fetch("baseline") == "audit"
|
|
227
250
|
|
|
@@ -241,7 +264,10 @@ module Principles
|
|
|
241
264
|
def compared(listed, key, sha)
|
|
242
265
|
then_sha, since = baseline(key)
|
|
243
266
|
return listed.merge("state" => "no_baseline") unless since
|
|
244
|
-
|
|
267
|
+
unless then_sha == sha
|
|
268
|
+
return listed.merge("state" => "changed", "since" => since,
|
|
269
|
+
**(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
|
|
270
|
+
end
|
|
245
271
|
|
|
246
272
|
listed.merge("state" => since["baseline"] == "mapping_commit" ? "unchanged_since_mapping" : "unchanged")
|
|
247
273
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# The moves that may repair a member this tool cannot find, each as the locator fields it keeps and those the agent
|
|
8
|
+
# fills in, which Views::MemberRepairs prints as move-member commands. A member whose file is gone moves to the
|
|
9
|
+
# path the agent finds, keeping its own section, passage or query, so a rename keeps its audit (#268). A member
|
|
10
|
+
# whose place in its file is gone moves within it, or into another file its text moved to (#378); a passage keeps
|
|
11
|
+
# its anchors, so a move cannot silently widen it to its whole new section (#251), but not an opening text that is
|
|
12
|
+
# gone, which a move repeating it would fail on again as printed (#1104); and it is given no section a passage
|
|
13
|
+
# located by its opening alone never had (#1134). Which fits is the agent's to judge.
|
|
14
|
+
class MemberRepairMoves
|
|
15
|
+
# The locator fields a member may give beside its path.
|
|
16
|
+
LOCATOR = %w[section starting_at ending_at query].freeze #: Array[String]
|
|
17
|
+
|
|
18
|
+
# member is the member's locator fields, as its map holds them; code is that of the refusal saying why it cannot
|
|
19
|
+
# be found.
|
|
20
|
+
#: (Hash[String, untyped], code: String?) -> void
|
|
21
|
+
def initialize(member, code:)
|
|
22
|
+
@member = given(member, LOCATOR) #: Hash[String, untyped]
|
|
23
|
+
@code = code
|
|
24
|
+
freeze
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Each move, as { "keep" => the locator fields it keeps, by name, "fill" => the fields the agent fills in }.
|
|
28
|
+
#: () -> Array[Hash[String, untyped]]
|
|
29
|
+
def to_a
|
|
30
|
+
return [move(@member, %w[path])] if @code == "unreadable_file"
|
|
31
|
+
return [move({}, %w[query])] if @member["query"]
|
|
32
|
+
|
|
33
|
+
kept = opening_lost? ? %w[ending_at] : %w[starting_at ending_at]
|
|
34
|
+
anchors = given(@member, kept)
|
|
35
|
+
opening = opening_lost? ? %w[starting_at] : []
|
|
36
|
+
section = @member.key?("section") ? %w[section] : []
|
|
37
|
+
[move(anchors, [*opening, *section]), move(anchors, [*opening, "path", *section])]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# The fields of member named in fields that it gives, in the order fields names them.
|
|
43
|
+
#: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
|
|
44
|
+
def given(member, fields) = fields.filter_map { [it, member[it]] unless member[it].nil? }.to_h.freeze
|
|
45
|
+
|
|
46
|
+
# Whether the passage's opening text is no longer in its file.
|
|
47
|
+
#: () -> bool
|
|
48
|
+
def opening_lost? = @code == "passage_not_found"
|
|
49
|
+
|
|
50
|
+
#: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
|
|
51
|
+
def move(keep, fill) = { "keep" => keep, "fill" => fill }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -51,7 +51,7 @@ module Principles
|
|
|
51
51
|
# The members sharing a line with the located one, beside map, its own: those in map, those of them on exactly
|
|
52
52
|
# its lines, and those in the other maps, as plain values, with whether the agent should check the text where
|
|
53
53
|
# one of those holds the other's lines without being a whole file (#756).
|
|
54
|
-
#: (
|
|
54
|
+
#: (Principle)
|
|
55
55
|
#| -> { overlaps: Array[String], same_lines_as: Array[String], mapped_elsewhere: Array[Hash[String, untyped]],
|
|
56
56
|
#| text_check: bool }
|
|
57
57
|
def facts_beside(map)
|
|
@@ -70,14 +70,14 @@ module Principles
|
|
|
70
70
|
# reports it.
|
|
71
71
|
#: (except: String) -> MembersElsewhere
|
|
72
72
|
def elsewhere(except:)
|
|
73
|
-
maps = @project.
|
|
73
|
+
maps = @project.principles
|
|
74
74
|
MembersElsewhere.new((maps.ids - [except]).flat_map { |id| sharing_in(maps, id) })
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
private
|
|
78
78
|
|
|
79
79
|
# The members of map id sharing a line with the located member, or none when that map cannot be read.
|
|
80
|
-
#: (
|
|
80
|
+
#: (MappedPrinciples, String) -> Array[MemberElsewhere]
|
|
81
81
|
def sharing_in(maps, id)
|
|
82
82
|
sharing(maps.find(id).members.to_a).map do |member, found|
|
|
83
83
|
MemberElsewhere.new(principle_id: id, member:, span: found.span(whole_file: member.whole_file?),
|
|
@@ -47,8 +47,8 @@ module Principles
|
|
|
47
47
|
def refusal(message, rerun: nil, note: "")
|
|
48
48
|
Error.new("broken_members", message,
|
|
49
49
|
"For each member listed, say whether it moved or is gone, and run the matching command in its " \
|
|
50
|
-
"repair_with: the move-member, with its NEW_PATH, HEADING or QUERY filled in, if
|
|
51
|
-
"remove-member if it is gone. #{note}#{REPAIR}" \
|
|
50
|
+
"repair_with: the move-member, with its NEW_PATH, HEADING, NEW_OPENING_TEXT or QUERY filled in, if " \
|
|
51
|
+
"it moved, or the remove-member if it is gone. #{note}#{REPAIR}" \
|
|
52
52
|
"#{rerun ? "\nThen run it again: #{rerun}" : " Then run the command again."}")
|
|
53
53
|
.including(**({ "principle" => @principle } if @principle), "members" => members, "missing_files" => to_a)
|
|
54
54
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "template_placeholders"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# The findings an assessment answer raises, as start-audit --as template prints one to fill: a finding sent back
|
|
10
|
+
# exactly as printed raises none, and one otherwise filled may not keep a text field as printed (#1010).
|
|
11
|
+
class NewFindings
|
|
12
|
+
# The text fields of the printed finding, which their own check accepts as written text, so a field left as
|
|
13
|
+
# printed in a finding otherwise filled is refused here (#1010). A member id or evidence left as printed is
|
|
14
|
+
# refused by its own check.
|
|
15
|
+
TEXT = TemplatePlaceholders.new(
|
|
16
|
+
{ "id" => "Only for a problem you found: an id such as F1. Leave this finding as printed to raise none",
|
|
17
|
+
"problem" => "What is wrong, in the members' own words",
|
|
18
|
+
"consequence" => "What it costs an agent that reads them",
|
|
19
|
+
"proposed_action" => "What would fix it. Fixing, deferring or accepting it is decided in the correction" }
|
|
20
|
+
) #: TemplatePlaceholders
|
|
21
|
+
|
|
22
|
+
# The finding the template printed alone gives to fill, which an answer leaves as printed to raise none; whether
|
|
23
|
+
# to fix, defer or accept a finding is the correction's, so the finding itself carries none (#1010).
|
|
24
|
+
TEMPLATE = {
|
|
25
|
+
"id" => TEXT.fetch("id"), "member_ids" => ["The id of each member it concerns"],
|
|
26
|
+
"problem" => TEXT.fetch("problem"), "consequence" => TEXT.fetch("consequence"),
|
|
27
|
+
"proposed_action" => TEXT.fetch("proposed_action"),
|
|
28
|
+
"evidence" => [{ "path" => "Where it shows: a path, with heading, starting_at or query to narrow it" }]
|
|
29
|
+
}.freeze #: Hash[String, untyped]
|
|
30
|
+
|
|
31
|
+
# findings is the answer's findings as sent, a list once its shape is checked.
|
|
32
|
+
#: (Array[untyped]) -> void
|
|
33
|
+
def initialize(findings)
|
|
34
|
+
@findings = findings
|
|
35
|
+
freeze
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The findings the answer raises: each but one sent back as the template printed it.
|
|
39
|
+
#: () -> Array[untyped]
|
|
40
|
+
def raised = @findings.reject { it == TEMPLATE }
|
|
41
|
+
|
|
42
|
+
# Each text field a raised finding leaves as the template printed it, named by the finding's place and the
|
|
43
|
+
# field, with its pointer, which the answer refuses with every other judgement left so (#991, #1010).
|
|
44
|
+
#: () -> Hash[String, String]
|
|
45
|
+
def left_as_printed
|
|
46
|
+
@findings.each_with_index.flat_map do |finding, index|
|
|
47
|
+
next [] if !finding.is_a?(Hash) || finding == TEMPLATE
|
|
48
|
+
|
|
49
|
+
TEXT.to_h.keys.select { TEXT.left?(it, finding[it]) }
|
|
50
|
+
.map { ["Finding #{index + 1} #{it}", "/findings/#{index}/#{it}"] }
|
|
51
|
+
end.to_h
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|