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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +0 -2
  4. data/lib/principles/controllers/acknowledgement.rb +11 -4
  5. data/lib/principles/controllers/acknowledgements.rb +4 -4
  6. data/lib/principles/controllers/assessment.rb +1 -1
  7. data/lib/principles/controllers/audit.rb +2 -1
  8. data/lib/principles/controllers/broken_member_repairs.rb +60 -0
  9. data/lib/principles/controllers/command.rb +8 -30
  10. data/lib/principles/controllers/correction.rb +7 -5
  11. data/lib/principles/controllers/full_audit_request.rb +32 -16
  12. data/lib/principles/controllers/inventory.rb +3 -3
  13. data/lib/principles/controllers/member_acknowledgement.rb +5 -5
  14. data/lib/principles/controllers/member_addition.rb +1 -1
  15. data/lib/principles/controllers/member_entries.rb +1 -1
  16. data/lib/principles/controllers/member_problems_report.rb +4 -1
  17. data/lib/principles/controllers/members_to_assess.rb +1 -1
  18. data/lib/principles/controllers/meta_principle_setup.rb +4 -3
  19. data/lib/principles/controllers/open_correction.rb +3 -3
  20. data/lib/principles/data/command-steps.json +4 -4
  21. data/lib/principles/data/repository.rb +4 -4
  22. data/lib/principles/data/running_version.rb +1 -1
  23. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  24. data/lib/principles/invocation_options.rb +4 -4
  25. data/lib/principles/models/acknowledgement.rb +1 -27
  26. data/lib/principles/models/acknowledgement_left_as_printed.rb +2 -1
  27. data/lib/principles/models/acknowledgement_placeholders.rb +48 -0
  28. data/lib/principles/models/assessment_answer.rb +2 -2
  29. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  30. data/lib/principles/models/audit.rb +1 -1
  31. data/lib/principles/models/audit_records.rb +1 -1
  32. data/lib/principles/models/candidate_inventory.rb +1 -1
  33. data/lib/principles/models/disposition.rb +12 -76
  34. data/lib/principles/models/disposition_placeholders.rb +48 -0
  35. data/lib/principles/models/disposition_text_field.rb +41 -0
  36. data/lib/principles/models/evidence_item.rb +1 -1
  37. data/lib/principles/models/fix_only_fields.rb +4 -3
  38. data/lib/principles/models/located_text.rb +19 -11
  39. data/lib/principles/models/member_assessments.rb +11 -4
  40. data/lib/principles/models/member_file.rb +9 -12
  41. data/lib/principles/models/member_mapping_run.rb +1 -1
  42. data/lib/principles/models/member_repair_moves.rb +20 -4
  43. data/lib/principles/models/member_snapshots.rb +10 -10
  44. data/lib/principles/models/members_sharing_lines.rb +1 -1
  45. data/lib/principles/models/misspelt_member_id.rb +9 -3
  46. data/lib/principles/models/named_placeholder.rb +32 -0
  47. data/lib/principles/models/other_templates_placeholders.rb +25 -6
  48. data/lib/principles/models/principle_history.rb +4 -3
  49. data/lib/principles/models/project.rb +7 -13
  50. data/lib/principles/models/project_at_commit.rb +70 -0
  51. data/lib/principles/models/project_history.rb +10 -52
  52. data/lib/principles/models/sent_answer.rb +4 -3
  53. data/lib/principles/models/template_placeholders.rb +22 -7
  54. data/lib/principles/models/text_size.rb +11 -3
  55. data/lib/principles/models/unfinished_field.rb +34 -0
  56. data/lib/principles/start_audit_options.rb +10 -2
  57. data/lib/principles/version.rb +2 -2
  58. data/lib/principles/views/acknowledged_result.rb +59 -0
  59. data/lib/principles/views/acknowledgement_result.rb +32 -42
  60. data/lib/principles/views/answer_in_a_file.rb +53 -0
  61. data/lib/principles/views/assessed_members.rb +4 -2
  62. data/lib/principles/views/audit_result.rb +3 -1
  63. data/lib/principles/views/context_parts.rb +1 -1
  64. data/lib/principles/views/correction_request.rb +19 -13
  65. data/lib/principles/views/member_repairs.rb +21 -5
  66. data/lib/principles/views/meta_principle_result.rb +26 -5
  67. data/lib/principles/views/parts_index_result.rb +8 -6
  68. data/lib/principles/views/principle_read_result.rb +2 -2
  69. data/lib/principles/views/problem_lines.rb +8 -3
  70. data/lib/principles/views/problem_result.rb +11 -0
  71. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
  72. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  73. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-check.md +4 -3
  74. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +4 -3
  75. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +7 -8
  76. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +4 -3
  77. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member-check.md +4 -3
  78. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +4 -3
  79. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +13 -12
  80. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +5 -5
  81. data/lib/principles/views/prompts/start-a-session/act-on-the-changed-principles.md +2 -0
  82. data/lib/principles/views/prompts.rb +7 -4
  83. metadata +13 -2
@@ -9,12 +9,12 @@ module Principles
9
9
  class InvocationOptions
10
10
  # The options that take a value; --help, -h and --version take none.
11
11
  VALUE_OPTIONS = %w[project file description path section starting-at ending-at query role
12
- check session-start commits-after hook-event as instruction part].freeze #: Array[String]
12
+ check session-start commits-after hook-event as instruction].freeze #: Array[String]
13
13
  # The options that take no value, as list-member-problems --short.
14
- FLAG_OPTIONS = %w[short lines when-invoked always write-ups confirm open-findings].freeze #: Array[String]
14
+ FLAG_OPTIONS = %w[short lines when-invoked always write-ups confirm open-findings history].freeze #: Array[String]
15
15
  # The options that may be given more than once, each value kept in order, as change-activation --when-files and
16
- # start-audit --member.
17
- LIST_OPTIONS = %w[when-files also member].freeze #: Array[String]
16
+ # start-audit --member and --part.
17
+ LIST_OPTIONS = %w[when-files also member part].freeze #: Array[String]
18
18
  # The words that name an option taking the next word as its value.
19
19
  VALUE_WORDS = (VALUE_OPTIONS + LIST_OPTIONS).map { |name| "--#{name}" }.freeze #: Array[String]
20
20
  # Every word the parser reads as an option, which an option taking a value refuses as its value.
@@ -3,7 +3,7 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "acknowledged_check"
6
- require_relative "acknowledgement_left_as_printed"
6
+ require_relative "acknowledgement_placeholders"
7
7
  require_relative "acknowledgement_refusal"
8
8
  require_relative "acknowledgements"
9
9
  require_relative "request_id"
@@ -12,8 +12,6 @@ require_relative "member"
12
12
  require_relative "member_lines"
13
13
  require_relative "placement"
14
14
  require_relative "quoted_change"
15
- require_relative "reported_check"
16
- require_relative "template_placeholders"
17
15
 
18
16
  module Principles
19
17
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -23,30 +21,6 @@ module Principles
23
21
  # Refused outside git, for a member no completed audit assessed, and for an unchanged or checked member.
24
22
  class Acknowledgement
25
23
  PHASE = "acknowledgement"
26
- # The text the answer's template prints in each field the agent judges, which an answer may not send back, so
27
- # a template returned as printed acknowledges nothing. It prints no quotes, which an answer leaving them
28
- # out reads as first_changed_lines. After a pure insertion, meaning_kept's says that an
29
- # inserted line usually adds a rule, for an agent that reads the template alone.
30
- PLACEHOLDERS = TemplatePlaceholders.new(
31
- { "meaning_kept" => "true only if the member still says the same thing",
32
- "reason" => "Why, in one line of your own" },
33
- also_printed: { "meaning_kept" => "true only if the member still says the same thing; this change inserted " \
34
- "a line, which usually adds a rule" }
35
- ) #: TemplatePlaceholders
36
- # The text a checked member's template prints where its check's exit status goes, short since the request's
37
- # context says how to run the check.
38
- EXIT_STATUS_PLACEHOLDER = ReportedCheck::EXIT_STATUS_PLACEHOLDER #: String
39
- # The fields an answer may not send back as the template printed them, refused before its shape.
40
- LEFT_AS_PRINTED = AcknowledgementLeftAsPrinted.new(
41
- PLACEHOLDERS, exit_status: EXIT_STATUS_PLACEHOLDER
42
- ) #: AcknowledgementLeftAsPrinted
43
-
44
- # The placeholders the template prints beside quotes, its first_changed_lines.
45
- #: (Hash[String, String]) -> Hash[String, untyped]
46
- def self.placeholders_beside(quotes)
47
- quotes["old_line"] == "" ? PLACEHOLDERS.with_other_text_in("meaning_kept") : PLACEHOLDERS.to_h
48
- end
49
-
50
24
  # before holds the member's lines at its baseline commit, now its lines and hash at base, HEAD.
51
25
  #: (principle_id: String, member: Member, record: AuditRecord?, base: String?, now_sha256: String) -> void
52
26
  def initialize(principle_id:, member:, record:, base:, now_sha256:)
@@ -12,7 +12,8 @@ module Principles
12
12
  # The fields a one-member audit's answer leaves as its template printed them, refused in one refusal before the
13
13
  # answer's shape: its judgement's, meaning_kept and reason, and a checked member's exit_status, which was
14
14
  # otherwise refused as text with a repair offering the not_run_reason this template refuses. It holds the
15
- # placeholders the template prints in each; Acknowledgement::LEFT_AS_PRINTED is the one every acknowledgement uses.
15
+ # placeholders the template prints in each; AcknowledgementPlaceholders::LEFT_AS_PRINTED is the one every
16
+ # acknowledgement uses.
16
17
  class AcknowledgementLeftAsPrinted
17
18
  include RefusalBeforeShape
18
19
 
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "acknowledgement_left_as_printed"
5
+ require_relative "named_placeholder"
6
+ require_relative "reported_check"
7
+ require_relative "template_placeholders"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # The text a one-member audit's template prints in each field the agent writes, and the refusal of an answer
13
+ # that sends any back as printed.
14
+ class AcknowledgementPlaceholders
15
+ # The text the answer's template prints in each field the agent judges, which an answer may not send back, so
16
+ # a template returned as printed acknowledges nothing. It prints no quotes, which an answer leaving them
17
+ # out reads as first_changed_lines. After a pure insertion, meaning_kept's says that an
18
+ # inserted line usually adds a rule, for an agent that reads the template alone.
19
+ # Each names the member of the entry it is printed in, so no two members' slots are alike and one edit fills
20
+ # one; any member's, or the text printed before each named one, is left as printed.
21
+ PLACEHOLDERS = TemplatePlaceholders.new(
22
+ { "meaning_kept" => NamedPlaceholder.new("true only if #{NamedPlaceholder::SLOT} still says the same thing",
23
+ before: "true only if the member still says the same thing"),
24
+ "reason" => NamedPlaceholder.new("Why, for #{NamedPlaceholder::SLOT}, in one line of your own",
25
+ before: "Why, in one line of your own") },
26
+ also_printed: { "meaning_kept" => NamedPlaceholder.new(
27
+ "true only if #{NamedPlaceholder::SLOT} still says the same thing; this change inserted a line, which " \
28
+ "usually adds a rule",
29
+ before: "true only if the member still says the same thing; this change inserted a line, which usually " \
30
+ "adds a rule"
31
+ ) }
32
+ ) #: TemplatePlaceholders
33
+ # The text a checked member's template prints where its check's exit status goes, short since the request's
34
+ # context says how to run the check.
35
+ EXIT_STATUS_PLACEHOLDER = ReportedCheck::EXIT_STATUS_PLACEHOLDER #: String
36
+ # The fields an answer may not send back as the template printed them, refused before its shape.
37
+ LEFT_AS_PRINTED = AcknowledgementLeftAsPrinted.new(
38
+ PLACEHOLDERS, exit_status: EXIT_STATUS_PLACEHOLDER
39
+ ) #: AcknowledgementLeftAsPrinted
40
+
41
+ # The placeholders the template prints beside quotes, its first_changed_lines.
42
+ #: (Hash[String, String]) -> Hash[String, untyped]
43
+ def self.beside(quotes)
44
+ quotes["old_line"] == "" ? PLACEHOLDERS.with_other_text_in("meaning_kept") : PLACEHOLDERS.to_h
45
+ end
46
+ end
47
+ end
48
+ end
@@ -32,14 +32,14 @@ module Principles
32
32
  "\"observed\" and adds observation, and observed_at for one before this audit." #: String
33
33
 
34
34
  #: (untyped, PrincipleMembers, answered_at: String, ?judged_against: RecordJudgedAgainst?)
35
- #| { (Locator) -> Hash[String, untyped] } -> void
35
+ #| { (Locator) -> LocatedText } -> void
36
36
  def initialize(response, members, answered_at:, judged_against: nil, &locate)
37
37
  @response = response
38
38
  @members = members
39
39
  @answered_at = answered_at
40
40
  @judged_against = judged_against
41
41
  @loads = judged_against&.loads #: LoadsToCheck?
42
- @locate = locate #: ^(Locator) -> Hash[String, untyped]
42
+ @locate = locate #: ^(Locator) -> LocatedText
43
43
  @fields = AnswerFields.new(locate) #: AnswerFields
44
44
  end
45
45
 
@@ -55,7 +55,7 @@ module Principles
55
55
  # The fields of assessment, as sent, that are still the text the template printed there and must be written.
56
56
  #: (Hash[String, untyped]) -> Array[String]
57
57
  def unwritten_fields(assessment)
58
- [("assessment" if assessment["assessment"] == MemberAssessments::PLACEHOLDER),
58
+ [("assessment" if MemberAssessments::ASSESSMENT.left?(assessment["assessment"])),
59
59
  ("observation" if assessment["delivery"] == "observed" &&
60
60
  MemberAssessments::SIGHTING.left?("observation", assessment["observation"]))].compact
61
61
  end
@@ -76,7 +76,7 @@ module Principles
76
76
  # evidence, giving where it is and the hash of its text.
77
77
  # judged_against is the principle's record as it stands, which says which members' last assessments the
78
78
  # answer may carry forward; answered_at is when the answer came, which no sighting it reports is after.
79
- #: (untyped, RecordJudgedAgainst, String) { (Locator) -> Hash[String, untyped] }
79
+ #: (untyped, RecordJudgedAgainst, String) { (Locator) -> LocatedText }
80
80
  #| -> AssessmentAnswer
81
81
  def assessment(response, judged_against, answered_at, &)
82
82
  AssessmentAnswer.new(response, members, answered_at: answered_at, judged_against: judged_against, &)
@@ -28,7 +28,7 @@ module Principles
28
28
  #: (String, String) -> [String, AuditRecord]?
29
29
  def at(id, commit)
30
30
  [file(id), earlier_file(id)].each do |path|
31
- text = @history.text_at(commit, path) or next
31
+ text = @history.at(commit).text(path) or next
32
32
  return [path, AuditRecord.new(@files.parse(id, text) { refuse_unreadable(it, path) })]
33
33
  end
34
34
  nil
@@ -59,7 +59,7 @@ module Principles
59
59
  text_of: ->(path) { texts[path] ||= text_of.call(path) })
60
60
  hints = inventory.fetch("possibly_test_data")
61
61
  listed = listed(inventory, files.listing(hints, changed:))
62
- new(listed, untracked: history.untracked(listed.fetch("files").map { it.fetch("path") }),
62
+ new(listed, untracked: history.untracked_excluding_ignored(listed.fetch("files").map { it.fetch("path") }),
63
63
  outlines: files.outlines(hints))
64
64
  end
65
65
 
@@ -5,7 +5,10 @@ require_relative "../error"
5
5
  require_relative "answer_fields"
6
6
  require_relative "answer_place"
7
7
  require_relative "answer_text"
8
+ require_relative "disposition_placeholders"
9
+ require_relative "disposition_text_field"
8
10
  require_relative "fix_only_fields"
11
+ require_relative "unfinished_field"
9
12
  require_relative "waits_on"
10
13
  require_relative "write_up_pointer"
11
14
 
@@ -20,78 +23,6 @@ module Principles
20
23
  class Disposition
21
24
  ACTIONS = %w[fixed deferred accepted disagreed].freeze #: Array[String]
22
25
 
23
- # A field the agent left unfinished: empty, the template's placeholder, the answer guide's sample, or
24
- # an action not one of the four. It says where it sits in the answer and what to write there, which one
25
- # refusal lists beside every other.
26
- class UnfinishedField
27
- #: String
28
- attr_reader :repair
29
-
30
- #: (AnswerPlace, String, problem: String, repair: String) -> void
31
- def initialize(place, name, problem:, repair:)
32
- @place = place
33
- @name = name
34
- @problem = problem
35
- @repair = repair
36
- freeze
37
- end
38
-
39
- # Whose field it is, such as "Finding F1 reason".
40
- #: () -> String
41
- def to_s = "#{@place.subject} #{@name}"
42
-
43
- # Its entry in the refusal's fields, as a malformed answer's are.
44
- #: () -> Hash[String, String]
45
- def field = { "pointer" => @place.pointer, "problem" => @problem }
46
- end
47
-
48
- # A text field the agent must write: the placeholder the correction template leaves in it, which an answer may
49
- # not send back unchanged, and what to write instead; reassessment applies only to a fix.
50
- class TextField
51
- #: String
52
- attr_reader :placeholder
53
-
54
- #: (placeholder: String, repair: String) -> void
55
- def initialize(placeholder:, repair:)
56
- @placeholder = placeholder
57
- @repair = repair
58
- freeze
59
- end
60
-
61
- # The field named name, at place, when value leaves it empty, as the placeholder or as sample,
62
- # the answer guide's illustration of this field for the disposition's action, if it gives one.
63
- #: (untyped, AnswerPlace, String, sample: String?) -> UnfinishedField?
64
- def left_in(value, place, name, sample:)
65
- problem = if !AnswerText.new(value).written? then "must be a nonempty string"
66
- elsif value == @placeholder then "is the template's placeholder, unchanged"
67
- elsif value == sample then SAMPLE_UNCHANGED
68
- end
69
- UnfinishedField.new(place, name, problem:, repair: @repair) if problem
70
- end
71
- end
72
-
73
- # The problem with a field the agent gave back as the answer guide's sample.
74
- SAMPLE_UNCHANGED = "is the answer guide's sample, unchanged" #: String
75
-
76
- TEXT_FIELDS = {
77
- "reason" => TextField.new(placeholder: "Why, and what remains",
78
- repair: "Write why you chose this action and what remains."),
79
- "reassessment" => TextField.new(placeholder: "fixed only: how the changed members now carry the " \
80
- "principle. Leave as printed otherwise",
81
- repair: "Write how the changed members now carry the principle.")
82
- }.freeze #: Hash[String, TextField]
83
- # The placeholder in each field, which the template prints.
84
- PLACEHOLDERS = TEXT_FIELDS.transform_values(&:placeholder).freeze #: Hash[String, String]
85
- # What action takes, said where it is written when the correction's answer is printed with no answer guide
86
- # beside it, as show-answer-check prints it. It is help, never an action, so it is left unchosen.
87
- ACTION_PLACEHOLDER = "One of fixed, deferred, accepted or disagreed, each with a reason: fixed lists " \
88
- "changed_members for current text changes, optional removed_members for map removals, " \
89
- "and evidence and gives a reassessment; deferred gives recorded_at, " \
90
- "where the write-up is, and may give waits_on; any other action leaves changed_members, " \
91
- "evidence and reassessment as printed" #: String
92
- # Every placeholder a correction's template prints: each text field's, and the action's.
93
- TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION_PLACEHOLDER).freeze #: Hash[String, String]
94
-
95
26
  # at is the disposition's place in the answer, such as /dispositions/0, which a refusal about its pointers names.
96
27
  # samples is the answer guide's disposition for each action, whose text illustrates each field.
97
28
  #: (untyped, AnswerFields, at: String, samples: Hash[String, untyped]) -> void
@@ -167,7 +98,7 @@ module Principles
167
98
  action = @disposition["action"]
168
99
  return if ACTIONS.include?(action)
169
100
 
170
- unchosen = action.nil? || action == ACTION_PLACEHOLDER
101
+ unchosen = action.nil? || DispositionPlaceholders::ACTION.left?(action)
171
102
  problem = unchosen ? "is not chosen" : "is #{action.inspect}, not one of the four"
172
103
  UnfinishedField.new(@place.child("action"), "action",
173
104
  problem:, repair: "Set its action to one of fixed, deferred, accepted or disagreed.")
@@ -178,7 +109,8 @@ module Principles
178
109
  #: () -> Array[UnfinishedField]
179
110
  def unwritten_text
180
111
  action = @disposition["action"]
181
- required = action == "fixed" ? TEXT_FIELDS : TEXT_FIELDS.slice("reason")
112
+ fields = DispositionPlaceholders::TEXT_FIELDS
113
+ required = action == "fixed" ? fields : fields.slice("reason")
182
114
  required.filter_map do |name, field|
183
115
  field.left_in(@disposition[name], @place.child(name), name, sample: @samples.dig(action, name))
184
116
  end
@@ -191,7 +123,8 @@ module Principles
191
123
  sample = @samples.dig(@disposition["action"], "waits_on")
192
124
  return unless sample && @disposition["waits_on"] == sample
193
125
 
194
- UnfinishedField.new(@place.child("waits_on"), "waits_on", problem: SAMPLE_UNCHANGED, repair: WaitsOn::REPAIR)
126
+ UnfinishedField.new(@place.child("waits_on"), "waits_on", problem: DispositionTextField::SAMPLE_UNCHANGED,
127
+ repair: WaitsOn::REPAIR)
195
128
  end
196
129
 
197
130
  # A fix's claimed members, each of which must have changed. A fix may claim no member's text when it
@@ -216,7 +149,10 @@ module Principles
216
149
  end
217
150
 
218
151
  #: () -> FixOnlyFields
219
- def fix_fields = FixOnlyFields.new(@disposition, left_reassessment: PLACEHOLDERS.fetch("reassessment"))
152
+ def fix_fields
153
+ FixOnlyFields.new(@disposition,
154
+ left_reassessment: DispositionPlaceholders::TEXT_FIELDS.fetch("reassessment").placeholder)
155
+ end
220
156
 
221
157
  # Each piece of evidence, and where the finding is written up, located in the project.
222
158
  #: () -> void
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "disposition_text_field"
5
+ require_relative "named_placeholder"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # The text a correction's template prints in each disposition field the agent fills, which an answer may not
11
+ # send back unchanged: each text field's, with what to write instead, and the action's. Each names the finding
12
+ # of the disposition it is printed in, so no two dispositions' slots are alike and one edit fills one.
13
+ class DispositionPlaceholders
14
+ TEXT_FIELDS = {
15
+ "reason" => DispositionTextField.new(
16
+ placeholder: NamedPlaceholder.new("Why #{NamedPlaceholder::SLOT} takes this action, and what remains",
17
+ before: "Why, and what remains"),
18
+ repair: "Write why you chose this action and what remains."
19
+ ),
20
+ "reassessment" => DispositionTextField.new(
21
+ placeholder: NamedPlaceholder.new(
22
+ "fixed only: how the members changed for #{NamedPlaceholder::SLOT} now carry the principle. " \
23
+ "Leave as printed otherwise",
24
+ before: "fixed only: how the changed members now carry the principle. Leave as printed otherwise"
25
+ ),
26
+ repair: "Write how the changed members now carry the principle."
27
+ )
28
+ }.freeze #: Hash[String, DispositionTextField]
29
+ # The placeholder in each field, which the template prints with the disposition's finding in its slot.
30
+ PLACEHOLDERS = TEXT_FIELDS.transform_values { it.placeholder.slotted }.freeze #: Hash[String, String]
31
+ # What action takes, said where it is written when the correction's answer is printed with no answer guide
32
+ # beside it, as show-answer-check prints it, before it named the finding. It is help, never an action, so it
33
+ # is left unchosen.
34
+ ACTION_PLACEHOLDER = "One of fixed, deferred, accepted or disagreed, each with a reason: fixed lists " \
35
+ "changed_members for current text changes, optional removed_members for map removals, " \
36
+ "and evidence and gives a reassessment; deferred gives recorded_at, " \
37
+ "where the write-up is, and may give waits_on; any other action leaves changed_members, " \
38
+ "evidence and reassessment as printed" #: String
39
+ # The action's placeholder, naming the finding.
40
+ ACTION = NamedPlaceholder.new("For #{NamedPlaceholder::SLOT}, #{ACTION_PLACEHOLDER.sub(/\AO/, "o")}",
41
+ before: ACTION_PLACEHOLDER) #: NamedPlaceholder
42
+ # Every placeholder a slot of a correction's template prints, for any finding.
43
+ NAMED = [*TEXT_FIELDS.values.map(&:placeholder), ACTION].freeze #: Array[NamedPlaceholder]
44
+ # Every placeholder a correction's template prints, each text field's and the action's, each with its slot.
45
+ TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION.slotted).freeze #: Hash[String, String]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_place"
5
+ require_relative "answer_text"
6
+ require_relative "named_placeholder"
7
+ require_relative "unfinished_field"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # A text field the agent must write: the placeholder the correction template leaves in it, which an answer may
13
+ # not send back unchanged, and what to write instead; reassessment applies only to a fix.
14
+ class DispositionTextField
15
+ # The problem with a field the agent gave back as the answer guide's sample.
16
+ SAMPLE_UNCHANGED = "is the answer guide's sample, unchanged" #: String
17
+
18
+ # The placeholder, naming the finding of the disposition it is printed in.
19
+ #: NamedPlaceholder
20
+ attr_reader :placeholder
21
+
22
+ #: (placeholder: NamedPlaceholder, repair: String) -> void
23
+ def initialize(placeholder:, repair:)
24
+ @placeholder = placeholder
25
+ @repair = repair
26
+ freeze
27
+ end
28
+
29
+ # The field named name, at place, when value leaves it empty, as the placeholder for any finding or as sample,
30
+ # the answer guide's illustration of this field for the disposition's action, if it gives one.
31
+ #: (untyped, AnswerPlace, String, sample: String?) -> UnfinishedField?
32
+ def left_in(value, place, name, sample:)
33
+ problem = if !AnswerText.new(value).written? then "must be a nonempty string"
34
+ elsif @placeholder.left?(value) then "is the template's placeholder, unchanged"
35
+ elsif value == sample then SAMPLE_UNCHANGED
36
+ end
37
+ UnfinishedField.new(place, name, problem:, repair: @repair) if problem
38
+ end
39
+ end
40
+ end
41
+ end
@@ -30,7 +30,7 @@ module Principles
30
30
 
31
31
  # The lines it names in the project's file at commit, or nil when that commit lacks the file or its place there.
32
32
  #: (ProjectHistory, String) -> Array[String]?
33
- def lines_at(history, commit) = history.lines_at(commit, @locator)
33
+ def lines_at(history, commit) = history.at(commit).lines(@locator)
34
34
 
35
35
  # The lines it names in the project's file now; refused when it no longer resolves.
36
36
  #: (Project) -> Array[String]
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "answer_text"
6
+ require_relative "named_placeholder"
6
7
 
7
8
  module Principles
8
9
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -12,8 +13,8 @@ module Principles
12
13
  # them as printed, and claims no change.
13
14
  class FixOnlyFields
14
15
  # disposition is the disposition as the agent gave it; left_reassessment is the reassessment its template
15
- # prints, which a disposition not fixed leaves as printed.
16
- #: (Hash[String, untyped], left_reassessment: String) -> void
16
+ # prints, for any finding, which a disposition not fixed leaves as printed.
17
+ #: (Hash[String, untyped], left_reassessment: NamedPlaceholder) -> void
17
18
  def initialize(disposition, left_reassessment:)
18
19
  @disposition = disposition
19
20
  @left_reassessment = left_reassessment
@@ -69,7 +70,7 @@ module Principles
69
70
  #: () -> void
70
71
  def fix_text_unclaimed
71
72
  reassessment = @disposition["reassessment"]
72
- written = reassessment != @left_reassessment && AnswerText.new(reassessment).written?
73
+ written = !@left_reassessment.left?(reassessment) && AnswerText.new(reassessment).written?
73
74
  field = ("reassessment" if written) || ("evidence" unless list("evidence").empty?) or return
74
75
  raise Error.new("invalid_disposition", "Only a fixed disposition may give #{field}",
75
76
  "Mark it fixed, or leave #{field} as printed.")
@@ -1,33 +1,32 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "digest"
4
5
  require_relative "line_span"
6
+ require_relative "locator"
5
7
 
6
8
  module Principles
7
9
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
10
  module Models
9
11
  # The text a locator found now: its file, the lines it spans and the hash of what it says. A Locator says where
10
- # to look; this is what was found there, as Project#locate finds it.
12
+ # to look; this is what was found there, as MemberFile#locate finds it.
11
13
  class LocatedText
12
- # The text found, from what Project#locate gives.
13
- #: (Hash[String, untyped]) -> LocatedText
14
- def self.of(found)
15
- new(path: found.fetch("path"), first_line: found.fetch("first_line"), last_line: found.fetch("last_line"),
16
- sha256: found.fetch("sha256"))
17
- end
18
-
19
14
  #: String
20
15
  attr_reader :path, :sha256
21
16
 
22
17
  #: Integer
23
18
  attr_reader :first_line, :last_line
24
19
 
25
- #: (path: String, first_line: Integer, last_line: Integer, sha256: String) -> void
26
- def initialize(path:, first_line:, last_line:, sha256:)
20
+ # path is the file's spelling as git tracks it, which may differ from the locator's in case; text is what
21
+ # was found, whose hash and length it keeps, so the two never disagree.
22
+ #: (locator: Locator, path: String, first_line: Integer, last_line: Integer, text: String) -> void
23
+ def initialize(locator:, path:, first_line:, last_line:, text:)
24
+ @locator = locator
27
25
  @path = path
28
26
  @first_line = first_line
29
27
  @last_line = last_line
30
- @sha256 = sha256
28
+ @sha256 = Digest::SHA256.hexdigest(text) #: String
29
+ @characters = text.length #: Integer
31
30
  freeze
32
31
  end
33
32
 
@@ -38,6 +37,15 @@ module Principles
38
37
  # Its first and last lines, as a request prints them.
39
38
  #: () -> Hash[String, Integer]
40
39
  def lines = { "first_line" => @first_line, "last_line" => @last_line }
40
+
41
+ # Where it was found and the hash of what it says, as show-principle prints a member's snapshot. query appears
42
+ # only for a locator that has one, so every other member's snapshot, and each request id digesting it, is
43
+ # unchanged.
44
+ #: () -> Hash[String, untyped]
45
+ def to_h
46
+ { "path" => @path, "heading" => @locator.heading, "starting_at" => @locator.starting_at,
47
+ "sha256" => @sha256, "characters" => @characters, **lines }.merge(@locator.to_h.slice("query"))
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -10,6 +10,7 @@ require_relative "principle_members"
10
10
  require_relative "answered_time"
11
11
  require_relative "member_sighting"
12
12
  require_relative "misspelt_member_id"
13
+ require_relative "named_placeholder"
13
14
  require_relative "record_judged_against"
14
15
  require_relative "reported_check"
15
16
  require_relative "template_placeholders"
@@ -25,10 +26,16 @@ module Principles
25
26
  # What a record entry keeps for a member carried forward, until completion puts back its last assessment.
26
27
  CARRIED = { "carried_forward" => true }.freeze #: Hash[String, untyped]
27
28
 
28
- # The text a fresh member's template prints in its assessment, which an answer may not send back unchanged, as a
29
- # correction may not send back its own.
29
+ # The text a fresh member's template printed in its assessment before each named its member, which an answer
30
+ # may not send back unchanged, as a correction may not send back its own.
30
31
  PLACEHOLDER = "Your assessment, including its context cost" #: String
31
32
 
33
+ # The text a fresh member's template prints in its assessment now, naming the member.
34
+ NAMED_PLACEHOLDER = "Your assessment of #{NamedPlaceholder::SLOT}, including its context cost".freeze #: String
35
+
36
+ # The assessment's placeholder, which any member's assessment leaves as printed for any member's id.
37
+ ASSESSMENT = NamedPlaceholder.new(NAMED_PLACEHOLDER, before: PLACEHOLDER) #: NamedPlaceholder
38
+
32
39
  # The text the template printed alone gives a sighting's fields beside delivery, each left as printed when the
33
40
  # delivery gives none.
34
41
  SIGHTING = TemplatePlaceholders.new(
@@ -74,12 +81,12 @@ module Principles
74
81
 
75
82
  # Each member's assessment by id, as its record entry keeps it: what the agent said, and the hash of each piece
76
83
  # of evidence it cited, which the block locates, so the next audit can say whether that evidence changed.
77
- #: () { (Locator) -> Hash[String, untyped] } -> Hash[String, Hash[String, untyped]]
84
+ #: () { (Locator) -> LocatedText } -> Hash[String, Hash[String, untyped]]
78
85
  def kept(&locate)
79
86
  @assessments.to_h do |assessment|
80
87
  next [assessment.fetch("member_id"), { "assessment" => CARRIED }] if carried_forward?(assessment)
81
88
 
82
- hashes = assessment.fetch("evidence").map { |reference| locate.call(Locator.new(reference)).fetch("sha256") }
89
+ hashes = assessment.fetch("evidence").map { |reference| locate.call(Locator.new(reference)).sha256 }
83
90
  [assessment.fetch("member_id"),
84
91
  { "assessment" => assessment.slice("assessment", "delivery", "observation", "observed_at", "evidence")
85
92
  .reject { |key, value| key == "observed_at" && value.nil? }
@@ -1,11 +1,11 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "digest"
5
4
  require_relative "../error"
6
5
  require_relative "locator"
7
6
  require_relative "member_region"
8
7
  require_relative "line_span"
8
+ require_relative "located_text"
9
9
  require_relative "write_up_opening"
10
10
 
11
11
  module Principles
@@ -50,7 +50,7 @@ module Principles
50
50
  end
51
51
 
52
52
  # Where the member locator names is in this text, and the hash of what it says there.
53
- #: (Locator) -> Hash[String, untyped]
53
+ #: (Locator) -> LocatedText
54
54
  def locate(locator)
55
55
  refuse_mixed_locators(locator)
56
56
  lines = @text.lines
@@ -65,7 +65,7 @@ module Principles
65
65
  end
66
66
 
67
67
  # Only a newly supplied add/move location needs an unambiguous ending; existing references keep lookup.
68
- #: (Locator) -> Hash[String, untyped]
68
+ #: (Locator) -> LocatedText
69
69
  def locate_for_authoring(locator)
70
70
  found = locate(locator)
71
71
  opening = locator.starting_at
@@ -82,7 +82,7 @@ module Principles
82
82
  #: (Locator) -> Array[String]
83
83
  def lines_of(locator)
84
84
  located = locate(locator)
85
- @text.lines[(located.fetch("first_line") - 1)...located.fetch("last_line")].to_a
85
+ @text.lines[(located.first_line - 1)...located.last_line].to_a
86
86
  end
87
87
 
88
88
  # The opening of the region locator names, after the heading line itself when it names a heading, as
@@ -91,19 +91,16 @@ module Principles
91
91
  def write_up_opening(locator)
92
92
  located = locate(locator)
93
93
  heading_line = locator.heading && !locator.starting_at ? 1 : 0
94
- WriteUpOpening.new(lines: @text.lines, first: located.fetch("first_line") - 1 + heading_line,
95
- last: located.fetch("last_line")).to_h
94
+ WriteUpOpening.new(lines: @text.lines, first: located.first_line - 1 + heading_line,
95
+ last: located.last_line).to_h
96
96
  end
97
97
 
98
98
  private
99
99
 
100
- # What locate found: the member's place, the hash of its text and its span. query appears only for a
101
- # member that has one, so every other member's snapshot, and each request id digesting it, is unchanged.
102
- #: (Locator, String, Integer, Integer) -> Hash[String, untyped]
100
+ # What locate found: the member's place, the hash of its text and its span.
101
+ #: (Locator, String, Integer, Integer) -> LocatedText
103
102
  def snapshot(locator, selected, first_line, last_line)
104
- { "path" => @path, "heading" => locator.heading, "starting_at" => locator.starting_at,
105
- "sha256" => Digest::SHA256.hexdigest(selected), "characters" => selected.length,
106
- "first_line" => first_line, "last_line" => last_line }.merge(locator.to_h.slice("query"))
103
+ LocatedText.new(locator:, path: @path, first_line:, last_line:, text: selected)
107
104
  end
108
105
 
109
106
  # A query names a field whole, so it takes no section or passage beside it.
@@ -19,7 +19,7 @@ module Principles
19
19
  #: (ProjectHistory) -> Hash[String, String]?
20
20
  def baseline(history)
21
21
  @entries.reverse_each do |sha, fields|
22
- hash = history.hashes_by_key_at(sha, [fields])[@key] or next
22
+ hash = history.at(sha).hashes_by_key([fields])[@key] or next
23
23
 
24
24
  return { "commit" => sha, "sha256" => hash }
25
25
  end