principles 0.0.10 → 0.0.11
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 +11 -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/assessment.rb +1 -1
- data/lib/principles/controllers/audit.rb +2 -1
- 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 +32 -16
- data/lib/principles/controllers/inventory.rb +3 -3
- data/lib/principles/controllers/member_acknowledgement.rb +5 -5
- data/lib/principles/controllers/member_addition.rb +1 -1
- data/lib/principles/controllers/member_entries.rb +1 -1
- data/lib/principles/controllers/member_problems_report.rb +4 -1
- 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/data/command-steps.json +4 -4
- data/lib/principles/data/repository.rb +4 -4
- data/lib/principles/data/running_version.rb +1 -1
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/invocation_options.rb +4 -4
- 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/assessment_answer.rb +2 -2
- data/lib/principles/models/assessment_left_as_printed.rb +1 -1
- data/lib/principles/models/audit.rb +1 -1
- data/lib/principles/models/audit_records.rb +1 -1
- data/lib/principles/models/candidate_inventory.rb +1 -1
- 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/fix_only_fields.rb +4 -3
- data/lib/principles/models/located_text.rb +19 -11
- data/lib/principles/models/member_assessments.rb +11 -4
- data/lib/principles/models/member_file.rb +9 -12
- data/lib/principles/models/member_mapping_run.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_sharing_lines.rb +1 -1
- data/lib/principles/models/misspelt_member_id.rb +9 -3
- data/lib/principles/models/named_placeholder.rb +32 -0
- data/lib/principles/models/other_templates_placeholders.rb +25 -6
- data/lib/principles/models/principle_history.rb +4 -3
- data/lib/principles/models/project.rb +7 -13
- data/lib/principles/models/project_at_commit.rb +70 -0
- data/lib/principles/models/project_history.rb +10 -52
- data/lib/principles/models/sent_answer.rb +4 -3
- data/lib/principles/models/template_placeholders.rb +22 -7
- data/lib/principles/models/text_size.rb +11 -3
- data/lib/principles/models/unfinished_field.rb +34 -0
- data/lib/principles/start_audit_options.rb +10 -2
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledged_result.rb +59 -0
- data/lib/principles/views/acknowledgement_result.rb +32 -42
- data/lib/principles/views/answer_in_a_file.rb +53 -0
- data/lib/principles/views/assessed_members.rb +4 -2
- data/lib/principles/views/audit_result.rb +3 -1
- data/lib/principles/views/context_parts.rb +1 -1
- data/lib/principles/views/correction_request.rb +19 -13
- data/lib/principles/views/member_repairs.rb +21 -5
- data/lib/principles/views/meta_principle_result.rb +26 -5
- 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_lines.rb +8 -3
- data/lib/principles/views/problem_result.rb +11 -0
- data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
- 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-member-problems.md +7 -8
- 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/start-audit.md +5 -5
- 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 +13 -2
|
@@ -22,6 +22,22 @@ module Principles
|
|
|
22
22
|
# tracked by git only under another spelling.
|
|
23
23
|
FILE_NOT_AT_PATH = %w[unreadable_file renamed_in_case].freeze #: Array[String]
|
|
24
24
|
|
|
25
|
+
# One move: the locator fields it keeps, by name, and those the agent fills in.
|
|
26
|
+
class Move
|
|
27
|
+
#: Hash[String, untyped]
|
|
28
|
+
attr_reader :keep
|
|
29
|
+
|
|
30
|
+
#: Array[String]
|
|
31
|
+
attr_reader :fill
|
|
32
|
+
|
|
33
|
+
#: (Hash[String, untyped], Array[String]) -> void
|
|
34
|
+
def initialize(keep, fill)
|
|
35
|
+
@keep = keep
|
|
36
|
+
@fill = fill
|
|
37
|
+
freeze
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
25
41
|
# member is the member's locator fields, as its map holds them; code is that of the refusal saying why it cannot
|
|
26
42
|
# be found, and tracked_as the spelling git tracks its path under, which a renamed_in_case refusal gives.
|
|
27
43
|
#: (Hash[String, untyped], code: String?, ?tracked_as: String?) -> void
|
|
@@ -32,8 +48,8 @@ module Principles
|
|
|
32
48
|
freeze
|
|
33
49
|
end
|
|
34
50
|
|
|
35
|
-
# Each move
|
|
36
|
-
#: () -> Array[
|
|
51
|
+
# Each move that may repair the member.
|
|
52
|
+
#: () -> Array[Move]
|
|
37
53
|
def to_a
|
|
38
54
|
return [move(@member.merge("path" => @tracked_as), [])] if @code == "renamed_in_case" && @tracked_as
|
|
39
55
|
return [move(@member, %w[path])] if FILE_NOT_AT_PATH.include?(@code)
|
|
@@ -51,8 +67,8 @@ module Principles
|
|
|
51
67
|
#: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
|
|
52
68
|
def given(member, fields) = fields.filter_map { [it, member[it]] unless member[it].nil? }.to_h.freeze
|
|
53
69
|
|
|
54
|
-
#: (Hash[String, untyped], Array[String]) ->
|
|
55
|
-
def move(keep, fill) =
|
|
70
|
+
#: (Hash[String, untyped], Array[String]) -> Move
|
|
71
|
+
def move(keep, fill) = Move.new(keep, fill)
|
|
56
72
|
end
|
|
57
73
|
end
|
|
58
74
|
end
|
|
@@ -14,36 +14,36 @@ module Principles
|
|
|
14
14
|
#: (Project, Principle) -> MemberSnapshots
|
|
15
15
|
def self.read(project, map)
|
|
16
16
|
broken = [] #: Array[Hash[String, untyped]]
|
|
17
|
-
found =
|
|
18
|
-
|
|
17
|
+
found = {} #: Hash[String, LocatedText]
|
|
18
|
+
map.members.each do |member|
|
|
19
|
+
found[member.id] = project.located_text(member.locator)
|
|
19
20
|
rescue Error => e
|
|
20
21
|
broken << { "id" => member.id }.merge(e.payload.except("status"))
|
|
21
|
-
[member.id, {}]
|
|
22
22
|
end
|
|
23
23
|
broken.empty? ? new(found) : project.refuse_broken(map.id, broken)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
#: (Hash[String,
|
|
26
|
+
#: (Hash[String, LocatedText]) -> void
|
|
27
27
|
def initialize(by_id)
|
|
28
|
-
@by_id = by_id.freeze #: Hash[String,
|
|
28
|
+
@by_id = by_id.freeze #: Hash[String, LocatedText]
|
|
29
29
|
freeze
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
# Each member's
|
|
33
|
-
#: () -> Hash[String,
|
|
32
|
+
# Each member's located text by id.
|
|
33
|
+
#: () -> Hash[String, LocatedText]
|
|
34
34
|
def to_h = @by_id
|
|
35
35
|
|
|
36
36
|
# Where the member id is in its file now, and the hash of what it says there.
|
|
37
37
|
#: (String) -> LocatedText
|
|
38
|
-
def of(id) =
|
|
38
|
+
def of(id) = @by_id.fetch(id)
|
|
39
39
|
|
|
40
40
|
# Each member's id and the hash of its text now.
|
|
41
41
|
#: () -> Hash[String, String]
|
|
42
|
-
def hashes = @by_id.transform_values
|
|
42
|
+
def hashes = @by_id.transform_values(&:sha256)
|
|
43
43
|
|
|
44
44
|
# The lines the members span now, against which another principle's evidence is said to share them.
|
|
45
45
|
#: () -> AuditedMemberLines
|
|
46
|
-
def audited_lines = AuditedMemberLines.new(@by_id
|
|
46
|
+
def audited_lines = AuditedMemberLines.new(@by_id)
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -15,7 +15,7 @@ module Principles
|
|
|
15
15
|
# each. The project locates the others; a member this tool cannot find now is left out, since show-principle
|
|
16
16
|
# reports it.
|
|
17
17
|
class MembersSharingLines
|
|
18
|
-
# The members sharing a line with member, located where it is now; refuses as Project#
|
|
18
|
+
# The members sharing a line with member, located where it is now; refuses as Project#located_text does when it
|
|
19
19
|
# cannot be found.
|
|
20
20
|
#: (Project, Member) -> MembersSharingLines
|
|
21
21
|
def self.of(project, member)
|
|
@@ -19,11 +19,13 @@ module Principles
|
|
|
19
19
|
freeze
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
# The one mapped id spelled like this one apart from punctuation, case and spacing, or
|
|
22
|
+
# The one mapped id spelled like this one apart from punctuation, case and spacing, or else the one whose
|
|
23
|
+
# heading or passage this is, as an agent gives a passage's start text without its path@ prefix; nil when
|
|
24
|
+
# none or several are. It is only named, for the agent to judge.
|
|
23
25
|
#: (Array[String]) -> String?
|
|
24
26
|
def closest(mapped)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
only(mapped.select { |each| loose(each) == loose(@id) }) ||
|
|
28
|
+
only(mapped.select { |each| each.end_with?("##{@id}", "@#{@id}") })
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
# What a refusal says of this id: that it is not mapped, and the mapped id it is spelled like; nil when none.
|
|
@@ -35,6 +37,10 @@ module Principles
|
|
|
35
37
|
|
|
36
38
|
private
|
|
37
39
|
|
|
40
|
+
# The one id among matches, or nil.
|
|
41
|
+
#: (Array[String]) -> String?
|
|
42
|
+
def only(matches) = (matches.first if matches.one?)
|
|
43
|
+
|
|
38
44
|
#: (String) -> String
|
|
39
45
|
def loose(text)
|
|
40
46
|
text.unicode_normalize(:nfkc).gsub(APOSTROPHES, "'").gsub(QUOTES, '"').gsub(DASHES, "-")
|
|
@@ -0,0 +1,32 @@
|
|
|
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 placeholder a template prints naming the id of the slot it fills, a member's or a finding's, so no two slots
|
|
8
|
+
# are alike and a file-edit tool's one-match replace fills one. Its text for any id, or the text it printed
|
|
9
|
+
# before it named one, sent in any slot, is left as printed.
|
|
10
|
+
class NamedPlaceholder
|
|
11
|
+
# The slot in slotted that each slot's id fills.
|
|
12
|
+
SLOT = "%<id>s" #: String
|
|
13
|
+
|
|
14
|
+
# slotted is the text with SLOT where the id goes; before is the text it printed before it named one.
|
|
15
|
+
#: (String, before: String) -> void
|
|
16
|
+
def initialize(slotted, before:)
|
|
17
|
+
@slotted = slotted
|
|
18
|
+
@before = before
|
|
19
|
+
@pattern = /\A#{Regexp.escape(slotted).sub(Regexp.escape(SLOT), ".+")}\z/m #: Regexp
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# The text with SLOT, which a controller hands the view that fills each slot's id.
|
|
24
|
+
#: String
|
|
25
|
+
attr_reader :slotted
|
|
26
|
+
|
|
27
|
+
# Whether text is this placeholder, for any id or as it was printed before it named one.
|
|
28
|
+
#: (untyped) -> bool
|
|
29
|
+
def left?(text) = text == @before || (text.is_a?(String) && @pattern.match?(text))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "acknowledgement"
|
|
6
6
|
require_relative "assessment_answer"
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "disposition_placeholders"
|
|
8
8
|
require_relative "loading_decision"
|
|
9
9
|
require_relative "member_assessments"
|
|
10
|
+
require_relative "named_placeholder"
|
|
10
11
|
require_relative "prior_decision_fields"
|
|
11
12
|
require_relative "recent_decision"
|
|
12
13
|
require_relative "refusal_before_shape"
|
|
@@ -63,12 +64,19 @@ module Principles
|
|
|
63
64
|
# decision, the correction's disposition, and the one-member audit's acknowledgement. Its spec fails on a
|
|
64
65
|
# placeholder constant in models/ missing here.
|
|
65
66
|
KNOWN = [
|
|
66
|
-
MemberAssessments::PLACEHOLDER,
|
|
67
|
+
MemberAssessments::PLACEHOLDER, MemberAssessments::NAMED_PLACEHOLDER, AssessmentAnswer::COLLECTIVE_PLACEHOLDER,
|
|
68
|
+
RecentDecision::PLACEHOLDERS.to_h,
|
|
67
69
|
ReportedCheck::PLACEHOLDERS.to_h, ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h,
|
|
68
70
|
LoadingDecision::PLACEHOLDERS.to_h, PriorDecisionFields::TEMPLATE_PLACEHOLDERS,
|
|
69
|
-
|
|
71
|
+
DispositionPlaceholders::TEMPLATE_PLACEHOLDERS, DispositionPlaceholders::ACTION_PLACEHOLDER,
|
|
72
|
+
AcknowledgementPlaceholders::PLACEHOLDERS.to_h, AcknowledgementPlaceholders::EXIT_STATUS_PLACEHOLDER
|
|
70
73
|
].then { Strings.new(it).by_pointer.values.to_set }.freeze #: Set[String]
|
|
71
74
|
|
|
75
|
+
# Every placeholder a template of this release prints naming its slot's id, for any id or as printed before
|
|
76
|
+
# it named one.
|
|
77
|
+
NAMED = [MemberAssessments::ASSESSMENT, *DispositionPlaceholders::NAMED,
|
|
78
|
+
*AcknowledgementPlaceholders::PLACEHOLDERS.named].freeze #: Array[NamedPlaceholder]
|
|
79
|
+
|
|
72
80
|
# Each string in template, a request's template as printed, which its answer may send back; start_from says
|
|
73
81
|
# where that template is printed, as RequestId#answer_to_fill gives it.
|
|
74
82
|
#: (untyped, start_from: String) -> OtherTemplatesPlaceholders
|
|
@@ -76,11 +84,14 @@ module Principles
|
|
|
76
84
|
new(Strings.new(template).by_pointer.values, start_from:)
|
|
77
85
|
end
|
|
78
86
|
|
|
79
|
-
# printed is the placeholders the request's own template printed, which an answer may leave as printed,
|
|
80
|
-
# start_from where that template is
|
|
87
|
+
# printed is the placeholders the request's own template printed, which an answer may leave as printed, each
|
|
88
|
+
# with NamedPlaceholder::SLOT where it names its slot's id, for any id, and start_from where that template is
|
|
89
|
+
# printed.
|
|
81
90
|
#: (Array[String], start_from: String) -> void
|
|
82
91
|
def initialize(printed, start_from:)
|
|
83
92
|
@printed = printed
|
|
93
|
+
@printed_named = printed.select { it.include?(NamedPlaceholder::SLOT) }
|
|
94
|
+
.map { NamedPlaceholder.new(it, before: it) } #: Array[NamedPlaceholder]
|
|
84
95
|
@repair = "Start from #{start_from}, or replace each field named with your own text; if one is your own " \
|
|
85
96
|
"text, reword its ending" #: String
|
|
86
97
|
end
|
|
@@ -108,7 +119,15 @@ module Principles
|
|
|
108
119
|
|
|
109
120
|
# Whether text ends as a placeholder does, or is one another template prints, but is none printed.
|
|
110
121
|
#: (String) -> bool
|
|
111
|
-
def other?(text) = (
|
|
122
|
+
def other?(text) = (known?(text) || NAMED.any? { it.left?(text) }) && !printed?(text)
|
|
123
|
+
|
|
124
|
+
# Whether the request's own template printed text, a slot's id in any named placeholder.
|
|
125
|
+
#: (String) -> bool
|
|
126
|
+
def printed?(text) = @printed.include?(text) || @printed_named.any? { it.left?(text) }
|
|
127
|
+
|
|
128
|
+
# Whether text ends as a placeholder does, or is one a model's constant holds.
|
|
129
|
+
#: (String) -> bool
|
|
130
|
+
def known?(text) = text.match?(ENDING) || KNOWN.include?(text)
|
|
112
131
|
end
|
|
113
132
|
end
|
|
114
133
|
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).hashes_by_key([fields]).values.first)
|
|
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.hashes_by_key([fields])[key] || then_project.hashes_by_key([now_at])[key]
|
|
179
180
|
end
|
|
180
181
|
|
|
181
182
|
# Each member the map at commit holds, by key. Legacy unreadable maps give nil; certified proof failures
|
|
@@ -113,23 +113,17 @@ 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 lines locator finds now, as one text; refused as
|
|
120
|
+
# The lines locator finds now, as one text; refused as located_text refuses.
|
|
127
121
|
#: (Locator) -> String
|
|
128
122
|
def member_text(locator) = member_file(locator.path).lines_of(locator).join
|
|
129
123
|
|
|
130
124
|
# The text locator finds now, as one value: its path, its lines and the hash of what it says.
|
|
131
125
|
#: (Locator) -> LocatedText
|
|
132
|
-
def located_text(locator) =
|
|
126
|
+
def located_text(locator) = member_file(locator.path).locate(locator)
|
|
133
127
|
|
|
134
128
|
# The member at locator, its lines in its file at commit beside its lines now, which an audit shows the
|
|
135
129
|
# agent so it judges the member's own change without the rest of its file's; nil when commit lacks the
|
|
@@ -137,7 +131,7 @@ module Principles
|
|
|
137
131
|
# then_locator places it at commit where it was elsewhere then, as before a move.
|
|
138
132
|
#: (Locator, since: String, ?then_locator: Locator) -> MemberLines?
|
|
139
133
|
def member_lines(locator, since:, then_locator: locator)
|
|
140
|
-
before = history.
|
|
134
|
+
before = history.at(since).lines(then_locator) or return nil
|
|
141
135
|
|
|
142
136
|
MemberLines.new(at_baseline: before, now: member_file(locator.path).lines_of(locator))
|
|
143
137
|
end
|
|
@@ -175,7 +169,7 @@ module Principles
|
|
|
175
169
|
#: (PrincipleMembers) -> Hash[String, untyped]
|
|
176
170
|
def current_by_key(members)
|
|
177
171
|
members.to_h do |member|
|
|
178
|
-
[member.key,
|
|
172
|
+
[member.key, located_text(member.locator).sha256]
|
|
179
173
|
rescue Error => e
|
|
180
174
|
[member.key, e.payload]
|
|
181
175
|
end
|
|
@@ -193,8 +187,8 @@ module Principles
|
|
|
193
187
|
# refusal.
|
|
194
188
|
#: (Locator) { (String) -> String } -> Hash[String, untyped]
|
|
195
189
|
def freshness(locator, &)
|
|
196
|
-
now =
|
|
197
|
-
{ "snapshot" => now, "freshness" => yield(now.
|
|
190
|
+
now = located_text(locator)
|
|
191
|
+
{ "snapshot" => now.to_h, "freshness" => yield(now.sha256) }
|
|
198
192
|
rescue Error => e
|
|
199
193
|
{ "freshness" => LocateRefusal.new(e.payload).member_state, "error" => e.payload }
|
|
200
194
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
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.
|
|
44
|
+
#: (PrincipleMembers) -> Hash[String, String]?
|
|
45
|
+
def hashes(members)
|
|
46
|
+
members.to_h do |member|
|
|
47
|
+
path = member.path
|
|
48
|
+
found = text(path)
|
|
49
|
+
return nil unless found
|
|
50
|
+
|
|
51
|
+
[member.id, MemberFile.for(path: path, text: found).locate(member.locator).sha256]
|
|
52
|
+
end
|
|
53
|
+
rescue Error
|
|
54
|
+
nil
|
|
55
|
+
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
|
+
end
|
|
69
|
+
end
|
|
70
|
+
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)
|
|
@@ -22,9 +22,10 @@ module Principles
|
|
|
22
22
|
# What a refusal to read its file calls that file.
|
|
23
23
|
FILE_NAMED = "The answer file" #: String
|
|
24
24
|
|
|
25
|
-
# The repair of a field-by-field
|
|
26
|
-
#
|
|
27
|
-
REPAIR = "Repair each field listed
|
|
25
|
+
# The repair of a field-by-field refusal for the acknowledgements phase, whose controller refuses its own
|
|
26
|
+
# fields: the agent repairs the bare answer it saved and fills, which --as template prints.
|
|
27
|
+
REPAIR = "Repair each field listed in the answer you saved from start-audit with the same --member options " \
|
|
28
|
+
"and --as template." #: String
|
|
28
29
|
|
|
29
30
|
# The answer read from the file or stdin the agent named, to the request given, the REQUEST_ID the agent typed,
|
|
30
31
|
# or when it typed none the request_id the answer names, as its template printed it, using that request's
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "left_as_printed"
|
|
5
|
+
require_relative "named_placeholder"
|
|
5
6
|
require_relative "refusal_before_shape"
|
|
6
7
|
|
|
7
8
|
module Principles
|
|
@@ -16,26 +17,32 @@ module Principles
|
|
|
16
17
|
# placeholders is the text printed in each field, by field name, or for a field that takes pointers, one pointer
|
|
17
18
|
# whose fields hold that text, so the template shows their shape; empty_lists names the fields a template
|
|
18
19
|
# may instead start as an empty list, which is not given either; also_printed, the other text a template
|
|
19
|
-
# may print in a field, refused alike.
|
|
20
|
-
|
|
20
|
+
# may print in a field, refused alike. A NamedPlaceholder in either prints with its slot, which the view fills
|
|
21
|
+
# with the id of the entry it prints in, and is left as printed for any id.
|
|
22
|
+
#: (Hash[String, untyped], ?empty_lists: Array[String], ?also_printed: Hash[String, untyped]) -> void
|
|
21
23
|
def initialize(placeholders, empty_lists: [], also_printed: {})
|
|
22
24
|
@placeholders = placeholders.freeze #: Hash[String, untyped]
|
|
23
25
|
@empty_lists = empty_lists.freeze #: Array[String]
|
|
24
|
-
@also_printed = also_printed.freeze #: Hash[String,
|
|
26
|
+
@also_printed = also_printed.freeze #: Hash[String, untyped]
|
|
25
27
|
freeze
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
# The text printed in each field, with field's other text in place of its own.
|
|
29
31
|
#: (String) -> Hash[String, untyped]
|
|
30
|
-
def with_other_text_in(field) =
|
|
32
|
+
def with_other_text_in(field) = to_h.merge(field => shown(@also_printed.fetch(field)))
|
|
33
|
+
|
|
34
|
+
# Each placeholder printed in its own field naming its entry's id; a field's other text is printed only by
|
|
35
|
+
# some of its requests, so another template leaving it is not read as this one's.
|
|
36
|
+
#: () -> Array[NamedPlaceholder]
|
|
37
|
+
def named = @placeholders.values.grep(NamedPlaceholder)
|
|
31
38
|
|
|
32
39
|
# The text printed in each field, for the view that prints it.
|
|
33
40
|
#: () -> Hash[String, untyped]
|
|
34
|
-
def to_h = @placeholders
|
|
41
|
+
def to_h = @placeholders.transform_values { shown(it) }
|
|
35
42
|
|
|
36
43
|
# The text printed in field.
|
|
37
44
|
#: (String) -> untyped
|
|
38
|
-
def fetch(field) = @placeholders.fetch(field)
|
|
45
|
+
def fetch(field) = shown(@placeholders.fetch(field))
|
|
39
46
|
|
|
40
47
|
# fields, without each one left as its placeholder, which is not given.
|
|
41
48
|
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
@@ -65,7 +72,15 @@ module Principles
|
|
|
65
72
|
|
|
66
73
|
# Whether value is a text the template prints in field.
|
|
67
74
|
#: (String, untyped) -> bool
|
|
68
|
-
def printed?(field, value)
|
|
75
|
+
def printed?(field, value)
|
|
76
|
+
[@placeholders[field], @also_printed[field]].compact.any? do |printed|
|
|
77
|
+
printed.is_a?(NamedPlaceholder) ? printed.left?(value) : printed == value
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# placeholder as the template prints it, a NamedPlaceholder with its slot.
|
|
82
|
+
#: (untyped) -> untyped
|
|
83
|
+
def shown(placeholder) = placeholder.is_a?(NamedPlaceholder) ? placeholder.slotted : placeholder
|
|
69
84
|
end
|
|
70
85
|
end
|
|
71
86
|
end
|
|
@@ -13,13 +13,21 @@ module Principles
|
|
|
13
13
|
freeze
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
# Its bytes, none for a text not measured.
|
|
17
|
+
#: () -> Integer
|
|
18
|
+
def bytes = @text.to_s.bytesize
|
|
19
|
+
|
|
20
|
+
# Its tokens, estimated as characters / 4, rounded up; none for a text not measured.
|
|
21
|
+
#: () -> Integer
|
|
22
|
+
def estimated_tokens = (@text.to_s.length / 4.0).ceil
|
|
23
|
+
|
|
16
24
|
# The size under fields' two names, its bytes then its tokens; empty when there is no text.
|
|
17
25
|
#: ([String, String]) -> Hash[String, Integer]
|
|
18
26
|
def under(fields)
|
|
19
|
-
|
|
27
|
+
return {} unless @text
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
{
|
|
29
|
+
bytes_field, tokens_field = fields
|
|
30
|
+
{ bytes_field => bytes, tokens_field => estimated_tokens }
|
|
23
31
|
end
|
|
24
32
|
end
|
|
25
33
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "answer_place"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# A field the agent left unfinished: empty, the template's placeholder, the answer guide's sample, or
|
|
10
|
+
# an action not one of the four. It says where it sits in the answer and what to write there, which one
|
|
11
|
+
# refusal lists beside every other.
|
|
12
|
+
class UnfinishedField
|
|
13
|
+
#: String
|
|
14
|
+
attr_reader :repair
|
|
15
|
+
|
|
16
|
+
#: (AnswerPlace, String, problem: String, repair: String) -> void
|
|
17
|
+
def initialize(place, name, problem:, repair:)
|
|
18
|
+
@place = place
|
|
19
|
+
@name = name
|
|
20
|
+
@problem = problem
|
|
21
|
+
@repair = repair
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Whose field it is, such as "Finding F1 reason".
|
|
26
|
+
#: () -> String
|
|
27
|
+
def to_s = "#{@place.subject} #{@name}"
|
|
28
|
+
|
|
29
|
+
# Its entry in the refusal's fields, as a malformed answer's are.
|
|
30
|
+
#: () -> Hash[String, String]
|
|
31
|
+
def field = { "pointer" => @place.pointer, "problem" => @problem }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -7,6 +7,9 @@ module Principles
|
|
|
7
7
|
# The options that choose which audit start-audit begins, --member and --write-ups, and the form --as prints
|
|
8
8
|
# it in, and what is wrong with them as given, which CommandLine refuses as a usage error.
|
|
9
9
|
class StartAuditOptions
|
|
10
|
+
# The part that prints the answer to fill bare, saved as it stands, so no other part may print beside it.
|
|
11
|
+
TEMPLATE_PART = "response_template" #: String
|
|
12
|
+
|
|
10
13
|
# several_ids is whether start-audit was given more than one principle id.
|
|
11
14
|
#: (InvocationOptions, ?several_ids: bool) -> void
|
|
12
15
|
def initialize(options, several_ids: false)
|
|
@@ -16,7 +19,8 @@ module Principles
|
|
|
16
19
|
@write_ups = !options.value("write_ups").nil? #: bool
|
|
17
20
|
@form = options.value("as") #: String?
|
|
18
21
|
@instruction = !options.value("instruction").nil? #: bool
|
|
19
|
-
@
|
|
22
|
+
@parts = options.value("part") || [] #: Array[String]
|
|
23
|
+
@part = !@parts.empty? #: bool
|
|
20
24
|
freeze
|
|
21
25
|
end
|
|
22
26
|
|
|
@@ -53,7 +57,11 @@ module Principles
|
|
|
53
57
|
return unless @part
|
|
54
58
|
|
|
55
59
|
other = other_audit || ("the whole field --instruction prints" if @instruction)
|
|
56
|
-
"--part prints one part of a full audit's request, not of #{other}" if other
|
|
60
|
+
return "--part prints one part of a full audit's request, not of #{other}" if other
|
|
61
|
+
|
|
62
|
+
return unless @parts.include?(TEMPLATE_PART) && @parts.size > 1
|
|
63
|
+
|
|
64
|
+
"--part #{TEMPLATE_PART} prints the bare answer to save as it stands; give it alone"
|
|
57
65
|
end
|
|
58
66
|
|
|
59
67
|
# --instruction prints one field of a full audit's request whole; nil when nothing beside it prints
|