principles 0.0.4 → 0.0.6
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/after_commit_hook_options.rb +4 -1
- data/lib/principles/cli.rb +3 -1
- data/lib/principles/command_line.rb +38 -26
- data/lib/principles/command_routes.rb +11 -4
- data/lib/principles/controllers/acknowledgement.rb +93 -17
- data/lib/principles/controllers/answer.rb +45 -76
- data/lib/principles/controllers/answer_phase.rb +54 -0
- data/lib/principles/controllers/assessment.rb +46 -11
- data/lib/principles/controllers/audit.rb +17 -6
- data/lib/principles/controllers/audit_completion.rb +9 -5
- data/lib/principles/controllers/command.rb +5 -4
- data/lib/principles/controllers/correction.rb +22 -10
- data/lib/principles/controllers/full_audit_request.rb +11 -1
- data/lib/principles/controllers/guidance_search_paths.rb +31 -0
- data/lib/principles/controllers/inventory.rb +15 -29
- data/lib/principles/controllers/mapping.rb +9 -1
- data/lib/principles/controllers/member_addition.rb +65 -0
- data/lib/principles/controllers/member_entries.rb +6 -24
- data/lib/principles/controllers/member_problems_report.rb +13 -6
- data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
- data/lib/principles/controllers/members_to_assess.rb +21 -13
- data/lib/principles/controllers/meta_principle_setup.rb +1 -1
- data/lib/principles/controllers/repoint.rb +22 -23
- data/lib/principles/controllers/survey.rb +60 -0
- data/lib/principles/data/audit_files.rb +4 -0
- data/lib/principles/data/bounded_file.rb +9 -4
- data/lib/principles/data/candidate_files_found.rb +48 -13
- data/lib/principles/data/command-steps.json +85 -24
- data/lib/principles/data/committed_tree.rb +84 -0
- data/lib/principles/data/first_parent_log.rb +48 -0
- data/lib/principles/data/first_parent_range.rb +122 -0
- data/lib/principles/data/git_command.rb +37 -0
- data/lib/principles/data/guidance_search_paths_file.rb +107 -0
- data/lib/principles/data/map_files.rb +35 -10
- data/lib/principles/data/principles_directory.rb +40 -0
- data/lib/principles/data/principles_subfolder.rb +39 -16
- data/lib/principles/data/project_files.rb +22 -11
- data/lib/principles/data/repository.rb +55 -29
- data/lib/principles/data/requested_candidate_files.rb +43 -0
- data/lib/principles/data/running_version.rb +3 -5
- data/lib/principles/data/schema_check.rb +16 -6
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +18 -5
- data/lib/principles/data/schemas/answer-guide.schema.json +255 -68
- data/lib/principles/data/schemas/audit-record.schema.json +10 -1
- data/lib/principles/data/schemas/command-steps.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
- data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
- data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
- data/lib/principles/data/verified_head.rb +162 -0
- data/lib/principles/invocation_options.rb +3 -3
- data/lib/principles/models/acknowledgement.rb +95 -84
- data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
- 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 +0 -45
- data/lib/principles/models/assessment_left_as_printed.rb +81 -0
- data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
- data/lib/principles/models/audit_record.rb +12 -16
- data/lib/principles/models/audit_records.rb +52 -23
- data/lib/principles/models/candidate_files.rb +44 -10
- data/lib/principles/models/candidate_inventory.rb +69 -8
- data/lib/principles/models/candidate_outline.rb +195 -0
- data/lib/principles/models/captured_head.rb +72 -0
- data/lib/principles/models/carried_member.rb +42 -0
- data/lib/principles/models/check_since_last_audit.rb +20 -11
- data/lib/principles/models/command_steps.rb +17 -1
- data/lib/principles/models/declared_map_changes.rb +29 -12
- data/lib/principles/models/declared_member_removals.rb +75 -0
- data/lib/principles/models/disposition.rb +4 -2
- data/lib/principles/models/fix_only_fields.rb +12 -0
- data/lib/principles/models/frontmatter_fields.rb +9 -8
- data/lib/principles/models/guidance_search_path.rb +26 -0
- data/lib/principles/models/guidance_search_paths.rb +57 -0
- data/lib/principles/models/instruction_named.rb +35 -0
- data/lib/principles/models/left_as_printed.rb +39 -0
- data/lib/principles/models/line_span.rb +6 -0
- data/lib/principles/models/loaded_files.rb +1 -2
- data/lib/principles/models/loading_scope.rb +61 -0
- data/lib/principles/models/locator.rb +6 -0
- data/lib/principles/models/mapped_principles.rb +39 -37
- data/lib/principles/models/member_assessments.rb +9 -31
- data/lib/principles/models/member_file.rb +20 -47
- data/lib/principles/models/member_hashes_as_written.rb +10 -6
- data/lib/principles/models/member_history.rb +7 -5
- data/lib/principles/models/member_lines.rb +63 -15
- data/lib/principles/models/member_loading_scopes.rb +49 -0
- data/lib/principles/models/member_loads.rb +4 -0
- data/lib/principles/models/member_mapping_run.rb +30 -0
- data/lib/principles/models/member_moves.rb +4 -0
- data/lib/principles/models/member_problems.rb +63 -33
- data/lib/principles/models/member_region.rb +129 -0
- data/lib/principles/models/member_repair_moves.rb +52 -0
- data/lib/principles/models/member_snapshots.rb +14 -1
- data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
- data/lib/principles/models/meta_principle.rb +14 -0
- data/lib/principles/models/missing_files.rb +2 -2
- data/lib/principles/models/open_findings_elsewhere.rb +4 -0
- data/lib/principles/models/other_templates_placeholders.rb +81 -42
- data/lib/principles/models/outline_budget.rb +142 -0
- data/lib/principles/models/outline_group.rb +31 -0
- data/lib/principles/models/outline_section.rb +56 -0
- data/lib/principles/models/principle.rb +14 -7
- data/lib/principles/models/principle_file_revision.rb +48 -0
- data/lib/principles/models/principle_history.rb +46 -19
- data/lib/principles/models/principle_lineage.rb +118 -0
- data/lib/principles/models/principle_map_revision.rb +39 -0
- data/lib/principles/models/principle_mapping_history.rb +132 -0
- data/lib/principles/models/principle_members.rb +25 -0
- data/lib/principles/models/principle_predecessor.rb +45 -0
- data/lib/principles/models/principle_publication.rb +177 -0
- data/lib/principles/models/principle_revision.rb +104 -0
- data/lib/principles/models/prior_decision_fields.rb +3 -2
- data/lib/principles/models/prior_finding_decision.rb +14 -4
- data/lib/principles/models/problem_report.rb +17 -5
- data/lib/principles/models/project.rb +46 -39
- data/lib/principles/models/project_history.rb +45 -25
- data/lib/principles/models/quoted_change.rb +137 -0
- data/lib/principles/models/record_format.rb +12 -2
- data/lib/principles/models/recorded_entry.rb +6 -0
- data/lib/principles/models/recorded_hashes.rb +7 -3
- data/lib/principles/models/recorded_members.rb +27 -15
- 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 +5 -14
- data/lib/principles/models/sent_answer.rb +61 -0
- data/lib/principles/models/shape_problems_beside.rb +40 -0
- data/lib/principles/models/submitted_answer.rb +34 -0
- data/lib/principles/models/survey_search_paths.rb +26 -0
- data/lib/principles/models/template_placeholders.rb +34 -4
- data/lib/principles/models/text_within.rb +55 -0
- data/lib/principles/models/unchecked_members.rb +76 -0
- data/lib/principles/models/uncommitted_files.rb +50 -0
- data/lib/principles/models/unknown_principle.rb +29 -0
- data/lib/principles/models/write_up_opening.rb +21 -4
- data/lib/principles/positional_arguments.rb +37 -0
- data/lib/principles/session_start_options.rb +2 -2
- data/lib/principles/start_audit_options.rb +19 -4
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +23 -11
- data/lib/principles/views/added_member.rb +41 -0
- data/lib/principles/views/answered_request.rb +21 -0
- data/lib/principles/views/assessed_members.rb +43 -10
- data/lib/principles/views/assessment_request.rb +91 -31
- data/lib/principles/views/audit_result.rb +40 -28
- data/lib/principles/views/candidate_files_result.rb +85 -19
- data/lib/principles/views/candidate_outlines_result.rb +25 -0
- data/lib/principles/views/check_notes.rb +44 -0
- data/lib/principles/views/check_result_template.rb +14 -23
- data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
- data/lib/principles/views/correction_request.rb +32 -1
- data/lib/principles/views/guidance_search_paths_result.rb +26 -0
- data/lib/principles/views/instruction.rb +74 -0
- data/lib/principles/views/json_with_entries_on_lines.rb +59 -0
- data/lib/principles/views/loads_to_check_result.rb +2 -2
- data/lib/principles/views/map_added_to.rb +56 -2
- data/lib/principles/views/map_result.rb +23 -43
- data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
- data/lib/principles/views/member_change_since_baseline.rb +23 -5
- data/lib/principles/views/member_repairs.rb +22 -52
- data/lib/principles/views/members_a_commit_changed.rb +16 -6
- data/lib/principles/views/new_loading_scope.rb +31 -0
- data/lib/principles/views/one_member_check_result_template.rb +47 -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 +24 -29
- data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
- data/lib/principles/views/prior_findings_result.rb +23 -15
- data/lib/principles/views/problem_lines.rb +3 -1
- data/lib/principles/views/problem_result.rb +8 -3
- 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 +67 -48
- 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 +4 -16
- 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/say-what-observed-means.md +4 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +16 -3
- data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
- 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-an-existing-or-new-principle.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +11 -5
- data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
- 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/find-a-principle-to-map/survey-a-later-range.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
- data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +55 -7
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +9 -8
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
- data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +27 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
- data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -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/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 +9 -6
- 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 +3 -3
- data/lib/principles/views/request_part.rb +16 -8
- data/lib/principles/views/request_parts.rb +4 -0
- metadata +92 -7
- data/lib/principles/models/candidate_listing.rb +0 -32
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
- data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
- data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "../data/project_files"
|
|
5
5
|
require_relative "../data/project_root"
|
|
6
|
-
require_relative "../data/schema_check"
|
|
7
6
|
require_relative "../data/map_files"
|
|
8
7
|
require_relative "../data/audit_files"
|
|
9
8
|
require_relative "../data/principles_subfolder"
|
|
@@ -23,15 +22,18 @@ require_relative "missing_files"
|
|
|
23
22
|
require_relative "locate_refusal"
|
|
24
23
|
require_relative "audit_records"
|
|
25
24
|
require_relative "project_history"
|
|
25
|
+
require_relative "principle_history"
|
|
26
26
|
require_relative "principles_folder_move"
|
|
27
|
-
require_relative "
|
|
27
|
+
require_relative "sent_answer"
|
|
28
|
+
require_relative "guidance_search_paths"
|
|
29
|
+
require_relative "survey_search_paths"
|
|
28
30
|
|
|
29
31
|
module Principles
|
|
30
32
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
31
33
|
module Models
|
|
32
34
|
# The user's project as this tool reads it: its instruction files, each member's text, the answers an
|
|
33
35
|
# agent hands in, and the maps, audit records and git history kept beside them. Controllers reach the
|
|
34
|
-
# project only through this model. It is handed its
|
|
36
|
+
# project only through this model. It is handed its five data adapters, so a spec can hand it stand-ins
|
|
35
37
|
# that meet the same contracts (#337).
|
|
36
38
|
class Project
|
|
37
39
|
# An implicit invocation reuses its nearest established project; an explicit root uses .at directly.
|
|
@@ -44,16 +46,20 @@ module Principles
|
|
|
44
46
|
files = Data::ProjectFiles.new(root)
|
|
45
47
|
new(files: files, maps: Data::MapFiles.new(Data::PrinciplesSubfolder.new(files.root, "maps")),
|
|
46
48
|
audits: Data::AuditFiles.new(Data::PrinciplesSubfolder.new(files.root, "audits")),
|
|
47
|
-
repository: Data::Repository.new(files.root)
|
|
49
|
+
repository: Data::Repository.new(files.root),
|
|
50
|
+
guidance_search_paths: Data::GuidanceSearchPathsFile.new(Data::PrinciplesDirectory.new(files.root)))
|
|
48
51
|
end
|
|
49
52
|
|
|
50
53
|
#: (files: Data::ProjectFiles, maps: Data::MapFiles, audits: Data::AuditFiles,
|
|
51
|
-
#| repository: Data::Repository) -> void
|
|
52
|
-
def initialize(files:, maps:, audits:, repository:)
|
|
54
|
+
#| repository: Data::Repository, guidance_search_paths: Data::GuidanceSearchPathsFile) -> void
|
|
55
|
+
def initialize(files:, maps:, audits:, repository:, guidance_search_paths:)
|
|
53
56
|
@files = files
|
|
54
57
|
@maps = maps
|
|
55
58
|
@audits = audits
|
|
56
59
|
@repository = repository
|
|
60
|
+
@guidance_search_paths = guidance_search_paths
|
|
61
|
+
@history = nil #: ProjectHistory?
|
|
62
|
+
@principle_histories = {} #: Hash[[String, PrincipleMappingHistory?], PrincipleHistory]
|
|
57
63
|
end
|
|
58
64
|
|
|
59
65
|
# The project's root, resolved.
|
|
@@ -65,7 +71,7 @@ module Principles
|
|
|
65
71
|
#: () -> MappedPrinciples
|
|
66
72
|
def principles
|
|
67
73
|
refuse_unmoved_folder
|
|
68
|
-
MappedPrinciples.new(@maps)
|
|
74
|
+
MappedPrinciples.new(@maps, history)
|
|
69
75
|
end
|
|
70
76
|
|
|
71
77
|
#: () -> AuditRecords
|
|
@@ -74,9 +80,24 @@ module Principles
|
|
|
74
80
|
AuditRecords.new(@audits, history)
|
|
75
81
|
end
|
|
76
82
|
|
|
83
|
+
#: () -> GuidanceSearchPaths
|
|
84
|
+
def guidance_search_paths
|
|
85
|
+
refuse_unmoved_folder
|
|
86
|
+
GuidanceSearchPaths.read(@guidance_search_paths)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# The project's history, one for the whole command, so every read names the HEAD it first read (#1161).
|
|
77
90
|
#: () -> ProjectHistory
|
|
78
91
|
def history
|
|
79
|
-
ProjectHistory.new(@repository, @files)
|
|
92
|
+
@history ||= ProjectHistory.new(@repository, @files)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Each principle's history view belongs to this command, sharing its captured project history.
|
|
96
|
+
#: (String, ?mapping: PrincipleMappingHistory?) -> PrincipleHistory
|
|
97
|
+
def principle_history(id, mapping: nil)
|
|
98
|
+
key = [id.dup.freeze, mapping].freeze #: [String, PrincipleMappingHistory?]
|
|
99
|
+
@principle_histories[key] ||= PrincipleHistory.new(id: key.first, history: history,
|
|
100
|
+
principles: principles, mapping: mapping)
|
|
80
101
|
end
|
|
81
102
|
|
|
82
103
|
# Whether two paths name one file, as their symbolic links lead them, so an edit through either is an edit
|
|
@@ -90,6 +111,10 @@ module Principles
|
|
|
90
111
|
member_file(locator.path).locate(locator)
|
|
91
112
|
end
|
|
92
113
|
|
|
114
|
+
# Check the location an add or move is about to persist, with the authoring-only ending constraint.
|
|
115
|
+
#: (Locator) -> Hash[String, untyped]
|
|
116
|
+
def locate_for_authoring(locator) = member_file(locator.path).locate_for_authoring(locator)
|
|
117
|
+
|
|
93
118
|
# The text locator finds now, as one value: its path, its lines and the hash of what it says (#909).
|
|
94
119
|
#: (Locator) -> LocatedText
|
|
95
120
|
def located_text(locator) = LocatedText.of(locate(locator))
|
|
@@ -121,16 +146,7 @@ module Principles
|
|
|
121
146
|
# Each of map's members by id, where it is in its file now and the hash of what it says there. It is
|
|
122
147
|
# refused once, listing every member that cannot be found or read, so the agent repairs them together.
|
|
123
148
|
#: (Principle) -> MemberSnapshots
|
|
124
|
-
def snapshots(map)
|
|
125
|
-
broken = [] #: Array[Hash[String, untyped]]
|
|
126
|
-
found = map.members.to_h do |member|
|
|
127
|
-
[member.id, locate(member.locator)]
|
|
128
|
-
rescue Error => e
|
|
129
|
-
broken << { "id" => member.id }.merge(e.payload.except("status"))
|
|
130
|
-
[member.id, {}]
|
|
131
|
-
end
|
|
132
|
-
broken.empty? ? MemberSnapshots.new(found) : refuse_broken(map.id, broken)
|
|
133
|
-
end
|
|
149
|
+
def snapshots(map) = MemberSnapshots.read(self, map)
|
|
134
150
|
|
|
135
151
|
# The superseded, git-ignored file where an older version kept audit runs; this version never reads it.
|
|
136
152
|
OLDER_STATE = ".memeplex/state.json" #: String
|
|
@@ -191,30 +207,21 @@ module Principles
|
|
|
191
207
|
#: () -> EntryFiles
|
|
192
208
|
def entry_files = EntryFiles.read(@files, history)
|
|
193
209
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
ANSWER_HEAD = %w[request_id basis].freeze
|
|
210
|
+
# An answer to a phase's request from file, where - means it was read from stdin, its head checked against
|
|
211
|
+
# the phase's answer schema (D29) and the rest left to check once its request is known (#1052).
|
|
212
|
+
#: (String, stdin: String?, phase: String) -> SentAnswer
|
|
213
|
+
def answer(file, stdin:, phase:) = SentAnswer.read(@files, file, stdin:, phase:)
|
|
199
214
|
|
|
200
|
-
#
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
parsed = file == "-" ? @files.parse_json(stdin.to_s, "-") : @files.read_json(file)
|
|
207
|
-
check = Data::SchemaCheck.new("#{phase}-answer")
|
|
208
|
-
check.only(ANSWER_HEAD).checked(parsed, code: "invalid_answer", source: file, repair: ANSWER_REPAIR)
|
|
209
|
-
yield(parsed.slice(*ANSWER_HEAD)).refuse_in(parsed, file) if block_given?
|
|
210
|
-
check.checked(parsed, code: "invalid_answer", source: file, repair: ANSWER_REPAIR)
|
|
215
|
+
# What list-candidate-files found, as CandidateInventory reads it from the project, after a commit when given.
|
|
216
|
+
#: (?after: String?, ?also: Array[String]) -> CandidateInventory
|
|
217
|
+
def candidate_files(after: nil, also: [])
|
|
218
|
+
mapped = after ? principles.readable_paths : []
|
|
219
|
+
search_paths = SurveySearchPaths.new(recorded: guidance_search_paths.globs, also:)
|
|
220
|
+
CandidateInventory.read(@files, history, search_paths:, after:, mapped:)
|
|
211
221
|
end
|
|
212
222
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
def candidate_files
|
|
216
|
-
CandidateInventory.found(@files.inventory, history)
|
|
217
|
-
end
|
|
223
|
+
#: (Array[String]) -> CandidateInventory
|
|
224
|
+
def candidate_outlines(paths) = CandidateInventory.requested(@files, history, paths:)
|
|
218
225
|
|
|
219
226
|
private
|
|
220
227
|
|
|
@@ -9,6 +9,8 @@ require_relative "principle_members"
|
|
|
9
9
|
require_relative "member"
|
|
10
10
|
require_relative "member_file"
|
|
11
11
|
require_relative "commits_brought_in"
|
|
12
|
+
require_relative "uncommitted_files"
|
|
13
|
+
require_relative "captured_head"
|
|
12
14
|
|
|
13
15
|
module Principles
|
|
14
16
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -28,6 +30,7 @@ module Principles
|
|
|
28
30
|
def initialize(repository, files)
|
|
29
31
|
@repository = repository
|
|
30
32
|
@files = files
|
|
33
|
+
@head = CapturedHead.new(repository) #: CapturedHead
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
# Which of paths, and of the links and files they lead through, git does not track, which an audit refuses as
|
|
@@ -44,6 +47,25 @@ module Principles
|
|
|
44
47
|
#: () -> bool
|
|
45
48
|
def inside_git? = @repository.inside?
|
|
46
49
|
|
|
50
|
+
# The full sha of the commit revision names, which a survey of the commits after it starts from. Refuses outside
|
|
51
|
+
# git, where there are no commits, and a revision git resolves to no commit (#1171).
|
|
52
|
+
#: (String) -> String
|
|
53
|
+
def commit_named(revision)
|
|
54
|
+
unless @repository.inside?
|
|
55
|
+
raise Error.new("range_needs_git", "--commits-after needs git, to read the commits after #{revision}",
|
|
56
|
+
"To survey every candidate instead, run it without --commits-after.")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
@repository.commit_of(revision) or
|
|
60
|
+
raise Error.new("unknown_revision", "git resolves #{revision} to no commit",
|
|
61
|
+
"Name a commit git knows, such as a sha from git log, a branch or HEAD~3.")
|
|
62
|
+
.including("revision" => revision)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Each file the commits after commit, a full sha, changed up to HEAD that the project still holds (#1171).
|
|
66
|
+
#: (String) -> Array[String]
|
|
67
|
+
def changed_after(commit) = @repository.changed_since(commit).select { |path| @files.file?(path) }
|
|
68
|
+
|
|
47
69
|
# The project's files, other than paths, that differ from HEAD or are untracked, ignored ones aside; nil
|
|
48
70
|
# outside git or when there are none. A check and an answer's evidence read them as they are now (#409).
|
|
49
71
|
#: (Array[String]) -> Array[String]?
|
|
@@ -58,17 +80,7 @@ module Principles
|
|
|
58
80
|
# pointing at it, so a fresh clone would find nothing there (#760). Nothing outside git.
|
|
59
81
|
#: (String) -> void
|
|
60
82
|
def refuse_uncommitted_write_up(path)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
dirty = uncommitted([path])
|
|
64
|
-
return if dirty.empty?
|
|
65
|
-
|
|
66
|
-
linked = dirty - [path]
|
|
67
|
-
raise Error.new("uncommitted_files",
|
|
68
|
-
"The write-up at #{path} differs from the last commit" +
|
|
69
|
-
(linked.empty? ? "" : ", through #{linked.join(", ")}"),
|
|
70
|
-
"The record will point at the write-up as committed.\n" \
|
|
71
|
-
"Commit the write-up, then submit the same answer again.")
|
|
83
|
+
UncommittedFiles.new(uncommitted([path])).refuse_write_up(path) if @repository.inside?
|
|
72
84
|
end
|
|
73
85
|
|
|
74
86
|
# The commit an audit of id is based on: HEAD, refused while any of files, or a file their links lead to,
|
|
@@ -77,15 +89,8 @@ module Principles
|
|
|
77
89
|
def base_commit(id, files)
|
|
78
90
|
return unless @repository.inside?
|
|
79
91
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
raise Error.new("uncommitted_files", "The map or members of #{id} differ from the last commit: " \
|
|
83
|
-
"#{dirty.join(", ")}",
|
|
84
|
-
"An audit assesses the map and members as committed, so its record can name the commit " \
|
|
85
|
-
"it began from.\nCommit them, then start it again: #{Error::EXECUTABLE} start-audit #{id}")
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
@repository.head
|
|
92
|
+
UncommittedFiles.new(uncommitted(files)).refuse_audit(id)
|
|
93
|
+
head
|
|
89
94
|
end
|
|
90
95
|
|
|
91
96
|
# path's text at commit, or nil when commit does not hold it.
|
|
@@ -159,9 +164,14 @@ module Principles
|
|
|
159
164
|
#: (Array[String]) -> Array[String]
|
|
160
165
|
def existing(paths) = paths.select { |path| @files.file?(path) }
|
|
161
166
|
|
|
162
|
-
# The commit
|
|
167
|
+
# The commit HEAD named when this history first asked, kept for the rest of the command, so a commit landing
|
|
168
|
+
# while it runs leaves no read at one commit and the next at another (#1161); nil outside git. A history serves
|
|
169
|
+
# one command at most, so the next command sees the new commit.
|
|
163
170
|
#: () -> String?
|
|
164
|
-
def head =
|
|
171
|
+
def head = @head.commit
|
|
172
|
+
|
|
173
|
+
#: () -> CapturedHead
|
|
174
|
+
def captured_head = @head
|
|
165
175
|
|
|
166
176
|
# The commits after commit that changed path, a link on the way to it or the file they lead to, newest
|
|
167
177
|
# first.
|
|
@@ -170,11 +180,11 @@ module Principles
|
|
|
170
180
|
@repository.commits_since(commit, through_links([path]))
|
|
171
181
|
end
|
|
172
182
|
|
|
173
|
-
# Every commit on
|
|
174
|
-
# after it.
|
|
183
|
+
# Every commit on the first-parent line of head, the HEAD this history first named, that changed any of paths,
|
|
184
|
+
# newest first; with since, only those after it.
|
|
175
185
|
#: (Array[String], ?since: String?) -> Array[Hash[String, String]]
|
|
176
186
|
def commits_touching(paths, since: nil)
|
|
177
|
-
@repository.commits_touching(through_links(paths), since: since)
|
|
187
|
+
@repository.commits_touching(through_links(paths), since: since, up_to: head || "HEAD")
|
|
178
188
|
end
|
|
179
189
|
|
|
180
190
|
# The commits after commit, up to HEAD, that one move of HEAD brought in, whatever they changed (D73).
|
|
@@ -191,6 +201,16 @@ module Principles
|
|
|
191
201
|
!@repository.commits_since(commit, [*OWN_FOLDERS, *through_links(paths)]).empty?
|
|
192
202
|
end
|
|
193
203
|
|
|
204
|
+
# Whether one raw entry belongs to the permission-specific captured head.
|
|
205
|
+
#: (String) -> bool
|
|
206
|
+
def entry_at_head?(path) = @head.entry?(path)
|
|
207
|
+
|
|
208
|
+
#: (String, Array[String]) -> Array[String]
|
|
209
|
+
def commits_touching_since(base, paths) = @head.commits_touching_since(base, paths)
|
|
210
|
+
|
|
211
|
+
#: (String, String) -> bool
|
|
212
|
+
def entry_at?(revision, path) = @head.entry_at?(revision, path)
|
|
213
|
+
|
|
194
214
|
private
|
|
195
215
|
|
|
196
216
|
# paths, each with the links on the way to it and the file they lead to, once each.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "member_lines"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# A one-member audit's change as its answer quotes it (D33): a line of the member before the change and one after,
|
|
11
|
+
# each a whole line of its side or a fragment long enough to show the edit that only its side reads (#352, #379).
|
|
12
|
+
class QuotedChange
|
|
13
|
+
# One side of the change a quote is checked against: the member's lines then, and when they read.
|
|
14
|
+
class SideOfTheChange
|
|
15
|
+
#: String
|
|
16
|
+
attr_reader :reads_at
|
|
17
|
+
|
|
18
|
+
#: (Array[String], String) -> void
|
|
19
|
+
def initialize(lines, reads_at)
|
|
20
|
+
@lines = lines.map(&:chomp) #: Array[String]
|
|
21
|
+
@reads_at = reads_at
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#: (String) -> bool
|
|
26
|
+
def whole_line?(quote) = @lines.include?(quote)
|
|
27
|
+
|
|
28
|
+
#: (String) -> bool
|
|
29
|
+
def holds?(text) = @lines.any? { |line| line.include?(text) }
|
|
30
|
+
|
|
31
|
+
# Its first line the other side lacks, or "" when it has none, as after a pure insertion on the other side.
|
|
32
|
+
#: (SideOfTheChange) -> String
|
|
33
|
+
def first_line_absent_from(other) = @lines.find { |line| !other.whole_line?(line) } || ""
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The fewest characters a quoted fragment of a line may have, so it shows which edit was read (#352).
|
|
37
|
+
FRAGMENT_LENGTH = 30
|
|
38
|
+
|
|
39
|
+
# The longest changed line the hint gives whole, beyond which it gives the span the edit changed (#1103).
|
|
40
|
+
LONG_LINE = 200
|
|
41
|
+
|
|
42
|
+
# lines holds the member's lines at its baseline commit and at HEAD; member_id names it in a refusal.
|
|
43
|
+
#: (MemberLines, member_id: String) -> void
|
|
44
|
+
def initialize(lines, member_id:)
|
|
45
|
+
@then = SideOfTheChange.new(lines.at_baseline, "before the change") #: SideOfTheChange
|
|
46
|
+
@now = SideOfTheChange.new(lines.now, "at HEAD") #: SideOfTheChange
|
|
47
|
+
@member_id = member_id
|
|
48
|
+
freeze
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The first line on each side the other lacks, which the request hints the quotes from (#1016); of a pair with a
|
|
52
|
+
# line over LONG_LINE characters, the span each side's edit changed, so a small edit is found without comparing
|
|
53
|
+
# two long lines by eye, and the request does not carry them again (#1103).
|
|
54
|
+
#: () -> Hash[String, String]
|
|
55
|
+
def first_changed_lines
|
|
56
|
+
old_line = @then.first_line_absent_from(@now)
|
|
57
|
+
new_line = @now.first_line_absent_from(@then)
|
|
58
|
+
whole = { "old_line" => old_line, "new_line" => new_line }
|
|
59
|
+
return whole if whole.values.all? { it.length <= LONG_LINE }
|
|
60
|
+
|
|
61
|
+
{ "old_line" => changed_span(old_line, new_line, @then, @now),
|
|
62
|
+
"new_line" => changed_span(new_line, old_line, @now, @then) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Refuses an old_line not found before the change, or a new_line not found after it.
|
|
66
|
+
#: (old_line: String, new_line: String) -> void
|
|
67
|
+
def check(old_line:, new_line:)
|
|
68
|
+
quoted(old_line, @then, @now)
|
|
69
|
+
quoted(new_line, @now, @then)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
# line's characters between those it shares with other_line from the start and from the end, with
|
|
75
|
+
# FRAGMENT_LENGTH more on each side, widened to whole words, when that fragment is a quote only side holds; else
|
|
76
|
+
# the whole line.
|
|
77
|
+
#: (String, String, SideOfTheChange, SideOfTheChange) -> String
|
|
78
|
+
def changed_span(line, other_line, side, other)
|
|
79
|
+
edit = edited(line, other_line)
|
|
80
|
+
from = word_start(line, [edit.begin - FRAGMENT_LENGTH, 0].max)
|
|
81
|
+
span = line[from...word_end(line, edit.end + FRAGMENT_LENGTH)].to_s
|
|
82
|
+
only_on?(span, side, other) ? span : line
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# The start of the word at index in line, when it starts within FRAGMENT_LENGTH before it; else index, so a
|
|
86
|
+
# span of a line without spaces keeps its context (#1144).
|
|
87
|
+
#: (String, Integer) -> Integer
|
|
88
|
+
def word_start(line, index)
|
|
89
|
+
return index if index.zero?
|
|
90
|
+
|
|
91
|
+
start = (line.rindex(" ", index - 1) || -1) + 1
|
|
92
|
+
index - start <= FRAGMENT_LENGTH ? start : index
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The end of the word at index in line, when it ends within FRAGMENT_LENGTH after it; else index.
|
|
96
|
+
#: (String, Integer) -> Integer
|
|
97
|
+
def word_end(line, index)
|
|
98
|
+
finish = line.index(" ", index) || line.length
|
|
99
|
+
finish - index <= FRAGMENT_LENGTH ? finish : index
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# The characters of line between those it shares with other_line from the start and from the end, which never
|
|
103
|
+
# overlap, as an insertion repeating its neighbour would make them.
|
|
104
|
+
#: (String, String) -> Range[Integer]
|
|
105
|
+
def edited(line, other_line)
|
|
106
|
+
head = common_length(line, other_line)
|
|
107
|
+
tail = common_length(line[head..].to_s.reverse, other_line[head..].to_s.reverse)
|
|
108
|
+
head...(line.length - tail)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# How many characters two strings share from their start.
|
|
112
|
+
#: (String, String) -> Integer
|
|
113
|
+
def common_length(one, other) = one.each_char.zip(other.each_char).take_while { |a, b| a == b }.length
|
|
114
|
+
|
|
115
|
+
# A quote is a whole line, or a fragment long enough to show the edit, that only this side reads; or "" when
|
|
116
|
+
# this side has no line the other lacks, as before a pure insertion (#1070).
|
|
117
|
+
#: (String, SideOfTheChange, SideOfTheChange) -> void
|
|
118
|
+
def quoted(line, side, other)
|
|
119
|
+
return if line == side.first_line_absent_from(other)
|
|
120
|
+
return if !line.empty? && only_on?(line, side, other)
|
|
121
|
+
|
|
122
|
+
raise Error.new("quote_not_found",
|
|
123
|
+
"#{line.inspect} is not a line of #{@member_id} #{side.reads_at} that the change touched",
|
|
124
|
+
"Quote a whole line of the member as it reads #{side.reads_at}, as first_changed_lines " \
|
|
125
|
+
"shows, or at least #{FRAGMENT_LENGTH} characters of one that the member #{other.reads_at} " \
|
|
126
|
+
"does not hold; quote \"\" only where first_changed_lines does.")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Whether a quote is a whole line of side, or a fragment of at least FRAGMENT_LENGTH, that other does not hold.
|
|
130
|
+
#: (String, SideOfTheChange, SideOfTheChange) -> bool
|
|
131
|
+
def only_on?(line, side, other)
|
|
132
|
+
(side.whole_line?(line) && !other.whole_line?(line)) ||
|
|
133
|
+
(line.length >= FRAGMENT_LENGTH && side.holds?(line) && !other.holds?(line))
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -12,12 +12,22 @@ module Principles
|
|
|
12
12
|
# make (D85). A record without a format is older than format 1. An open record outside git keeps the last
|
|
13
13
|
# completed one whole, so that one's format counts too.
|
|
14
14
|
class RecordFormat
|
|
15
|
+
# The refusal of a record a later copy wrote at a format this copy cannot rewrite or read, which a read across
|
|
16
|
+
# principles, or one comparing members, catches by its kind rather than its code (D85, #1077).
|
|
17
|
+
class NewerFormatError < Error; end
|
|
18
|
+
|
|
15
19
|
# Raise NEWEST in the commit that adds a field an older copy would drop on a rewrite, and set FIRST_RELEASE by
|
|
16
20
|
# hand to the release that commit ships in.
|
|
17
21
|
NEWEST = 1
|
|
18
22
|
FIRST_RELEASE = "0.0.4"
|
|
19
23
|
FIELDS = %w[format format_first_release].freeze
|
|
20
24
|
|
|
25
|
+
#: (untyped) -> RecordFormat?
|
|
26
|
+
def self.newer_of(fields)
|
|
27
|
+
format = new(fields) if fields.is_a?(Hash)
|
|
28
|
+
format if format&.newer?
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
#: (Hash[String, untyped]) -> void
|
|
22
32
|
def initialize(fields)
|
|
23
33
|
@fields = fields
|
|
@@ -74,8 +84,8 @@ module Principles
|
|
|
74
84
|
|
|
75
85
|
#: (String, String, String) -> bot
|
|
76
86
|
def refuse(file, format_stated, update)
|
|
77
|
-
raise
|
|
78
|
-
|
|
87
|
+
raise NewerFormatError.new("newer_audit_record", "#{file} is format #{format_stated}",
|
|
88
|
+
"#{update} Leave the record as it is: it is not broken.", file)
|
|
79
89
|
end
|
|
80
90
|
|
|
81
91
|
# The highest format the record holds, with the release that first wrote it.
|
|
@@ -16,6 +16,12 @@ module Principles
|
|
|
16
16
|
freeze
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# The key the record knows the member by: the key kept beside its entry when it differs from the id it was
|
|
20
|
+
# filed under, else that id. The one owner of that rule, which MemberHashesAsWritten reads a newer record by
|
|
21
|
+
# too (#1066).
|
|
22
|
+
#: () -> String
|
|
23
|
+
def key = @entry["key"] || @filed_id
|
|
24
|
+
|
|
19
25
|
# The assessment the audit kept, with when it was made and what it was judged on; nil when it kept none.
|
|
20
26
|
#: () -> Hash[String, untyped]?
|
|
21
27
|
def assessment = @entry["assessment"]
|
|
@@ -15,9 +15,13 @@ module Principles
|
|
|
15
15
|
freeze
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
#
|
|
19
|
-
#:
|
|
20
|
-
|
|
18
|
+
# The hash the record holds for the member known by key, or nil when it holds none.
|
|
19
|
+
#: (String) -> String?
|
|
20
|
+
def hash_for(key) = @by_key[key]
|
|
21
|
+
|
|
22
|
+
# Whether the record holds no hash, as for a principle with no record.
|
|
23
|
+
#: () -> bool
|
|
24
|
+
def empty? = @by_key.empty?
|
|
21
25
|
|
|
22
26
|
# Whether a later copy wrote the record these hashes come from.
|
|
23
27
|
#: () -> bool
|
|
@@ -13,11 +13,6 @@ module Principles
|
|
|
13
13
|
# two differ, holding its hash then, the result reported for its check (D30), its accepted loading decision
|
|
14
14
|
# and the acknowledgements made for it since (D33). Callers reach them through AuditRecord#members.
|
|
15
15
|
class RecordedMembers
|
|
16
|
-
# The key a record knows the member filed under id by: the key kept beside its entry when the two differ, else
|
|
17
|
-
# that id. The one owner of that rule, which MemberHashesAsWritten reads a newer record by too (#1066).
|
|
18
|
-
#: (untyped, untyped) -> untyped
|
|
19
|
-
def self.filed_key(id, entry) = entry["key"] || id
|
|
20
|
-
|
|
21
16
|
#: (Hash[String, untyped]) -> void
|
|
22
17
|
def initialize(entries)
|
|
23
18
|
@entries = entries
|
|
@@ -55,7 +50,7 @@ module Principles
|
|
|
55
50
|
# Each hash the record assessed, by the key of the member it belongs to.
|
|
56
51
|
#: () -> Hash[String, String]
|
|
57
52
|
def hashes_by_key
|
|
58
|
-
@entries.to_h { |id, entry| [
|
|
53
|
+
@entries.to_h { |id, entry| [RecordedEntry.new(id, entry).key, entry.fetch("sha256")] }
|
|
59
54
|
end
|
|
60
55
|
|
|
61
56
|
# The hash the record assessed for the member known by key, or nil when it assessed no such member.
|
|
@@ -72,6 +67,21 @@ module Principles
|
|
|
72
67
|
result.key?("exit_status") ? result.fetch("command") : nil
|
|
73
68
|
end
|
|
74
69
|
|
|
70
|
+
# How check, the map's check now for the member known by key, stands to the one the record's audit ran:
|
|
71
|
+
# :unchanged when it ran this same command, or none for a member that has none; :removed when it ran one the
|
|
72
|
+
# member no longer has; :changed when it ran another; :not_run when it was told this one could not be run; :new
|
|
73
|
+
# when it reported none (D30, D63, #1071). The one owner of that comparison, which a full audit's template and a
|
|
74
|
+
# one-member audit both ask.
|
|
75
|
+
#: (String, String?) -> Symbol
|
|
76
|
+
def check_since(key, check)
|
|
77
|
+
ran = check_run_for(key)
|
|
78
|
+
return :unchanged if ran == check
|
|
79
|
+
return :removed unless check
|
|
80
|
+
return :changed if ran
|
|
81
|
+
|
|
82
|
+
entry_for(key)&.dig("check_result", "command") == check ? :not_run : :new
|
|
83
|
+
end
|
|
84
|
+
|
|
75
85
|
# What the review of that run rested on, for the member known by key, as the record keeps it: its review_basis
|
|
76
86
|
# and any review_basis_since, or nothing when the record ran no check for it or kept no line (D63).
|
|
77
87
|
#: (String) -> Hash[String, untyped]
|
|
@@ -106,13 +116,15 @@ module Principles
|
|
|
106
116
|
end.max_by(&:last)
|
|
107
117
|
end
|
|
108
118
|
|
|
109
|
-
# These entries with the member known by key moved to change's to_sha256, and change kept beside it (D33)
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
# These entries with the member known by key moved to change's to_sha256, and change kept beside it (D33), with
|
|
120
|
+
# check_result, when given, in place of the result it kept (#1071).
|
|
121
|
+
#: (String, Hash[String, untyped], ?check_result: Hash[String, untyped]?) -> RecordedMembers
|
|
122
|
+
def acknowledged(key, change, check_result: nil)
|
|
112
123
|
RecordedMembers.new(@entries.to_h do |id, entry|
|
|
113
|
-
next [id, entry] unless
|
|
124
|
+
next [id, entry] unless RecordedEntry.new(id, entry).key == key
|
|
114
125
|
|
|
115
|
-
|
|
126
|
+
result = check_result ? { "check_result" => check_result } : {}
|
|
127
|
+
[id, entry.merge("sha256" => change.fetch("to_sha256"), **result,
|
|
116
128
|
"acknowledgements" => [*entry["acknowledgements"], change])]
|
|
117
129
|
end)
|
|
118
130
|
end
|
|
@@ -120,13 +132,13 @@ module Principles
|
|
|
120
132
|
# The key of the member filed under id: its stored key when it had moved, or else id.
|
|
121
133
|
#: (String) -> String
|
|
122
134
|
def key_of(id)
|
|
123
|
-
|
|
135
|
+
RecordedEntry.new(id, @entries.fetch(id, {})).key
|
|
124
136
|
end
|
|
125
137
|
|
|
126
138
|
# The entry of the member known by key, under the id it was filed under, or nil when the record has none.
|
|
127
139
|
#: (String) -> RecordedEntry?
|
|
128
140
|
def recorded(key)
|
|
129
|
-
id, entry = @entries.find { |filed, each|
|
|
141
|
+
id, entry = @entries.find { |filed, each| RecordedEntry.new(filed, each).key == key }
|
|
130
142
|
RecordedEntry.new(id, entry) if id && entry
|
|
131
143
|
end
|
|
132
144
|
|
|
@@ -137,7 +149,7 @@ module Principles
|
|
|
137
149
|
RecordedMembers.new(@entries.to_h do |id, entry|
|
|
138
150
|
next [id, entry] unless entry.dig("assessment", "carried_forward")
|
|
139
151
|
|
|
140
|
-
[id, entry.merge("assessment" => last&.recorded(
|
|
152
|
+
[id, entry.merge("assessment" => last&.recorded(RecordedEntry.new(id, entry).key)&.assessment).compact]
|
|
141
153
|
end)
|
|
142
154
|
end
|
|
143
155
|
|
|
@@ -147,7 +159,7 @@ module Principles
|
|
|
147
159
|
# two differ.
|
|
148
160
|
#: (String) -> Hash[String, untyped]?
|
|
149
161
|
def entry_for(key)
|
|
150
|
-
@entries.find { |id, entry|
|
|
162
|
+
@entries.find { |id, entry| RecordedEntry.new(id, entry).key == key }&.last
|
|
151
163
|
end
|
|
152
164
|
end
|
|
153
165
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
# A refusal an answer meets before its shape is checked, for a mistake the shape would refuse without naming, such
|
|
8
|
+
# as a placeholder left in a field of another type (#773, #1084, #1088). A phase lists its own, in order, and
|
|
9
|
+
# SentAnswer reads each, so a new one is declared here once.
|
|
10
|
+
# @interface
|
|
11
|
+
module RefusalBeforeShape
|
|
12
|
+
# Refuses answer, as sent from source, when it makes this mistake; nothing otherwise. shape_problems are the
|
|
13
|
+
# problems its shape check finds, as Data::SchemaCheck#problems gives them, which a refusal may name beside its
|
|
14
|
+
# own, so one refusal names every repair (#1106). Sorbet takes an abstract method only with a forwarding super
|
|
15
|
+
# for its body, which RuboCop would otherwise call useless.
|
|
16
|
+
# @abstract
|
|
17
|
+
#: (untyped, String, Array[Hash[String, String]]) -> void
|
|
18
|
+
def refuse_in(answer, source, shape_problems) = super # rubocop:disable Lint/UselessMethodDefinition
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -5,6 +5,8 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "answer_fields"
|
|
6
6
|
require_relative "answer_place"
|
|
7
7
|
require_relative "audit_record"
|
|
8
|
+
require_relative "audit_records"
|
|
9
|
+
require_relative "last_completed_revision"
|
|
8
10
|
require_relative "project_history"
|
|
9
11
|
require_relative "request_id"
|
|
10
12
|
require_relative "write_up_repoint"
|
|
@@ -48,6 +50,17 @@ module Principles
|
|
|
48
50
|
completed.repointed(given.map { |repoint, index| located(repoint, index, fields) }, at: at)
|
|
49
51
|
end
|
|
50
52
|
|
|
53
|
+
# The record accepted from the answer, as accepted gives it, and the records it changes among records, not yet
|
|
54
|
+
# written: refused once the record changed after the request, whose revision the answer quotes back in its basis,
|
|
55
|
+
# was printed, unless it changes none.
|
|
56
|
+
#: (untyped, records: AuditRecords, at: String) { (Locator) -> void } -> [AuditRecord, Array[AuditRecord]]
|
|
57
|
+
def writable(response, records:, at:, &locate)
|
|
58
|
+
repointed = accepted(response, at:, &locate)
|
|
59
|
+
changes = records.changes(repointed)
|
|
60
|
+
LastCompletedRevision.new(response.dig("basis", "revision")).confirm_writable(@principle_id, @record, changes)
|
|
61
|
+
[repointed, changes]
|
|
62
|
+
end
|
|
63
|
+
|
|
51
64
|
# The ids of the completed record's open findings that repointed, the record accepted, points elsewhere (T16).
|
|
52
65
|
#: (AuditRecord) -> Array[String]
|
|
53
66
|
def moved_ids(repointed) = repointed.write_ups_moved_since(completed)
|