principles 0.0.10 → 0.1.0
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/CHANGELOG.md +42 -0
- data/README.md +0 -2
- data/lib/principles/controllers/acknowledgement.rb +11 -4
- data/lib/principles/controllers/acknowledgements.rb +4 -4
- data/lib/principles/controllers/answer.rb +2 -2
- data/lib/principles/controllers/assessment.rb +20 -4
- data/lib/principles/controllers/audit.rb +16 -5
- data/lib/principles/controllers/broken_member_repairs.rb +60 -0
- data/lib/principles/controllers/command.rb +8 -30
- data/lib/principles/controllers/correction.rb +7 -5
- data/lib/principles/controllers/full_audit_request.rb +44 -22
- data/lib/principles/controllers/guidance_search_paths.rb +1 -1
- data/lib/principles/controllers/inventory.rb +3 -3
- data/lib/principles/controllers/member_acknowledgement.rb +5 -5
- data/lib/principles/controllers/member_addition.rb +5 -2
- data/lib/principles/controllers/member_entries.rb +1 -1
- data/lib/principles/controllers/member_problems_report.rb +11 -7
- data/lib/principles/controllers/members_to_assess.rb +1 -1
- data/lib/principles/controllers/meta_principle_setup.rb +4 -3
- data/lib/principles/controllers/open_correction.rb +3 -3
- data/lib/principles/controllers/open_finding_decisions.rb +66 -0
- data/lib/principles/controllers/running_tool.rb +22 -5
- data/lib/principles/controllers/survey.rb +3 -2
- data/lib/principles/data/candidate_files_found.rb +6 -4
- data/lib/principles/data/command-steps.json +20 -20
- data/lib/principles/data/json_text.rb +5 -1
- data/lib/principles/data/parser_message.rb +61 -0
- data/lib/principles/data/project_files.rb +4 -2
- data/lib/principles/data/repository.rb +4 -4
- data/lib/principles/data/running_version.rb +1 -1
- data/lib/principles/data/schemas/audit-record.schema.json +15 -0
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
- data/lib/principles/invocation_options.rb +4 -4
- data/lib/principles/launch.rb +5 -3
- data/lib/principles/models/acknowledgement.rb +1 -27
- data/lib/principles/models/acknowledgement_left_as_printed.rb +2 -1
- data/lib/principles/models/acknowledgement_placeholders.rb +48 -0
- data/lib/principles/models/after_commit_input.rb +1 -0
- data/lib/principles/models/assessment_answer.rb +2 -2
- data/lib/principles/models/assessment_basis.rb +1 -1
- data/lib/principles/models/assessment_left_as_printed.rb +1 -1
- data/lib/principles/models/audit.rb +24 -4
- data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
- data/lib/principles/models/audit_record.rb +5 -14
- data/lib/principles/models/audit_records.rb +2 -2
- data/lib/principles/models/audited_member_lines.rb +1 -1
- data/lib/principles/models/candidate_files.rb +1 -1
- data/lib/principles/models/candidate_inventory.rb +20 -10
- data/lib/principles/models/candidate_outline.rb +1 -1
- data/lib/principles/models/changed_regions.rb +1 -1
- data/lib/principles/models/command_steps.rb +1 -2
- data/lib/principles/models/correction_basis.rb +1 -1
- data/lib/principles/models/declared_map_changes.rb +1 -2
- data/lib/principles/models/disposition.rb +12 -76
- data/lib/principles/models/disposition_placeholders.rb +48 -0
- data/lib/principles/models/disposition_text_field.rb +41 -0
- data/lib/principles/models/evidence_item.rb +1 -1
- data/lib/principles/models/finding_decision.rb +84 -0
- data/lib/principles/models/finding_write_ups.rb +2 -1
- data/lib/principles/models/first_full_audit.rb +1 -0
- data/lib/principles/models/fix_only_fields.rb +4 -3
- data/lib/principles/models/frontmatter_fields.rb +1 -1
- data/lib/principles/models/guidance_search_path.rb +1 -1
- data/lib/principles/models/guidance_search_paths.rb +5 -1
- data/lib/principles/models/head_moves.rb +1 -0
- data/lib/principles/models/ignored_candidates.rb +1 -1
- data/lib/principles/models/instruction_named.rb +1 -1
- data/lib/principles/models/json_path_query.rb +1 -1
- data/lib/principles/models/json_path_selectors.rb +1 -1
- data/lib/principles/models/json_path_string.rb +1 -1
- data/lib/principles/models/last_completed_revision.rb +1 -1
- data/lib/principles/models/line_diff.rb +1 -1
- data/lib/principles/models/line_span.rb +1 -1
- data/lib/principles/models/loading_scope.rb +1 -0
- data/lib/principles/models/located_text.rb +20 -12
- data/lib/principles/models/map_change.rb +66 -0
- data/lib/principles/models/mapped_principles.rb +4 -0
- data/lib/principles/models/markdown_file.rb +22 -1
- data/lib/principles/models/member.rb +1 -1
- data/lib/principles/models/member_assessments.rb +11 -4
- data/lib/principles/models/member_elsewhere.rb +1 -1
- data/lib/principles/models/member_file.rb +15 -13
- data/lib/principles/models/member_hashes_as_written.rb +2 -2
- data/lib/principles/models/member_history.rb +1 -1
- data/lib/principles/models/member_lines.rb +1 -1
- data/lib/principles/models/member_loading_scopes.rb +1 -0
- data/lib/principles/models/member_mapping_run.rb +4 -4
- data/lib/principles/models/member_moves.rb +1 -2
- data/lib/principles/models/member_problems.rb +5 -1
- data/lib/principles/models/member_region.rb +1 -1
- data/lib/principles/models/member_repair_moves.rb +20 -4
- data/lib/principles/models/member_snapshots.rb +10 -10
- data/lib/principles/models/members_elsewhere.rb +1 -1
- data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
- data/lib/principles/models/members_sharing_lines.rb +2 -2
- data/lib/principles/models/misspelt_member_id.rb +10 -4
- data/lib/principles/models/named_placeholder.rb +32 -0
- data/lib/principles/models/open_finding.rb +4 -3
- data/lib/principles/models/open_findings_decision.rb +124 -0
- data/lib/principles/models/open_findings_elsewhere.rb +1 -1
- data/lib/principles/models/other_templates_placeholders.rb +26 -6
- data/lib/principles/models/outline_budget.rb +1 -1
- data/lib/principles/models/outline_group.rb +1 -1
- data/lib/principles/models/outline_section.rb +1 -1
- data/lib/principles/models/part_named.rb +1 -1
- data/lib/principles/models/plain_text_file.rb +1 -1
- data/lib/principles/models/principle_history.rb +5 -4
- data/lib/principles/models/principle_members.rb +1 -1
- data/lib/principles/models/problem_report.rb +13 -1
- data/lib/principles/models/project.rb +15 -16
- data/lib/principles/models/project_at_commit.rb +60 -0
- data/lib/principles/models/project_history.rb +10 -52
- data/lib/principles/models/prose_line.rb +36 -0
- data/lib/principles/models/record_format.rb +17 -4
- data/lib/principles/models/recorded_finding.rb +47 -7
- data/lib/principles/models/recorded_findings.rb +7 -7
- data/lib/principles/models/recorded_hashes.rb +1 -1
- data/lib/principles/models/recorded_members.rb +6 -8
- data/lib/principles/models/report_hooks.rb +1 -0
- data/lib/principles/models/request_id.rb +2 -2
- data/lib/principles/models/sent_answer.rb +5 -3
- data/lib/principles/models/session_start_input.rb +1 -0
- data/lib/principles/models/stale_request.rb +22 -8
- data/lib/principles/models/submitted_answer.rb +1 -1
- data/lib/principles/models/survey_search_paths.rb +13 -5
- data/lib/principles/models/template_placeholders.rb +22 -7
- data/lib/principles/models/text_size.rb +11 -3
- data/lib/principles/models/text_within.rb +1 -1
- data/lib/principles/models/unchecked_members.rb +1 -0
- data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
- data/lib/principles/models/unfinished_field.rb +34 -0
- data/lib/principles/models/unknown_principle.rb +1 -0
- data/lib/principles/models/write_up_opening.rb +5 -31
- data/lib/principles/models/write_up_pointer.rb +2 -1
- data/lib/principles/start_audit_options.rb +35 -20
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledged_result.rb +59 -0
- data/lib/principles/views/acknowledgement_result.rb +44 -51
- data/lib/principles/views/added_member.rb +10 -1
- data/lib/principles/views/answer_in_a_file.rb +65 -0
- data/lib/principles/views/assessed_members.rb +4 -2
- data/lib/principles/views/assessment_answer_guide.rb +59 -0
- data/lib/principles/views/assessment_request.rb +2 -26
- data/lib/principles/views/audit_result.rb +18 -7
- data/lib/principles/views/candidate_files_result.rb +9 -4
- data/lib/principles/views/context_parts.rb +41 -10
- data/lib/principles/views/correction_request.rb +27 -18
- data/lib/principles/views/first_audit_brief.rb +2 -1
- data/lib/principles/views/guidance_search_paths_result.rb +13 -6
- data/lib/principles/views/invocation.rb +14 -4
- data/lib/principles/views/json_on_one_line.rb +18 -0
- data/lib/principles/views/member_repairs.rb +21 -5
- data/lib/principles/views/meta_principle_result.rb +26 -5
- data/lib/principles/views/open_findings_decision_result.rb +60 -0
- data/lib/principles/views/parts_index_result.rb +8 -6
- data/lib/principles/views/principle_read_result.rb +2 -2
- data/lib/principles/views/problem_facts.rb +46 -0
- data/lib/principles/views/problem_lines.rb +8 -3
- data/lib/principles/views/problem_result.rb +53 -31
- data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
- data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
- data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
- data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
- data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/change-member-check.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +7 -8
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
- data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-member-check.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +13 -12
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +12 -12
- data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
- data/lib/principles/views/prompts/start-a-session/act-on-the-changed-principles.md +2 -0
- data/lib/principles/views/prompts.rb +7 -4
- metadata +26 -8
- data/lib/principles/controllers/repoint.rb +0 -67
- data/lib/principles/models/repoint.rb +0 -125
- data/lib/principles/models/write_up_repoint.rb +0 -38
- data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
- data/lib/principles/views/repoint_result.rb +0 -80
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
module Principles
|
|
5
|
-
# The domain logic,
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
6
|
module Models
|
|
7
7
|
# One heading of a candidate file's outline and the top-level list items under it, with the lines of the file it
|
|
8
8
|
# spans, so an outline whose items are cut can say where to read them back.
|
|
@@ -5,7 +5,7 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "../prose_list"
|
|
6
6
|
|
|
7
7
|
module Principles
|
|
8
|
-
# The domain
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
9
|
module Models
|
|
10
10
|
# The part start-audit --part names, printed alone from the request a full audit asks, so an agent that needs one
|
|
11
11
|
# part of it need not read the whole request or script it. Only a part the request has, or leaves
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
require_relative "member_file"
|
|
5
5
|
|
|
6
6
|
module Principles
|
|
7
|
-
# The domain logic,
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
8
|
module Models
|
|
9
9
|
# A file that is not Markdown, such as a script or a config file. It has no sections, so a member is the
|
|
10
10
|
# whole file or a passage of it, and a # line is never read as a heading.
|
|
@@ -61,7 +61,7 @@ module Principles
|
|
|
61
61
|
#: (Array[String]) -> Hash[String, Hash[String, String]]
|
|
62
62
|
def mapped_baselines(keys)
|
|
63
63
|
runs(keys).each_with_object({}) do |(key, run), found|
|
|
64
|
-
baseline = MemberMappingRun.new(
|
|
64
|
+
baseline = MemberMappingRun.new(run).baseline(@history)
|
|
65
65
|
found[key] = baseline if baseline
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -88,7 +88,7 @@ module Principles
|
|
|
88
88
|
mapping = @mapping
|
|
89
89
|
return mapping.map_at_revision(commit, captured: @history.captured_head) if mapping
|
|
90
90
|
|
|
91
|
-
text = map_paths.lazy.filter_map { |path| @history.
|
|
91
|
+
text = map_paths.lazy.filter_map { |path| @history.at(commit).text(path) }.first
|
|
92
92
|
@principles.parsed(@id, text.to_s, commit: commit)
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -157,7 +157,7 @@ module Principles
|
|
|
157
157
|
fields_at = [members_at(commit)&.fetch(key, nil), now_at].compact
|
|
158
158
|
fields_at.uniq { |fields| Member.new(fields).reference }.map do |fields|
|
|
159
159
|
Placement.new(commit: commit, reference: Member.new(fields).reference,
|
|
160
|
-
sha256: @history.
|
|
160
|
+
sha256: @history.at(commit).hash_of(Member.new(fields)))
|
|
161
161
|
end
|
|
162
162
|
end
|
|
163
163
|
|
|
@@ -175,7 +175,8 @@ module Principles
|
|
|
175
175
|
#: (String, Hash[String, untyped], String) -> String?
|
|
176
176
|
def hash_at(key, now_at, revision)
|
|
177
177
|
fields = members_at(revision)&.fetch(key, nil) or return nil
|
|
178
|
-
|
|
178
|
+
then_project = @history.at(revision)
|
|
179
|
+
then_project.hash_of(Member.new(fields)) || then_project.hash_of(Member.new(now_at))
|
|
179
180
|
end
|
|
180
181
|
|
|
181
182
|
# Each member the map at commit holds, by key. Legacy unreadable maps give nil; certified proof failures
|
|
@@ -6,7 +6,7 @@ require_relative "member"
|
|
|
6
6
|
require_relative "misspelt_member_id"
|
|
7
7
|
|
|
8
8
|
module Principles
|
|
9
|
-
# The domain logic,
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
10
|
module Models
|
|
11
11
|
# One principle's members, as Members: finding one by its id, and the rules on ids and keys among them,
|
|
12
12
|
# which Principle asks as it changes the map. It is Enumerable over its members, in the map's order.
|
|
@@ -6,7 +6,7 @@ require_relative "member_problems"
|
|
|
6
6
|
require_relative "missing_files"
|
|
7
7
|
|
|
8
8
|
module Principles
|
|
9
|
-
# The domain logic,
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
10
|
module Models
|
|
11
11
|
# What list-member-problems reports across the maps it reads: refused while any member's reference is
|
|
12
12
|
# broken, so a gate can stop on its exit status alone, and otherwise every changed member and a count of
|
|
@@ -91,6 +91,18 @@ module Principles
|
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
+
# In git, for each map whose map or member files differ from HEAD, those files, which an audit of it refuses
|
|
95
|
+
# until they are committed; empty outside git, where an audit judges files as they are.
|
|
96
|
+
#: (MappedPrinciples) -> Hash[String, Array[String]]
|
|
97
|
+
def audit_files_to_commit(principles)
|
|
98
|
+
return {} unless @history&.inside_git?
|
|
99
|
+
|
|
100
|
+
@maps.filter_map do |map|
|
|
101
|
+
files = @history.uncommitted(principles.audited_files(map.principle_id, map.members))
|
|
102
|
+
[map.principle_id, files] unless files.empty?
|
|
103
|
+
end.to_h
|
|
104
|
+
end
|
|
105
|
+
|
|
94
106
|
private
|
|
95
107
|
|
|
96
108
|
# Each map's files holding a member with no baseline, by map id; a map with none is left out.
|
|
@@ -113,23 +113,22 @@ module Principles
|
|
|
113
113
|
#: (String) -> bool
|
|
114
114
|
def folder?(path) = @files.folder?(path)
|
|
115
115
|
|
|
116
|
-
# Where a member is in its file now, and the hash of what it says there.
|
|
117
|
-
#: (Locator) -> Hash[String, untyped]
|
|
118
|
-
def locate(locator)
|
|
119
|
-
member_file(locator.path).locate(locator)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
116
|
# Check the location an add or move is about to persist, with the authoring-only ending constraint.
|
|
123
|
-
#: (Locator) ->
|
|
117
|
+
#: (Locator) -> LocatedText
|
|
124
118
|
def locate_for_authoring(locator) = member_file(locator.path).locate_for_authoring(locator)
|
|
125
119
|
|
|
126
|
-
# The
|
|
120
|
+
# The last line of the paragraph or list item a passage named by its opening alone maps only the first line
|
|
121
|
+
# of, as its file type finds it; nil when none runs on.
|
|
122
|
+
#: (Locator) -> Integer?
|
|
123
|
+
def continues_to(locator) = member_file(locator.path).continues_to(locator)
|
|
124
|
+
|
|
125
|
+
# The lines locator finds now, as one text; refused as located_text refuses.
|
|
127
126
|
#: (Locator) -> String
|
|
128
127
|
def member_text(locator) = member_file(locator.path).lines_of(locator).join
|
|
129
128
|
|
|
130
129
|
# The text locator finds now, as one value: its path, its lines and the hash of what it says.
|
|
131
130
|
#: (Locator) -> LocatedText
|
|
132
|
-
def located_text(locator) =
|
|
131
|
+
def located_text(locator) = member_file(locator.path).locate(locator)
|
|
133
132
|
|
|
134
133
|
# The member at locator, its lines in its file at commit beside its lines now, which an audit shows the
|
|
135
134
|
# agent so it judges the member's own change without the rest of its file's; nil when commit lacks the
|
|
@@ -137,7 +136,7 @@ module Principles
|
|
|
137
136
|
# then_locator places it at commit where it was elsewhere then, as before a move.
|
|
138
137
|
#: (Locator, since: String, ?then_locator: Locator) -> MemberLines?
|
|
139
138
|
def member_lines(locator, since:, then_locator: locator)
|
|
140
|
-
before = history.
|
|
139
|
+
before = history.at(since).lines(then_locator) or return nil
|
|
141
140
|
|
|
142
141
|
MemberLines.new(at_baseline: before, now: member_file(locator.path).lines_of(locator))
|
|
143
142
|
end
|
|
@@ -175,7 +174,7 @@ module Principles
|
|
|
175
174
|
#: (PrincipleMembers) -> Hash[String, untyped]
|
|
176
175
|
def current_by_key(members)
|
|
177
176
|
members.to_h do |member|
|
|
178
|
-
[member.key,
|
|
177
|
+
[member.key, located_text(member.locator).sha256]
|
|
179
178
|
rescue Error => e
|
|
180
179
|
[member.key, e.payload]
|
|
181
180
|
end
|
|
@@ -193,8 +192,8 @@ module Principles
|
|
|
193
192
|
# refusal.
|
|
194
193
|
#: (Locator) { (String) -> String } -> Hash[String, untyped]
|
|
195
194
|
def freshness(locator, &)
|
|
196
|
-
now =
|
|
197
|
-
{ "snapshot" => now, "freshness" => yield(now.
|
|
195
|
+
now = located_text(locator)
|
|
196
|
+
{ "snapshot" => now.to_h, "freshness" => yield(now.sha256) }
|
|
198
197
|
rescue Error => e
|
|
199
198
|
{ "freshness" => LocateRefusal.new(e.payload).member_state, "error" => e.payload }
|
|
200
199
|
end
|
|
@@ -226,10 +225,10 @@ module Principles
|
|
|
226
225
|
def answer(file, stdin:, given:) = SentAnswer.read(@files, file, stdin:, given:)
|
|
227
226
|
|
|
228
227
|
# What list-candidate-files found, as CandidateInventory reads it from the project, after a commit when given.
|
|
229
|
-
#: (?after: String?, ?also: Array[String]) -> CandidateInventory
|
|
230
|
-
def candidate_files(after: nil, also: [])
|
|
228
|
+
#: (?after: String?, ?also: Array[String], ?only: Array[String]) -> CandidateInventory
|
|
229
|
+
def candidate_files(after: nil, also: [], only: [])
|
|
231
230
|
mapped = after ? principles.readable_paths : []
|
|
232
|
-
search_paths = SurveySearchPaths.new(recorded: guidance_search_paths.globs, also:)
|
|
231
|
+
search_paths = SurveySearchPaths.new(recorded: guidance_search_paths.globs, also:, only:)
|
|
233
232
|
CandidateInventory.read(@files, history, search_paths:, after:, mapped:)
|
|
234
233
|
end
|
|
235
234
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../data/repository"
|
|
6
|
+
require_relative "../data/project_files"
|
|
7
|
+
require_relative "member"
|
|
8
|
+
require_relative "member_file"
|
|
9
|
+
require_relative "principle_members"
|
|
10
|
+
|
|
11
|
+
module Principles
|
|
12
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
13
|
+
module Models
|
|
14
|
+
# The project as one commit holds it: each file's text there, read in the file a path's links lead to, since git
|
|
15
|
+
# holds a link as its target's name, and the lines each member's locator finds in that text.
|
|
16
|
+
class ProjectAtCommit
|
|
17
|
+
#: (Data::Repository, Data::ProjectFiles, String) -> void
|
|
18
|
+
def initialize(repository, files, commit)
|
|
19
|
+
@repository = repository
|
|
20
|
+
@files = files
|
|
21
|
+
@commit = commit
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# path's text at the commit, or nil when the commit does not hold it.
|
|
26
|
+
#: (String) -> String?
|
|
27
|
+
def text(path) = @repository.text_at(@commit, @files.leads_to(path))
|
|
28
|
+
|
|
29
|
+
# The lines of the member at locator in its file at the commit, or nil when the commit lacks the file or the
|
|
30
|
+
# locator finds nothing in its text there, as after a move; any other refusal still refuses.
|
|
31
|
+
#: (Locator) -> Array[String]?
|
|
32
|
+
def lines(locator)
|
|
33
|
+
path = locator.path
|
|
34
|
+
found = text(path) or return nil
|
|
35
|
+
MemberFile.for(path: path, text: found).lines_of(locator)
|
|
36
|
+
rescue Error => e
|
|
37
|
+
raise unless MemberFile::PLACEMENT_REFUSALS.include?(e.payload.fetch("code"))
|
|
38
|
+
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Each member's id and the hash of its text at the commit, or nil when the commit lacks a member's file or the
|
|
43
|
+
# member's place in it, since an audit's base needs every member.
|
|
44
|
+
#: (PrincipleMembers) -> Hash[String, String]?
|
|
45
|
+
def hashes(members)
|
|
46
|
+
members.to_h { |member| [member.id, hash_of(member) || (return nil)] }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The hash of member's text at the commit, or nil when the commit lacks its file or its place in it, as a
|
|
50
|
+
# member's history walks commits where an earlier placement may no longer be found.
|
|
51
|
+
#: (Member) -> String?
|
|
52
|
+
def hash_of(member)
|
|
53
|
+
committed = text(member.path) or return nil
|
|
54
|
+
MemberFile.for(path: member.path, text: committed).locate(member.locator).sha256
|
|
55
|
+
rescue Error
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -5,9 +5,7 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "../data/repository"
|
|
6
6
|
require_relative "../data/project_files"
|
|
7
7
|
require_relative "../data/principles_subfolder"
|
|
8
|
-
require_relative "
|
|
9
|
-
require_relative "member"
|
|
10
|
-
require_relative "member_file"
|
|
8
|
+
require_relative "project_at_commit"
|
|
11
9
|
require_relative "commits_brought_in"
|
|
12
10
|
require_relative "uncommitted_files"
|
|
13
11
|
require_relative "captured_head"
|
|
@@ -39,15 +37,17 @@ module Principles
|
|
|
39
37
|
#: () -> TrackedPaths
|
|
40
38
|
def tracked_paths = @tracked_paths ||= TrackedPaths.new(@repository.tracked_files)
|
|
41
39
|
|
|
42
|
-
# Which of paths, and of the links and files they lead through, git does not track
|
|
43
|
-
# members until committed. nil outside git, where nothing is checked.
|
|
40
|
+
# Which of paths, and of the links and files they lead through, git does not track and does not ignore, which
|
|
41
|
+
# an audit refuses as members until committed. nil outside git, where nothing is checked.
|
|
44
42
|
#: (Array[String]) -> Array[String]?
|
|
45
|
-
def
|
|
43
|
+
def untracked_excluding_ignored(paths)
|
|
44
|
+
@repository.untracked_excluding_ignored(through_links(paths)) if @repository.inside?
|
|
45
|
+
end
|
|
46
46
|
|
|
47
47
|
# Whether git tracks path and every file its links lead to, so a fresh clone finds its text; an ignored file is
|
|
48
48
|
# not tracked either. True outside git, where nothing is checked.
|
|
49
49
|
#: (String) -> bool
|
|
50
|
-
def tracks?(path) = !@repository.inside? || @repository.
|
|
50
|
+
def tracks?(path) = !@repository.inside? || @repository.untracked_including_ignored(through_links([path])).empty?
|
|
51
51
|
|
|
52
52
|
# Whether the project is in git, so it has a history at all.
|
|
53
53
|
#: () -> bool
|
|
@@ -99,39 +99,9 @@ module Principles
|
|
|
99
99
|
head
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
#
|
|
103
|
-
#: (String
|
|
104
|
-
def
|
|
105
|
-
@repository.text_at(commit, @files.leads_to(path))
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# The lines of the member at locator in its file at commit, or nil when commit lacks the file or the
|
|
109
|
-
# locator finds nothing in its text there, as after a move; any other refusal still refuses.
|
|
110
|
-
#: (String, Locator) -> Array[String]?
|
|
111
|
-
def lines_at(commit, locator)
|
|
112
|
-
path = locator.path
|
|
113
|
-
text = text_at(commit, path) or return nil
|
|
114
|
-
MemberFile.for(path: path, text: text).lines_of(locator)
|
|
115
|
-
rescue Error => e
|
|
116
|
-
raise unless MemberFile::PLACEMENT_REFUSALS.include?(e.payload.fetch("code"))
|
|
117
|
-
|
|
118
|
-
nil
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Each member's id and the hash of its text at commit, or nil when commit lacks a member's file or the
|
|
122
|
-
# member's place in it.
|
|
123
|
-
#: (String, PrincipleMembers) -> Hash[String, String]?
|
|
124
|
-
def hashes_at(commit, members)
|
|
125
|
-
members.to_h do |member|
|
|
126
|
-
path = member.path
|
|
127
|
-
text = text_at(commit, path)
|
|
128
|
-
return nil unless text
|
|
129
|
-
|
|
130
|
-
[member.id, MemberFile.for(path: path, text: text).locate(member.locator).fetch("sha256")]
|
|
131
|
-
end
|
|
132
|
-
rescue Error
|
|
133
|
-
nil
|
|
134
|
-
end
|
|
102
|
+
# The project as commit holds it.
|
|
103
|
+
#: (String) -> ProjectAtCommit
|
|
104
|
+
def at(commit) = ProjectAtCommit.new(@repository, @files, commit)
|
|
135
105
|
|
|
136
106
|
# The rename git detects for path, a file absent from the working tree, as {"to", "similarity",
|
|
137
107
|
# "deleted_in"}: the last commit that touched path, or nil while the move is not yet committed. It is
|
|
@@ -147,18 +117,6 @@ module Principles
|
|
|
147
117
|
found.slice("to", "similarity").merge("deleted_in" => deleted_in)
|
|
148
118
|
end
|
|
149
119
|
|
|
150
|
-
# Each member's key and the hash of its text at commit, leaving out a member that commit cannot find.
|
|
151
|
-
#: (String, Array[Hash[String, untyped]]) -> Hash[String, String]
|
|
152
|
-
def hashes_by_key_at(commit, members)
|
|
153
|
-
members.map { |fields| Member.new(fields) }.each_with_object({}) do |member, found|
|
|
154
|
-
path = member.path
|
|
155
|
-
text = text_at(commit, path) or next
|
|
156
|
-
found[member.key] = MemberFile.for(path: path, text: text).locate(member.locator).fetch("sha256")
|
|
157
|
-
rescue Error
|
|
158
|
-
next
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
120
|
# Which of paths, and of the links and files they lead through, differ from HEAD, or are not yet committed.
|
|
163
121
|
#: (Array[String]) -> Array[String]
|
|
164
122
|
def uncommitted(paths)
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
# One line of a file as prose reads it: blank, a heading, or continuing the paragraph or list item before it.
|
|
8
|
+
class ProseLine
|
|
9
|
+
# A line that starts a new block, a list item or a heading, rather than continuing the paragraph before it.
|
|
10
|
+
NEW_BLOCK = /\A(([-*+]|\d+[.)])\s|#)/
|
|
11
|
+
# What a heading line starts with, a block of its own line.
|
|
12
|
+
HEADING = "#"
|
|
13
|
+
|
|
14
|
+
#: (String) -> void
|
|
15
|
+
def initialize(text)
|
|
16
|
+
@text = text
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The line without its indentation or line break.
|
|
21
|
+
#: () -> String
|
|
22
|
+
def text = @text.strip
|
|
23
|
+
|
|
24
|
+
#: () -> bool
|
|
25
|
+
def blank? = text.empty?
|
|
26
|
+
|
|
27
|
+
#: () -> bool
|
|
28
|
+
def heading? = text.start_with?(HEADING)
|
|
29
|
+
|
|
30
|
+
# Whether the line continues the paragraph before it: it is not blank and starts no new block. It keeps its
|
|
31
|
+
# line break, which NEW_BLOCK's \s may match, so a bare "-" line still starts a list item.
|
|
32
|
+
#: () -> bool
|
|
33
|
+
def continues? = !blank? && !@text.lstrip.match?(NEW_BLOCK)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -19,9 +19,11 @@ module Principles
|
|
|
19
19
|
# The release that first wrote each format. In the commit that adds a field an older copy would drop on a
|
|
20
20
|
# rewrite, add the next format here, set by hand to the release that commit ships in, and name the field in
|
|
21
21
|
# FIELD_FORMATS, so only a record carrying it moves up.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
# Add its row to prompts/docs/AUDIT_RECORD_FORMAT_HISTORY.md too.
|
|
23
|
+
FIRST_RELEASES = { 1 => "0.0.4", 2 => "0.0.8", 3 => "0.1.0" }.freeze #: Hash[Integer, String]
|
|
24
|
+
# The format each later field needs, by its path of property names: the open record's correction, which
|
|
25
|
+
# show-open-correction prints again, and a finding's changes since its audit, which the next full audit shows.
|
|
26
|
+
FIELD_FORMATS = { "correction" => 2, "findings.changed_since_audit" => 3 }.freeze #: Hash[String, Integer]
|
|
25
27
|
# The newest format this copy writes and rewrites without losing a field; formats count up from 1.
|
|
26
28
|
NEWEST = FIRST_RELEASES.size #: Integer
|
|
27
29
|
FIELDS = %w[format format_first_release].freeze
|
|
@@ -42,7 +44,7 @@ module Principles
|
|
|
42
44
|
# format's first release, worked out again on each write.
|
|
43
45
|
#: () -> Hash[String, untyped]
|
|
44
46
|
def stamped
|
|
45
|
-
format = FIELD_FORMATS.filter_map { |
|
|
47
|
+
format = FIELD_FORMATS.filter_map { |path, needs| needs if holds?(@fields, path.split(".")) }.max || 1
|
|
46
48
|
{ "format" => format, "format_first_release" => FIRST_RELEASES.fetch(format), **@fields.except(*FIELDS) }
|
|
47
49
|
end
|
|
48
50
|
|
|
@@ -88,6 +90,17 @@ module Principles
|
|
|
88
90
|
|
|
89
91
|
private
|
|
90
92
|
|
|
93
|
+
# Whether value holds the property names leads to, through any entry of an array on the way.
|
|
94
|
+
#: (untyped, Array[String]) -> bool
|
|
95
|
+
def holds?(value, names)
|
|
96
|
+
first, *rest = names
|
|
97
|
+
return true unless first
|
|
98
|
+
return value.any? { holds?(it, names) } if value.is_a?(Array)
|
|
99
|
+
return false unless value.is_a?(Hash) && value.key?(first)
|
|
100
|
+
|
|
101
|
+
holds?(value[first], rest)
|
|
102
|
+
end
|
|
103
|
+
|
|
91
104
|
#: (String, String, String) -> bot
|
|
92
105
|
def refuse(file, format_stated, update)
|
|
93
106
|
raise NewerFormatError.new("newer_audit_record", "#{file} is format #{format_stated}",
|
|
@@ -82,20 +82,60 @@ module Principles
|
|
|
82
82
|
#: () -> bool
|
|
83
83
|
def fixed? = action == "fixed"
|
|
84
84
|
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
# Each change made to it since the full audit that kept it, as field, from, to, at and reason, for the next full
|
|
86
|
+
# audit to see before its record drops them; a repoint's move, which records written by earlier releases keep
|
|
87
|
+
# under repointed, is a change to recorded_at. Nil when none was made.
|
|
88
|
+
#: () -> Array[Hash[String, untyped]]?
|
|
89
|
+
def changes_since_audit
|
|
90
|
+
moves = (@fields["repointed"] || []).map { |moved| { "field" => "recorded_at", **moved } }
|
|
91
|
+
changes = [*moves, *@fields["changed_since_audit"]]
|
|
92
|
+
changes unless changes.empty?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# This finding pointed at pointer, or written up nowhere for nil, the change kept beside it with when and why;
|
|
96
|
+
# or itself when it already points there, so an identical retry writes nothing.
|
|
97
|
+
#: (WriteUpPointer?, at: String, reason: String) -> RecordedFinding
|
|
98
|
+
def pointed_at(pointer, at:, reason:)
|
|
89
99
|
return self if recorded_at == pointer
|
|
90
100
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
change = { "field" => "recorded_at", "from" => @fields["recorded_at"], "to" => pointer&.to_h, "at" => at,
|
|
102
|
+
"reason" => reason }
|
|
103
|
+
with(@fields.except("recorded_at").merge(pointer ? { "recorded_at" => pointer.to_h } : {}), change)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# This finding left open as action, deferred or accepted, its reason the decision's, the change kept beside it,
|
|
107
|
+
# an accepted one waiting on no one; or itself when it already is, so an identical retry writes nothing.
|
|
108
|
+
#: (String, at: String, reason: String) -> RecordedFinding
|
|
109
|
+
def acting(new_action, at:, reason:)
|
|
110
|
+
return self if action == new_action
|
|
111
|
+
|
|
112
|
+
change = { "field" => "action", "from" => action, "to" => new_action, "at" => at, "reason" => reason }
|
|
113
|
+
acted = with(@fields.merge("action" => new_action, "reason" => reason), change)
|
|
114
|
+
new_action == "accepted" ? acted.waiting_on(nil, at:, reason:) : acted
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# This finding waiting on line, dated at, or on no one for nil, the change kept beside it with why, or itself
|
|
118
|
+
# when it already waits on line, so an identical retry writes nothing.
|
|
119
|
+
#: (String?, at: String, reason: String) -> RecordedFinding
|
|
120
|
+
def waiting_on(line, at:, reason:)
|
|
121
|
+
return self if waits_on == line
|
|
122
|
+
|
|
123
|
+
change = { "field" => "waits_on", "from" => waits_on, "to" => line, "at" => at, "reason" => reason }
|
|
124
|
+
waiting = line ? { "waits_on" => line, "waits_on_since" => at } : {}
|
|
125
|
+
with(@fields.except("waits_on", "waits_on_since").merge(waiting), change)
|
|
94
126
|
end
|
|
95
127
|
|
|
96
128
|
# The finding as its record's file holds it.
|
|
97
129
|
#: () -> Hash[String, untyped]
|
|
98
130
|
def to_h = @fields
|
|
131
|
+
|
|
132
|
+
private
|
|
133
|
+
|
|
134
|
+
# The finding with fields, change appended to the changes kept beside it since its audit.
|
|
135
|
+
#: (Hash[String, untyped], Hash[String, untyped]) -> RecordedFinding
|
|
136
|
+
def with(fields, change)
|
|
137
|
+
RecordedFinding.new(fields.merge("changed_since_audit" => [*@fields["changed_since_audit"], change]))
|
|
138
|
+
end
|
|
99
139
|
end
|
|
100
140
|
end
|
|
101
141
|
end
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
require_relative "open_finding"
|
|
5
5
|
require_relative "recorded_finding"
|
|
6
6
|
require_relative "recorded_members"
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "finding_decision"
|
|
8
8
|
|
|
9
9
|
module Principles
|
|
10
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -38,13 +38,13 @@ module Principles
|
|
|
38
38
|
#: () -> Array[String]
|
|
39
39
|
def fixed_ids = @findings.select(&:fixed?).map(&:id)
|
|
40
40
|
|
|
41
|
-
# These findings with each
|
|
42
|
-
#: (Array[
|
|
43
|
-
def
|
|
44
|
-
by_finding =
|
|
41
|
+
# These findings with each decision applied to the one it names, dated at.
|
|
42
|
+
#: (Array[FindingDecision], at: String) -> RecordedFindings
|
|
43
|
+
def decided(decisions, at:)
|
|
44
|
+
by_finding = decisions.to_h { |decision| [decision.finding_id, decision] }
|
|
45
45
|
moved = @findings.map do |finding|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
decision = by_finding[finding.id]
|
|
47
|
+
decision ? decision.applied_to(finding, at: at) : finding
|
|
48
48
|
end
|
|
49
49
|
RecordedFindings.new(moved.map(&:to_h), principle_id: @principle_id, audited_at: @audited_at,
|
|
50
50
|
members: @members)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
module Principles
|
|
5
|
-
# The domain logic,
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
6
|
module Models
|
|
7
7
|
# The member hashes a principle's audit record holds, by key, which its members now are compared with, and
|
|
8
8
|
# whether a later copy wrote that record, so its audits wait on an upgrade and the comparison is read-only.
|
|
@@ -43,14 +43,12 @@ module Principles
|
|
|
43
43
|
#: (String, String) -> String
|
|
44
44
|
def freshness(key, sha) = hashes.freshness(key, sha)
|
|
45
45
|
|
|
46
|
-
# The hashes the record assessed, which a member now is compared
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def hashes_by_key
|
|
53
|
-
@entries.to_h { |id, entry| [RecordedEntry.new(id, entry).key, entry.fetch("sha256")] }
|
|
46
|
+
# The hashes the record assessed, each by the key of the member it belongs to, which a member now is compared
|
|
47
|
+
# with; waiting when a later copy wrote the record.
|
|
48
|
+
#: (?waiting: bool) -> RecordedHashes
|
|
49
|
+
def hashes(waiting: false)
|
|
50
|
+
RecordedHashes.new(@entries.to_h { |id, entry| [RecordedEntry.new(id, entry).key, entry.fetch("sha256")] },
|
|
51
|
+
waiting:)
|
|
54
52
|
end
|
|
55
53
|
|
|
56
54
|
# The hash the record assessed for the member known by key, or nil when it assessed no such member.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
5
6
|
module Models
|
|
6
7
|
# The hooks that run this tool's two hook commands for a project without the principles plugin, on each host: the
|
|
7
8
|
# file the project's own hooks go in, and the command each event runs. Claude Code runs a hook after a failed shell
|
|
@@ -5,14 +5,14 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "json_digest"
|
|
6
6
|
|
|
7
7
|
module Principles
|
|
8
|
-
# The domain logic,
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
9
|
module Models
|
|
10
10
|
# The id of a judgement request: the principle, the phase and a digest of everything the request
|
|
11
11
|
# depends on, as ID.PHASE.DIGEST. This tool stores no request, so an answer is matched by recomputing
|
|
12
12
|
# the digest from the project as it is now: a different digest means something the request depended
|
|
13
13
|
# on has changed. The digest has no secret, so it catches mistakes, not forgery.
|
|
14
14
|
class RequestId
|
|
15
|
-
PHASES = %w[assessment correction acknowledgement acknowledgements
|
|
15
|
+
PHASES = %w[assessment correction acknowledgement acknowledgements deciding].freeze
|
|
16
16
|
FORMAT = /\A(?<principle>[a-z0-9]+(?:-[a-z0-9]+)*)\.(?<phase>[a-z]+)\.(?<digest>[0-9a-f]{12})\z/
|
|
17
17
|
|
|
18
18
|
#: String
|
|
@@ -8,6 +8,7 @@ require_relative "refusal_before_shape"
|
|
|
8
8
|
require_relative "request_id"
|
|
9
9
|
|
|
10
10
|
module Principles
|
|
11
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
11
12
|
module Models
|
|
12
13
|
# An answer an agent sent for a phase's request, read from its source, whose head, the fields every answer hands
|
|
13
14
|
# back as its request printed them, is checked on arrival: they say whether it still answers that request.
|
|
@@ -22,9 +23,10 @@ module Principles
|
|
|
22
23
|
# What a refusal to read its file calls that file.
|
|
23
24
|
FILE_NAMED = "The answer file" #: String
|
|
24
25
|
|
|
25
|
-
# The repair of a field-by-field
|
|
26
|
-
#
|
|
27
|
-
REPAIR = "Repair each field listed
|
|
26
|
+
# The repair of a field-by-field refusal for the acknowledgements phase, whose controller refuses its own
|
|
27
|
+
# fields: the agent repairs the bare answer it saved and fills, which --as template prints.
|
|
28
|
+
REPAIR = "Repair each field listed in the answer you saved from start-audit with the same --member options " \
|
|
29
|
+
"and --as template." #: String
|
|
28
30
|
|
|
29
31
|
# The answer read from the file or stdin the agent named, to the request given, the REQUEST_ID the agent typed,
|
|
30
32
|
# or when it typed none the request_id the answer names, as its template printed it, using that request's
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
require "json"
|
|
5
5
|
|
|
6
6
|
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
7
8
|
module Models
|
|
8
9
|
# The JSON a SessionStart hook is given on stdin, as far as report-at-session-start reads it: the source the
|
|
9
10
|
# session started from. Input that is not JSON, or names no source a host sends, reads as a startup, since a
|