principles 0.0.11 → 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 +31 -0
- data/lib/principles/controllers/answer.rb +2 -2
- data/lib/principles/controllers/assessment.rb +19 -3
- data/lib/principles/controllers/audit.rb +14 -4
- data/lib/principles/controllers/full_audit_request.rb +16 -10
- data/lib/principles/controllers/guidance_search_paths.rb +1 -1
- data/lib/principles/controllers/member_addition.rb +4 -1
- data/lib/principles/controllers/member_problems_report.rb +7 -6
- 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 +17 -17
- 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/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 +1 -1
- data/lib/principles/launch.rb +5 -3
- data/lib/principles/models/after_commit_input.rb +1 -0
- data/lib/principles/models/assessment_basis.rb +1 -1
- data/lib/principles/models/audit.rb +23 -3
- 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 +1 -1
- 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 +19 -9
- 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/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/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 +1 -1
- 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_elsewhere.rb +1 -1
- data/lib/principles/models/member_file.rb +6 -1
- 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/members_elsewhere.rb +1 -1
- data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
- data/lib/principles/models/members_sharing_lines.rb +1 -1
- data/lib/principles/models/misspelt_member_id.rb +1 -1
- 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 +1 -0
- 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 +3 -3
- data/lib/principles/models/principle_members.rb +1 -1
- data/lib/principles/models/problem_report.rb +13 -1
- data/lib/principles/models/project.rb +8 -3
- data/lib/principles/models/project_at_commit.rb +9 -19
- 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 +1 -0
- 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/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/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 +25 -18
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +12 -9
- data/lib/principles/views/added_member.rb +10 -1
- data/lib/principles/views/answer_in_a_file.rb +16 -4
- 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 +15 -6
- data/lib/principles/views/candidate_files_result.rb +9 -4
- data/lib/principles/views/context_parts.rb +40 -9
- data/lib/principles/views/correction_request.rb +8 -5
- 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/open_findings_decision_result.rb +60 -0
- data/lib/principles/views/problem_facts.rb +46 -0
- data/lib/principles/views/problem_result.rb +42 -31
- data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
- 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/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/list-candidate-files.md +12 -12
- 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/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 +8 -8
- data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
- metadata +14 -7
- 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
|
@@ -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.
|
|
@@ -117,6 +117,11 @@ module Principles
|
|
|
117
117
|
#: (Locator) -> LocatedText
|
|
118
118
|
def locate_for_authoring(locator) = member_file(locator.path).locate_for_authoring(locator)
|
|
119
119
|
|
|
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
|
+
|
|
120
125
|
# The lines locator finds now, as one text; refused as located_text refuses.
|
|
121
126
|
#: (Locator) -> String
|
|
122
127
|
def member_text(locator) = member_file(locator.path).lines_of(locator).join
|
|
@@ -220,10 +225,10 @@ module Principles
|
|
|
220
225
|
def answer(file, stdin:, given:) = SentAnswer.read(@files, file, stdin:, given:)
|
|
221
226
|
|
|
222
227
|
# What list-candidate-files found, as CandidateInventory reads it from the project, after a commit when given.
|
|
223
|
-
#: (?after: String?, ?also: Array[String]) -> CandidateInventory
|
|
224
|
-
def candidate_files(after: nil, also: [])
|
|
228
|
+
#: (?after: String?, ?also: Array[String], ?only: Array[String]) -> CandidateInventory
|
|
229
|
+
def candidate_files(after: nil, also: [], only: [])
|
|
225
230
|
mapped = after ? principles.readable_paths : []
|
|
226
|
-
search_paths = SurveySearchPaths.new(recorded: guidance_search_paths.globs, also:)
|
|
231
|
+
search_paths = SurveySearchPaths.new(recorded: guidance_search_paths.globs, also:, only:)
|
|
227
232
|
CandidateInventory.read(@files, history, search_paths:, after:, mapped:)
|
|
228
233
|
end
|
|
229
234
|
|
|
@@ -40,31 +40,21 @@ module Principles
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
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.
|
|
43
|
+
# member's place in it, since an audit's base needs every member.
|
|
44
44
|
#: (PrincipleMembers) -> Hash[String, String]?
|
|
45
45
|
def hashes(members)
|
|
46
|
-
members.to_h
|
|
47
|
-
|
|
48
|
-
found = text(path)
|
|
49
|
-
return nil unless found
|
|
46
|
+
members.to_h { |member| [member.id, hash_of(member) || (return nil)] }
|
|
47
|
+
end
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
53
55
|
rescue Error
|
|
54
56
|
nil
|
|
55
57
|
end
|
|
56
|
-
|
|
57
|
-
# Each member's key and the hash of its text at the commit, leaving out a member the commit cannot find.
|
|
58
|
-
#: (Array[Hash[String, untyped]]) -> Hash[String, String]
|
|
59
|
-
def hashes_by_key(members)
|
|
60
|
-
members.map { |fields| Member.new(fields) }.each_with_object({}) do |member, found|
|
|
61
|
-
path = member.path
|
|
62
|
-
committed = text(path) or next
|
|
63
|
-
found[member.key] = MemberFile.for(path: path, text: committed).locate(member.locator).sha256
|
|
64
|
-
rescue Error
|
|
65
|
-
next
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
58
|
end
|
|
69
59
|
end
|
|
70
60
|
end
|
|
@@ -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.
|
|
@@ -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
|
|
@@ -4,21 +4,25 @@
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "../prose_list"
|
|
6
6
|
require_relative "request_id"
|
|
7
|
+
require_relative "map_change"
|
|
7
8
|
|
|
8
9
|
module Principles
|
|
9
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
11
|
module Models
|
|
11
12
|
# The refusal of an answer to one principle's audit request that no longer matches the project: its cause, the
|
|
12
|
-
# members changed since the request's base commit when any are known, or
|
|
13
|
-
# and its repair: to answer the audit's open correction when members alone
|
|
13
|
+
# members changed since the request's base commit when any are known, or how its map changed since then, or else
|
|
14
|
+
# every input the request depends on, and its repair: to answer the audit's open correction when members alone
|
|
15
|
+
# changed, or else to start again.
|
|
14
16
|
class StaleRequest
|
|
15
17
|
# principle_id is the principle audited; changed names the members whose text differs from the base commit's;
|
|
16
|
-
# correction_open says whether the principle's record is open, its correction asked for and not yet answered
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
# correction_open says whether the principle's record is open, its correction asked for and not yet answered;
|
|
19
|
+
# map_change is how the map differs from the one the request was printed from, when that is known.
|
|
20
|
+
#: (String, ?Array[String], ?correction_open: bool, ?map_change: MapChange?) -> void
|
|
21
|
+
def initialize(principle_id, changed = [], correction_open: false, map_change: nil)
|
|
19
22
|
@principle_id = principle_id
|
|
20
23
|
@changed = changed
|
|
21
24
|
@correction_open = correction_open
|
|
25
|
+
@map_change = map_change
|
|
22
26
|
freeze
|
|
23
27
|
end
|
|
24
28
|
|
|
@@ -29,13 +33,14 @@ module Principles
|
|
|
29
33
|
|
|
30
34
|
private
|
|
31
35
|
|
|
32
|
-
# The members changed since the base commit, which a request is printed only once they are committed;
|
|
33
|
-
# every input that may have changed.
|
|
36
|
+
# The members changed since the base commit, which a request is printed only once they are committed; or else
|
|
37
|
+
# how its map changed since then; otherwise every input that may have changed.
|
|
34
38
|
#: () -> String
|
|
35
39
|
def cause
|
|
36
40
|
unless @changed.empty?
|
|
37
41
|
return "#{ProseList.new(@changed)} #{@changed.one? ? "has" : "have"} changed since its base commit"
|
|
38
42
|
end
|
|
43
|
+
return "its map has changed since its base commit: #{@map_change}" if @map_change
|
|
39
44
|
|
|
40
45
|
"its map, a member, the commit it was based on, or what says when a listed member loads and how big it is " \
|
|
41
46
|
"(project settings, frontmatter or a listed file), has changed since it was printed, or another release " \
|
|
@@ -44,16 +49,25 @@ module Principles
|
|
|
44
49
|
|
|
45
50
|
# To start the audit again; but while its correction is open and only members changed, that correction stays
|
|
46
51
|
# answerable, since it is checked against the members at the base commit, so the repair names the command that
|
|
47
|
-
# prints its answer again from the open record.
|
|
52
|
+
# prints its answer again from the open record; and after a map change alone, the answer stays worth keeping.
|
|
48
53
|
#: () -> String
|
|
49
54
|
def repair
|
|
50
55
|
start = "#{Error::EXECUTABLE} start-audit #{@principle_id}"
|
|
56
|
+
return carried_over(start, @map_change) if @map_change && @changed.empty?
|
|
51
57
|
return "Start the audit again and answer the new request: #{start}" unless @correction_open && @changed.any?
|
|
52
58
|
|
|
53
59
|
"This audit's correction is still open, and fixing members leaves it current: answer it rather than start " \
|
|
54
60
|
"again, saving its answer from this command's output, filling only its dispositions, and submitting it: " \
|
|
55
61
|
"#{Error::EXECUTABLE} show-open-correction #{@principle_id}"
|
|
56
62
|
end
|
|
63
|
+
|
|
64
|
+
# To carry the answer to a new request, judging again what map_change touched, or to undo map_change.
|
|
65
|
+
#: (String, MapChange) -> String
|
|
66
|
+
def carried_over(start, map_change)
|
|
67
|
+
"Keep this answer. To carry it to a new request, copy that request's request_id and basis into it, judge " \
|
|
68
|
+
"#{map_change.to_judge_again}, and submit it; or change the map back as it was at the base commit, " \
|
|
69
|
+
"commit it, and submit this answer unchanged.\nStart the new request: #{start}"
|
|
70
|
+
end
|
|
57
71
|
end
|
|
58
72
|
end
|
|
59
73
|
end
|
|
@@ -5,7 +5,7 @@ require_relative "prior_findings"
|
|
|
5
5
|
require_relative "request_id"
|
|
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
|
# An answer submitted to the request request_id names, its shape checked, with the prior findings a full
|
|
11
11
|
# audit's request listed, which checking its head found, or nil for any other phase.
|
|
@@ -4,20 +4,28 @@
|
|
|
4
4
|
require_relative "guidance_search_path"
|
|
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
|
# The project's recorded guidance search paths and this invocation's temporary selections, combined once.
|
|
10
|
+
# Selections made with only replace both the recorded paths and the places hosts load by convention, so a
|
|
11
|
+
# survey after a search path is added reads just the files it matches.
|
|
10
12
|
class SurveySearchPaths
|
|
11
13
|
#: Array[String]
|
|
12
14
|
attr_reader :globs
|
|
13
15
|
|
|
14
|
-
#: (recorded: Array[String], also: Array[String]) -> void
|
|
15
|
-
def initialize(recorded:, also:)
|
|
16
|
-
@
|
|
17
|
-
|
|
16
|
+
#: (recorded: Array[String], also: Array[String], ?only: Array[String]) -> void
|
|
17
|
+
def initialize(recorded:, also:, only: [])
|
|
18
|
+
@conventional = only.empty? #: bool
|
|
19
|
+
kept = @conventional ? recorded : [] #: Array[String]
|
|
20
|
+
@recorded = kept.map { |glob| GuidanceSearchPath.new(glob).glob }.uniq.freeze #: Array[String]
|
|
21
|
+
@globs = (@recorded | (also + only).map { |glob| GuidanceSearchPath.new(glob).glob }).freeze #: Array[String]
|
|
18
22
|
freeze
|
|
19
23
|
end
|
|
20
24
|
|
|
25
|
+
# Whether the survey lists the places hosts load by convention as well as these globs' matches.
|
|
26
|
+
#: () -> bool
|
|
27
|
+
def conventional? = @conventional
|
|
28
|
+
|
|
21
29
|
# Saved provenance is distinct from all match counts; omit it when the project records no search paths.
|
|
22
30
|
#: () -> Hash[String, untyped]
|
|
23
31
|
def recorded_listing = @recorded.empty? ? {} : { "recorded_guidance_search_paths" => @recorded }
|
|
@@ -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
|
# A text cut to at most some characters, as a candidate file's outline prints its items, opening line and
|
|
8
8
|
# description: whole when it fits, else back to a sentence end or a whole word.
|
|
@@ -8,6 +8,7 @@ require_relative "principle_members"
|
|
|
8
8
|
require_relative "refusal_before_shape"
|
|
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
|
# The members of a principle that name no check, whose assessments take no check_result. An answer is read for
|
|
13
14
|
# one before its shape is checked, since the shape would ask for the command such a check_result lacks, sending
|
|
@@ -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 project's files outside a principle's map that differ from the audit's base commit, as an assessment
|
|
8
8
|
# request names them. A project with many untracked files would put every one into each request, so
|
|
@@ -5,6 +5,7 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "meta_principle"
|
|
6
6
|
|
|
7
7
|
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
9
|
module Models
|
|
9
10
|
# An absent principle id, whose repair creates an ordinary map or sets up the keeping principle.
|
|
10
11
|
class UnknownPrinciple
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative "prose_line"
|
|
5
|
+
|
|
4
6
|
module Principles
|
|
5
7
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
8
|
module Models
|
|
@@ -9,41 +11,13 @@ module Principles
|
|
|
9
11
|
class WriteUpOpening
|
|
10
12
|
# The longest opening printed whole; a longer one is cut and marked truncated.
|
|
11
13
|
LIMIT = 200
|
|
12
|
-
# A line that starts a new block, a list item or a heading, rather than continuing the paragraph before it.
|
|
13
|
-
NEW_BLOCK = /\A(([-*+]|\d+[.)])\s|#)/
|
|
14
|
-
# What a heading line starts with, a block of its own line.
|
|
15
|
-
HEADING = "#"
|
|
16
14
|
# The end of a sentence: its mark and any closing quotes or brackets, before a space or the end.
|
|
17
15
|
SENTENCE_END = /[.!?]["')\]]*(?=\s|\z)/
|
|
18
16
|
|
|
19
|
-
# One line of the file, as the opening reads it.
|
|
20
|
-
class Line
|
|
21
|
-
#: (String) -> void
|
|
22
|
-
def initialize(text)
|
|
23
|
-
@text = text
|
|
24
|
-
freeze
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# The line without its indentation or line break.
|
|
28
|
-
#: () -> String
|
|
29
|
-
def text = @text.strip
|
|
30
|
-
|
|
31
|
-
#: () -> bool
|
|
32
|
-
def blank? = text.empty?
|
|
33
|
-
|
|
34
|
-
#: () -> bool
|
|
35
|
-
def heading? = text.start_with?(HEADING)
|
|
36
|
-
|
|
37
|
-
# Whether the line continues the paragraph before it: it is not blank and starts no new block. It keeps its
|
|
38
|
-
# line break, which NEW_BLOCK's \s may match, so a bare "-" line still starts a list item.
|
|
39
|
-
#: () -> bool
|
|
40
|
-
def continues? = !blank? && !@text.lstrip.match?(NEW_BLOCK)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
17
|
# lines are the file's lines; the region runs from index first up to, not including, index last.
|
|
44
18
|
#: (lines: Array[String], first: Integer, last: Integer) -> void
|
|
45
19
|
def initialize(lines:, first:, last:)
|
|
46
|
-
@lines = lines.map { |each|
|
|
20
|
+
@lines = lines.map { |each| ProseLine.new(each) } #: Array[ProseLine]
|
|
47
21
|
@first = first
|
|
48
22
|
@last = last
|
|
49
23
|
freeze
|
|
@@ -103,8 +77,8 @@ module Principles
|
|
|
103
77
|
def closed?(text) = text.count("(") <= text.count(")")
|
|
104
78
|
|
|
105
79
|
# The line at index, or a blank one past the file's end.
|
|
106
|
-
#: (Integer) ->
|
|
107
|
-
def line(index) = @lines[index] ||
|
|
80
|
+
#: (Integer) -> ProseLine
|
|
81
|
+
def line(index) = @lines[index] || ProseLine.new("")
|
|
108
82
|
end
|
|
109
83
|
end
|
|
110
84
|
end
|
|
@@ -25,7 +25,8 @@ module Principles
|
|
|
25
25
|
#: () -> bool
|
|
26
26
|
def starting_at? = !@locator.starting_at.nil?
|
|
27
27
|
|
|
28
|
-
# The same heading or starting_at in the file at path, as a
|
|
28
|
+
# The same heading or starting_at in the file at path, as a decision on open findings checks git's match for a
|
|
29
|
+
# missing file.
|
|
29
30
|
#: (String) -> WriteUpPointer
|
|
30
31
|
def in_file(path) = WriteUpPointer.new(to_h.merge("path" => path))
|
|
31
32
|
|