principles 0.0.1 → 0.0.4

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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +7 -1
  3. data/lib/principles/command_line.rb +12 -29
  4. data/lib/principles/controllers/acknowledgement.rb +4 -4
  5. data/lib/principles/controllers/answer.rb +64 -100
  6. data/lib/principles/controllers/assessment.rb +108 -0
  7. data/lib/principles/controllers/audit.rb +29 -135
  8. data/lib/principles/controllers/audit_completion.rb +2 -4
  9. data/lib/principles/controllers/command.rb +27 -13
  10. data/lib/principles/controllers/correction.rb +4 -4
  11. data/lib/principles/controllers/full_audit_request.rb +180 -0
  12. data/lib/principles/controllers/inventory.rb +32 -70
  13. data/lib/principles/controllers/mapping.rb +3 -3
  14. data/lib/principles/controllers/member_entries.rb +24 -12
  15. data/lib/principles/controllers/member_problems_report.rb +72 -0
  16. data/lib/principles/controllers/members_a_commit_changed.rb +10 -2
  17. data/lib/principles/controllers/members_to_assess.rb +16 -9
  18. data/lib/principles/controllers/meta_principle_setup.rb +5 -5
  19. data/lib/principles/controllers/repoint.rb +1 -1
  20. data/lib/principles/controllers/running_tool.rb +1 -1
  21. data/lib/principles/data/audit_files.rb +11 -7
  22. data/lib/principles/data/bounded_file.rb +11 -0
  23. data/lib/principles/data/command-steps.json +7 -6
  24. data/lib/principles/data/map_files.rb +2 -2
  25. data/lib/principles/data/principles_subfolder.rb +8 -1
  26. data/lib/principles/data/project_files.rb +1 -7
  27. data/lib/principles/data/project_root.rb +48 -0
  28. data/lib/principles/data/schema_check.rb +23 -5
  29. data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
  30. data/lib/principles/data/schemas/audit-record.schema.json +3 -0
  31. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  32. data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
  33. data/lib/principles/invocation_options.rb +1 -1
  34. data/lib/principles/models/assessment_answer.rb +64 -17
  35. data/lib/principles/models/audit.rb +24 -15
  36. data/lib/principles/models/audit_record.rb +10 -3
  37. data/lib/principles/models/audit_records.rb +74 -4
  38. data/lib/principles/models/audit_start.rb +3 -3
  39. data/lib/principles/models/carried_assessments.rb +1 -1
  40. data/lib/principles/models/check_since_last_audit.rb +6 -6
  41. data/lib/principles/models/correction_basis.rb +1 -1
  42. data/lib/principles/models/decided_prior_findings.rb +9 -19
  43. data/lib/principles/models/declared_map_changes.rb +8 -8
  44. data/lib/principles/models/disposition.rb +28 -24
  45. data/lib/principles/models/evidence_replacements.rb +8 -1
  46. data/lib/principles/models/fix_only_fields.rb +67 -0
  47. data/lib/principles/models/kept_prior_finding.rb +12 -7
  48. data/lib/principles/models/loaded_files.rb +5 -3
  49. data/lib/principles/models/loading_decision.rb +9 -2
  50. data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
  51. data/lib/principles/models/member.rb +1 -1
  52. data/lib/principles/models/member_assessments.rb +48 -3
  53. data/lib/principles/models/member_grounds.rb +2 -2
  54. data/lib/principles/models/member_hashes_as_written.rb +40 -0
  55. data/lib/principles/models/member_moves.rb +3 -3
  56. data/lib/principles/models/member_problems.rb +38 -18
  57. data/lib/principles/models/members_sharing_lines.rb +3 -3
  58. data/lib/principles/models/new_findings.rb +55 -0
  59. data/lib/principles/models/open_finding.rb +23 -13
  60. data/lib/principles/models/other_principles.rb +1 -1
  61. data/lib/principles/models/other_templates_placeholders.rb +74 -0
  62. data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
  63. data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
  64. data/lib/principles/models/{map_members.rb → principle_members.rb} +4 -4
  65. data/lib/principles/models/prior_decision_fields.rb +46 -0
  66. data/lib/principles/models/prior_finding_decision.rb +24 -3
  67. data/lib/principles/models/prior_finding_outcomes.rb +10 -3
  68. data/lib/principles/models/prior_findings.rb +1 -1
  69. data/lib/principles/models/problem_report.rb +7 -3
  70. data/lib/principles/models/project.rb +27 -13
  71. data/lib/principles/models/project_history.rb +2 -2
  72. data/lib/principles/models/recent_decision.rb +90 -0
  73. data/lib/principles/models/record_format.rb +105 -0
  74. data/lib/principles/models/recorded_finding.rb +4 -0
  75. data/lib/principles/models/recorded_hashes.rb +39 -0
  76. data/lib/principles/models/recorded_members.rb +17 -12
  77. data/lib/principles/models/reported_check.rb +63 -11
  78. data/lib/principles/models/request_id.rb +24 -4
  79. data/lib/principles/models/sent_prior_decisions.rb +31 -0
  80. data/lib/principles/models/still_holds_restatement.rb +7 -10
  81. data/lib/principles/models/template_placeholders.rb +41 -0
  82. data/lib/principles/session_start_options.rb +29 -0
  83. data/lib/principles/start_audit_options.rb +37 -0
  84. data/lib/principles/version.rb +2 -2
  85. data/lib/principles/views/answer_head.rb +29 -0
  86. data/lib/principles/views/assessed_members.rb +96 -0
  87. data/lib/principles/views/assessment_request.rb +51 -49
  88. data/lib/principles/views/audit_result.rb +38 -42
  89. data/lib/principles/views/check_result_template.rb +31 -10
  90. data/lib/principles/views/correction_request.rb +64 -0
  91. data/lib/principles/views/first_audit.rb +71 -0
  92. data/lib/principles/views/help.rb +3 -2
  93. data/lib/principles/views/loads_to_check_result.rb +11 -4
  94. data/lib/principles/views/map_added_to.rb +31 -0
  95. data/lib/principles/views/map_result.rb +37 -22
  96. data/lib/principles/views/members_a_commit_changed.rb +30 -10
  97. data/lib/principles/views/meta_principle_result.rb +3 -14
  98. data/lib/principles/views/principle_read_result.rb +27 -10
  99. data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
  100. data/lib/principles/views/prior_findings_result.rb +7 -3
  101. data/lib/principles/views/problem_lines.rb +14 -11
  102. data/lib/principles/views/problem_result.rb +30 -16
  103. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +3 -2
  104. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
  105. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  106. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  107. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
  108. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +1 -1
  109. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
  110. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
  111. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +22 -20
  112. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +8 -5
  113. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +3 -0
  114. data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
  115. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +6 -0
  116. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
  117. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +2 -1
  118. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
  119. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  120. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +37 -37
  121. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
  122. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +1 -0
  123. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
  124. data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
  125. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +2 -1
  126. data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
  127. data/lib/principles/views/request_part.rb +14 -2
  128. data/lib/principles/views/request_parts.rb +4 -0
  129. metadata +33 -7
@@ -0,0 +1,74 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+
6
+ module Principles
7
+ module Models
8
+ # The text in an answer that ends as this tool's placeholders end, "Leave as printed ...", "else leave" or "else
9
+ # kept", but is none the request's own template printed: another template's placeholder, as an answer filled from
10
+ # an older template and repaired field by field keeps it, which no other check refuses in free text (#1084). It
11
+ # reads the ending alone, so the agent's own text ending so is refused too, and the repair says to reword it.
12
+ class OtherTemplatesPlaceholders
13
+ # How every placeholder of this tool's templates ends, in this release and earlier ones.
14
+ ENDING = /(\bLeave (\S+ ){0,2}as printed[^.]*|\belse (leave|kept))\.?\z/ #: Regexp
15
+
16
+ # Each string in template, a request's template as printed, that ends as a placeholder does.
17
+ #: (untyped) -> OtherTemplatesPlaceholders
18
+ def self.besides(template)
19
+ new(strings(template).grep(ENDING))
20
+ end
21
+
22
+ # Every string in value, at any depth.
23
+ #: (untyped) -> Array[String]
24
+ def self.strings(value)
25
+ case value
26
+ when String then [value]
27
+ when Hash then value.values.flat_map { strings(it) }
28
+ when Array then value.flat_map { strings(it) }
29
+ else []
30
+ end
31
+ end
32
+
33
+ # printed is the placeholders the request's own template printed, which an answer may leave as printed.
34
+ #: (Array[String]) -> void
35
+ def initialize(printed)
36
+ @printed = printed
37
+ end
38
+
39
+ # Refuses answer, read from source, in one refusal naming every field holding another template's placeholder.
40
+ #: (untyped, String) -> void
41
+ def refuse_in(answer, source)
42
+ found = pointers(answer, "")
43
+ return if found.empty?
44
+
45
+ raise Error.new("invalid_answer", "#{source} holds text another template printed as a placeholder",
46
+ "Start from this request's response_template, or replace each field named with your own " \
47
+ "text; if one is your own text, reword its ending.",
48
+ source, fields: found.map { { "pointer" => it, "problem" => PROBLEM } })
49
+ end
50
+
51
+ PROBLEM = "ends as a placeholder does, but is none this request's template printed" #: String
52
+
53
+ private
54
+
55
+ # The pointer to each string in value, at pointer, that ends as a placeholder does and is not one printed.
56
+ #: (untyped, String) -> Array[String]
57
+ def pointers(value, pointer)
58
+ case value
59
+ when String then other?(value) ? [pointer] : []
60
+ when Hash then value.flat_map { |key, each| pointers(each, "#{pointer}/#{escaped(key)}") }
61
+ when Array then value.each_with_index.flat_map { |each, index| pointers(each, "#{pointer}/#{index}") }
62
+ else []
63
+ end
64
+ end
65
+
66
+ #: (String) -> bool
67
+ def other?(text) = text.match?(ENDING) && !@printed.include?(text)
68
+
69
+ # key as a JSON pointer writes it.
70
+ #: (String) -> String
71
+ def escaped(key) = key.gsub("~", "~0").gsub("/", "~1")
72
+ end
73
+ end
74
+ end
@@ -5,7 +5,7 @@ require "json"
5
5
  require_relative "../error"
6
6
  require_relative "../data/schema_check"
7
7
  require_relative "member"
8
- require_relative "map_members"
8
+ require_relative "principle_members"
9
9
  require_relative "activation"
10
10
  require_relative "json_digest"
11
11
  require_relative "meta_principle"
@@ -13,21 +13,21 @@ require_relative "meta_principle"
13
13
  module Principles
14
14
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
15
15
  module Models
16
- # One principle's member map: the principle it names and the members that reinforce it, each a project
17
- # file or a place in one, with the role it plays. Every change returns a new map and leaves this one as
18
- # it was; MemberMaps saves it. Fields the map holds beyond these are kept as they are.
19
- class MemberMap
16
+ # One principle: its id, description and activation, and the members that reinforce it, each a project file
17
+ # or a place in one, with the role it plays. Its map file holds it. Every change returns a new principle and
18
+ # leaves this one as it was; MappedPrinciples saves it. Fields its map holds beyond these are kept as they are.
19
+ class Principle
20
20
  #: String
21
21
  attr_reader :id
22
22
 
23
23
  #: (String, Hash[String, untyped]) -> void
24
24
  def initialize(id, fields)
25
25
  @id = id
26
- # The map owns its data: every field, an unknown one too, is copied and frozen down to each string, so no
26
+ # The principle owns its data: every field, an unknown one too, is copied and frozen down to each string, so no
27
27
  # change made in place to what it was built from or what it hands out changes its file or version (#648,
28
28
  # #654). The copy goes through the JSON its version digests, which a map's file holds anyway.
29
29
  owned = JSON.parse(JSON.generate(fields), freeze: true) #: Hash[String, untyped]
30
- @members = MapMembers.new(id, owned.fetch("members").map { |each| Member.new(each) }) #: MapMembers
30
+ @members = PrincipleMembers.new(id, owned.fetch("members").map { |each| Member.new(each) }) #: PrincipleMembers
31
31
  @fields = owned.merge("members" => @members.map(&:to_h).freeze).freeze #: Hash[String, untyped]
32
32
  freeze
33
33
  end
@@ -38,7 +38,7 @@ module Principles
38
38
  end
39
39
 
40
40
  # Its members as Member values, which say each one's id, key, place and check.
41
- #: MapMembers
41
+ #: PrincipleMembers
42
42
  attr_reader :members
43
43
 
44
44
  # Each member in one of paths, by its id and path, as show-meta-principle-passage reports the members already in
@@ -59,20 +59,25 @@ module Principles
59
59
  #: () -> bool
60
60
  def keeps_others_held? = meta_principle?
61
61
 
62
- # Whether this is the meta-principle's map with no members, as a setup that wrote its map before the first
63
- # member, or removing its last member, leaves it. Only this map's having none is out of the way: setup no longer
64
- # writes it, and its first add-member creates it with that member (T74), while any other principle has none from
65
- # create-principle until its first add-member (#931).
62
+ # Whether this is the meta-principle with no members, as a setup that wrote its map before the first
63
+ # member, or removing its last member, leaves it. Only this principle's having none is out of the way: setup no
64
+ # longer writes it, and its first add-member creates it with that member (T74), while any other principle has
65
+ # none from create-principle until its first add-member (#931).
66
66
  #: () -> bool
67
67
  def unstarted? = meta_principle? && @members.empty?
68
68
 
69
+ # Whether a full audit of this principle can have started, so that a correction may be open while a member is
70
+ # added: start-audit refuses a map with no members (D72, #1023).
71
+ #: () -> bool
72
+ def auditable? = !@members.empty?
73
+
69
74
  # The map's version: the digest of what its JSON says, so any change to it gives a new version, and a hand
70
75
  # edit or a formatter that only reorders its keys does not (#656).
71
76
  #: () -> String
72
77
  def version = JsonDigest.new(@fields).to_s
73
78
 
74
- # Whether other would write the same file as this map, so saving it would change nothing.
75
- #: (MemberMap) -> bool
79
+ # Whether other would write the same file as this principle, so saving it would change nothing.
80
+ #: (Principle) -> bool
76
81
  def same_as?(other) = version == other.version
77
82
 
78
83
  # Each member as this tool prints it: its id beside the fields shown gives it.
@@ -87,26 +92,26 @@ module Principles
87
92
  @fields
88
93
  end
89
94
 
90
- # The member with member_id, refused unless the map has it.
95
+ # The member with member_id, refused unless this principle has it.
91
96
  #: (String) -> Hash[String, untyped]
92
97
  def member(member_id)
93
98
  @members.found(member_id).to_h
94
99
  end
95
100
 
96
- #: (String) -> MemberMap
101
+ #: (String) -> Principle
97
102
  def describing(description)
98
- MemberMap.new(id, @fields.merge("description" => description))
103
+ Principle.new(id, @fields.merge("description" => description))
99
104
  end
100
105
 
101
106
  # When the agent said this principle's work is in hand, as the map stores it, or nil when it has not (D38).
102
107
  #: () -> Hash[String, untyped]?
103
108
  def activation = @fields["activation"]
104
109
 
105
- #: (Activation) -> MemberMap
106
- def activating(activation) = MemberMap.new(id, @fields.merge("activation" => activation.to_h))
110
+ #: (Activation) -> Principle
111
+ def activating(activation) = Principle.new(id, @fields.merge("activation" => activation.to_h))
107
112
 
108
- # This map with member added, refused when the map already has a member with its id.
109
- #: (Hash[String, untyped]) -> MemberMap
113
+ # This principle with member added, refused when it already has a member with its id.
114
+ #: (Hash[String, untyped]) -> Principle
110
115
  def adding(member)
111
116
  added = Member.new(member)
112
117
  new_id = added.id
@@ -118,10 +123,10 @@ module Principles
118
123
  with_members(@members.to_a + [@members.keyed(added)])
119
124
  end
120
125
 
121
- # This map with member_id pointed at the place located names, in the same file. The new place replaces
126
+ # This principle with member_id pointed at the place located names, in the same file. The new place replaces
122
127
  # the old one whole, and every other field is kept: its role, and any a newer version wrote (D29). It is
123
128
  # refused when another member is already there.
124
- #: (String, Hash[String, untyped]) -> MemberMap
129
+ #: (String, Hash[String, untyped]) -> Principle
125
130
  def moving(member_id, located)
126
131
  old = @members.found(member_id)
127
132
  moved = old.moved_to(located)
@@ -133,15 +138,15 @@ module Principles
133
138
  replacing(old, moved)
134
139
  end
135
140
 
136
- #: (String, String) -> MemberMap
141
+ #: (String, String) -> Principle
137
142
  def changing_role(member_id, role) = changing(member_id, "role" => role)
138
143
 
139
144
  # Names the command that enforces a member, which an audit asks the agent to run (D30). This tool
140
145
  # stores it and never runs it.
141
- #: (String, String) -> MemberMap
146
+ #: (String, String) -> Principle
142
147
  def changing_check(member_id, check) = changing(member_id, "check" => check)
143
148
 
144
- #: (String) -> MemberMap
149
+ #: (String) -> Principle
145
150
  def removing_check(member_id)
146
151
  old = @members.found(member_id)
147
152
  unless old.to_h.key?("check")
@@ -152,16 +157,16 @@ module Principles
152
157
  replacing(old, old.without_check)
153
158
  end
154
159
 
155
- #: (String) -> MemberMap
160
+ #: (String) -> Principle
156
161
  def removing(member_id)
157
162
  old = @members.found(member_id)
158
163
  with_members(@members.reject { |each| each.equal?(old) })
159
164
  end
160
165
 
161
- # Member owns the format each member field needs; this name stays while member_map_spec checks it there.
166
+ # Member owns the format each member field needs; this name stays while principle_spec checks it there.
162
167
  FIELD_FORMATS = Member::FIELD_FORMATS #: Hash[String, Integer]
163
168
 
164
- # The oldest format that holds every member of this map: 1 unless a member uses a later field.
169
+ # The oldest format that holds every member of this principle: 1 unless a member uses a later field.
165
170
  #: () -> Integer
166
171
  def format
167
172
  @members.format
@@ -169,38 +174,38 @@ module Principles
169
174
 
170
175
  private
171
176
 
172
- # Whether this is the map of the principle that keeps every other one held (D67).
177
+ # Whether this is the principle that keeps every other one held (D67).
173
178
  #: () -> bool
174
179
  def meta_principle? = @id == MetaPrinciple::ID
175
180
 
176
- # The map with only the fields this tool knows, for printing: a field someone added to the file is kept
181
+ # This principle with only the fields this tool knows, for printing: a field someone added to the file is kept
177
182
  # in it but never shown as if this tool had said it.
178
183
  #: () -> Hash[String, untyped]
179
184
  def shown
180
185
  Data::SchemaCheck.new("member-map").known(@fields)
181
186
  end
182
187
 
183
- # The refusal for a member id another member of this map has, ending with its repairs.
188
+ # The refusal for a member id another member of this principle has, ending with its repairs.
184
189
  #: (String, *Error::RepairCommand) -> Error
185
190
  def taken(new_id, *repairs)
186
191
  Error.new("member_exists", "#{new_id} is already a member of #{id}", "").ending_with(repairs)
187
192
  end
188
193
 
189
- # A repair command acting on a member of this map, with the placeholders the agent fills; the controller prints
190
- # it, quoting the member (D56, #729).
194
+ # A repair command acting on a member of this principle, with the placeholders the agent fills; the controller
195
+ # prints it, quoting the member (D56, #729).
191
196
  #: (String, String, String, ?String?) -> Error::RepairCommand
192
197
  def repair(purpose, command, member, usage = nil)
193
198
  Error::RepairCommand.new(purpose: purpose, command: command, values: [id, member], usage: usage)
194
199
  end
195
200
 
196
- # The map with member_id's entry holding fields in place of its own.
197
- #: (String, Hash[String, untyped]) -> MemberMap
201
+ # This principle with member_id's entry holding fields in place of its own.
202
+ #: (String, Hash[String, untyped]) -> Principle
198
203
  def changing(member_id, fields)
199
204
  old = @members.found(member_id)
200
205
  replacing(old, old.with(fields))
201
206
  end
202
207
 
203
- #: (Member, Member) -> MemberMap
208
+ #: (Member, Member) -> Principle
204
209
  def replacing(old, member)
205
210
  with_members(@members.map { |each| each.equal?(old) ? member : each })
206
211
  end
@@ -208,11 +213,11 @@ module Principles
208
213
  # Members are kept in id order, so a map's file changes only where a member does.
209
214
  # Its format is worked out again, and written only above 1, so a map that uses no later field keeps
210
215
  # the bytes an older version wrote, and its version.
211
- #: (Array[Member]) -> MemberMap
216
+ #: (Array[Member]) -> Principle
212
217
  def with_members(list)
213
- changed = MemberMap.new(id, @fields.merge("members" => list.sort_by(&:id).map(&:to_h)))
218
+ changed = Principle.new(id, @fields.merge("members" => list.sort_by(&:id).map(&:to_h)))
214
219
  fields = changed.to_h.except("format")
215
- MemberMap.new(id, changed.format > 1 ? fields.merge("format" => changed.format) : fields)
220
+ Principle.new(id, changed.format > 1 ? fields.merge("format" => changed.format) : fields)
216
221
  end
217
222
  end
218
223
  end
@@ -4,23 +4,23 @@
4
4
  require_relative "../error"
5
5
  require_relative "member"
6
6
  require_relative "member_history"
7
- require_relative "member_maps"
7
+ require_relative "mapped_principles"
8
8
  require_relative "placement"
9
9
  require_relative "project_history"
10
10
 
11
11
  module Principles
12
12
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
13
13
  module Models
14
- # One map's members as the commits that changed it held them, walking back from HEAD on its first-parent
15
- # line. Each member's run is the unbroken stretch of those commits whose map holds a member with its key,
16
- # so its oldest commit is the one that mapped the member where it is (#243). The walk stops at a map it
17
- # cannot read, so a run may start later than the true mapping; that can only hide an older change.
18
- class MemberMapHistory
19
- #: (id: String, history: ProjectHistory, member_maps: MemberMaps) -> void
20
- def initialize(id:, history:, member_maps:)
14
+ # One principle's members as the commits that changed its map held them, walking back from HEAD on its
15
+ # first-parent line. Each member's run is the unbroken stretch of those commits whose map holds a member
16
+ # with its key, so its oldest commit is the one that mapped the member where it is (#243). The walk stops
17
+ # at a map it cannot read, so a run may start later than the true mapping; that can only hide an older change.
18
+ class PrincipleHistory
19
+ #: (id: String, history: ProjectHistory, principles: MappedPrinciples) -> void
20
+ def initialize(id:, history:, principles:)
21
21
  @id = id
22
22
  @history = history
23
- @member_maps = member_maps
23
+ @principles = principles
24
24
  freeze
25
25
  end
26
26
 
@@ -58,20 +58,42 @@ module Principles
58
58
  #: (Member, baseline: String, now: String) -> Hash[String, untyped]
59
59
  def member_history(member, baseline:, now:)
60
60
  key = member.key
61
- now_at = @member_maps.find(@id).member(member.id)
61
+ now_at = @principles.find(@id).member(member.id)
62
62
  hashes = {} #: Hash[String, String?]
63
63
  hash_at = ->(revision) { hashes.fetch(revision) { hashes[revision] = hash_at(key, now_at, revision) } }
64
64
  commits = @history.commits_touching([*paths_of(member), *map_paths])
65
65
  MemberHistory.new(baseline: baseline, now: now, commits: commits, hash_at: hash_at).to_h
66
66
  end
67
67
 
68
- # The map as commit holds it, such as the one an audit began from, refused as MemberMaps refuses its text;
68
+ # The map as commit holds it, such as the one an audit began from, refused as MappedPrinciples refuses its text;
69
69
  # a commit before the folder took its name now holds it under the earlier name (#536), and a commit that lacks
70
70
  # the map under both gives empty text, which is refused as unparseable.
71
- #: (String) -> MemberMap
71
+ #: (String) -> Principle
72
72
  def map_at(commit)
73
73
  text = map_paths.lazy.filter_map { |path| @history.text_at(commit, path) }.first
74
- @member_maps.parsed(@id, text.to_s, commit: commit)
74
+ @principles.parsed(@id, text.to_s, commit: commit)
75
+ end
76
+
77
+ # Whether a full audit of this principle can have started from HEAD, so a correction may be open: in git,
78
+ # start-audit refuses a map that is not committed or has no member (D72, #1023). False outside git, or when HEAD
79
+ # holds no map it can read.
80
+ #: () -> bool
81
+ def startable_at_head?
82
+ head = @history.head or return false
83
+ map_at(head).auditable?
84
+ rescue Error
85
+ false
86
+ end
87
+
88
+ # Whether an add-member to map, as it stands before the member joins, is the first since the map was last
89
+ # committed, which add-member's reminders print on (#1025): map has no member, or, in git, its file is as HEAD
90
+ # holds it. Outside git, only with the first member.
91
+ #: (Principle) -> bool
92
+ def first_add_since_commit?(map)
93
+ return true if map.members.empty?
94
+ return false unless @history.head
95
+
96
+ @history.uncommitted([@principles.file(@id)]).empty?
75
97
  end
76
98
 
77
99
  # The member's fields as the map at commit placed it, found by key; nil where that map did not hold it or cannot
@@ -102,7 +124,7 @@ module Principles
102
124
 
103
125
  # The map's file now and under the folder's earlier name, so a walk of its history reaches back past the move.
104
126
  #: () -> Array[String]
105
- def map_paths = [@member_maps.file(@id), @member_maps.earlier_file(@id)]
127
+ def map_paths = [@principles.file(@id), @principles.earlier_file(@id)]
106
128
 
107
129
  # The member's placements at commit, as that commit's map placed it and as now_at does, once each.
108
130
  #: (String, String, Hash[String, untyped]) -> Array[Placement]
@@ -131,7 +153,8 @@ module Principles
131
153
  @history.hashes_by_key_at(revision, [fields])[key] || @history.hashes_by_key_at(revision, [now_at])[key]
132
154
  end
133
155
 
134
- # Each member the map at commit holds, by key, or nil when that commit lacks the map or MemberMaps refuses it.
156
+ # Each member the map at commit holds, by key, or nil when that commit lacks the map or
157
+ # MappedPrinciples refuses it.
135
158
  #: (String) -> Hash[String, Hash[String, untyped]]?
136
159
  def members_at(commit)
137
160
  map_at(commit).members.to_h { |member| [member.key, member.to_h] }
@@ -8,13 +8,13 @@ require_relative "misspelt_member_id"
8
8
  module Principles
9
9
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
10
  module Models
11
- # One principle map's members, as Members: finding one by its id, and the rules on ids and keys among them,
12
- # which MemberMap asks as it changes the map. It is Enumerable over its members, in the map's order.
11
+ # One principle's members, as Members: finding one by its id, and the rules on ids and keys among them,
12
+ # which Principle asks as it changes the map. It is Enumerable over its members, in the map's order.
13
13
  #: [out Elem = Member]
14
- class MapMembers
14
+ class PrincipleMembers
15
15
  include Enumerable
16
16
 
17
- # The principle whose map these are.
17
+ # The principle whose members these are.
18
18
  #: String
19
19
  attr_reader :principle_id
20
20
 
@@ -0,0 +1,46 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "template_placeholders"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The fields a decision on a prior finding may give, as start-audit --as template prints them to fill: each with
10
+ # a placeholder saying which decisions take it, so the agent fills those its decision takes and leaves the rest
11
+ # as printed, which is not giving them (#994). A marked finding's decision may start problem_evidence as an empty
12
+ # list instead, which is not given either (#838).
13
+ module PriorDecisionFields
14
+ # The decision's placeholder, naming what it may be (#746); one sent back is no decision, named in the answer's
15
+ # one refusal for every judgement left as printed (#1040).
16
+ DECISION = "still_holds, resolved, withdrawn or raised_again" #: String
17
+ # The fields that take pointers, which the answer's schema lets be text only for their placeholders.
18
+ POINTERS = %w[evidence recorded_at problem_evidence].freeze #: Array[String]
19
+ # raised_in's placeholder, in plain words, since the answer's schema accepts it as the one alternative to a full
20
+ # sha, the only value that reaches git (D53).
21
+ RAISED_IN = "With first_raised_at: its record's commit, full sha; else leave" #: String
22
+ # The placeholder printed in each field a decision may give: only which decision takes it, and what, since that
23
+ # a field left as printed is not given is stated once, at the template's head, and each finding printed every
24
+ # field's whole help (#1033). Each says what to do otherwise: "else kept" where omission keeps what the finding
25
+ # has, "else leave" where it gives nothing (#1043).
26
+ PLACEHOLDERS = TemplatePlaceholders.new(
27
+ {
28
+ "reason" => "resolved, withdrawn, new action: why, in a line; else leave",
29
+ "as" => "raised_again: the new finding's id; else leave",
30
+ "evidence" => [{ "path" => "resolved: where the fix shows, with heading; else leave" }],
31
+ "action" => "still_holds: deferred or accepted; else kept",
32
+ "recorded_at" => "still_holds: a write-up pointer or null; else kept",
33
+ "waits_on" => "deferral: whom it waits on, for what, or null; else kept",
34
+ "problem" => "still_holds: restated if renamed or moved; else kept",
35
+ "problem_evidence" => [{ "path" => "still_holds: where it shows, with heading, if not kept; else leave",
36
+ "replaces" => "if moved: a lost item's position" }],
37
+ "first_raised_at" => "still_holds, if dated late: an earlier audited_at; else leave",
38
+ "raised_in" => RAISED_IN
39
+ },
40
+ empty_lists: ["problem_evidence"]
41
+ ) #: TemplatePlaceholders
42
+ # Every placeholder a prior finding's decision prints: the decision's, and each field's.
43
+ TEMPLATE_PLACEHOLDERS = { "decision" => DECISION, **PLACEHOLDERS.to_h }.freeze #: Hash[String, untyped]
44
+ end
45
+ end
46
+ end
@@ -9,6 +9,7 @@ require_relative "first_raised_claim"
9
9
  require_relative "kept_prior_finding"
10
10
  require_relative "open_finding"
11
11
  require_relative "still_holds_restatement"
12
+ require_relative "prior_decision_fields"
12
13
  require_relative "waits_on"
13
14
 
14
15
  module Principles
@@ -22,13 +23,12 @@ module Principles
22
23
  # What the completed result shows of each closed finding.
23
24
  CLOSED_FIELDS = %w[finding_id decision reason evidence].freeze
24
25
  REPAIR = "Decide it still_holds, raised_again with as, or resolved or withdrawn with a one-line reason."
25
-
26
26
  # finding is the prior finding as its record left it open; at is the decision's place in the answer, such as
27
27
  # /prior_finding_decisions/0, which a refusal about its pointers names; members are the map's members now, which
28
28
  # a kept finding's members must still be among.
29
- #: (Hash[String, untyped], OpenFinding, Array[String], at: String, members: MapMembers) -> void
29
+ #: (Hash[String, untyped], OpenFinding, Array[String], at: String, members: PrincipleMembers) -> void
30
30
  def initialize(decision, finding, new_ids, at:, members:)
31
- @decision = decision.reject { |key, value| key == "problem_evidence" && value == [] } #: Hash[String, untyped]
31
+ @decision = PriorDecisionFields::PLACEHOLDERS.given(decision) #: Hash[String, untyped]
32
32
  @finding = finding
33
33
  @new_ids = new_ids
34
34
  @members = members
@@ -44,6 +44,7 @@ module Principles
44
44
  kind = @decision["decision"]
45
45
  invalid("#{kind.inspect} is not a decision") unless KINDS.include?(kind)
46
46
  kind == "still_holds" ? holds : closed_or_raised(kind)
47
+ pointers_as_text
47
48
  fix_shown(locate)
48
49
  new_action
49
50
  StillHoldsRestatement.new(@decision, @finding, @place, refuse: refusal).check(locate)
@@ -79,6 +80,16 @@ module Principles
79
80
 
80
81
  private
81
82
 
83
+ # Refuses text, other than its placeholder, in a field that takes pointers, which the schema lets be text only
84
+ # so the placeholder can be left (#994).
85
+ #: () -> void
86
+ def pointers_as_text
87
+ field = PriorDecisionFields::POINTERS.find { |name| @decision[name].is_a?(String) } or return
88
+ invalid("#{field} is text, not pointers into the project",
89
+ "Give #{field} as pointers, such as {\"path\": ..., \"heading\": ...}, or leave its placeholder as " \
90
+ "printed.")
91
+ end
92
+
82
93
  # A still_holds decision may make its finding deferred or accepted, with a one-line reason, and a deferral
83
94
  # says where it is written up, if only as null, as a correction's does (D35 brief, finding 14).
84
95
  #: () -> void
@@ -117,6 +128,16 @@ module Principles
117
128
  #: () -> void
118
129
  def holds
119
130
  gone unless @finding.removed_from(@members).empty?
131
+ unkept_reason if @decision.key?("reason") && !@decision.key?("action")
132
+ end
133
+
134
+ # A reason on a still_holds decision that changes no action, which the record has nowhere to keep, so the fact
135
+ # it corrects would stay as it was (#992).
136
+ #: () -> bot
137
+ def unkept_reason
138
+ invalid("still_holds keeps no reason",
139
+ "Drop reason from #{@id}'s decision. To correct what #{@id} says, give problem, one line restating " \
140
+ "it; to change its action, give action with the reason.")
120
141
  end
121
142
 
122
143
  #: (String) -> void
@@ -26,14 +26,21 @@ module Principles
26
26
  holding = of(["still_holds"]).map(&:kept)
27
27
  DecidedPriorFindings.new(
28
28
  { "kept" => holding.map(&:to_h), "closed" => of(PriorFindingDecision::CLOSING).map(&:closed),
29
- "inherited" => first_raised(of(["raised_again"])), "dropped" => holding.filter_map(&:dropped_write_up),
30
- "waits_on_dropped" => holding.filter_map(&:waits_on_dropped),
31
- "evidence_replaced" => holding.flat_map(&:swaps) }
29
+ "inherited" => first_raised(of(["raised_again"])), **changed(holding) }
32
30
  )
33
31
  end
34
32
 
35
33
  private
36
34
 
35
+ # What the still_holds decisions changed of the findings they kept, which the completed result names.
36
+ #: (Array[KeptPriorFinding]) -> Hash[String, Array[Hash[String, untyped]]]
37
+ def changed(holding)
38
+ { "dropped" => holding.filter_map(&:dropped_write_up),
39
+ "waits_on_dropped" => holding.filter_map(&:waits_on_dropped),
40
+ "evidence_replaced" => holding.flat_map(&:swaps),
41
+ "problems_restated" => holding.filter_map(&:problem_restated) }
42
+ end
43
+
37
44
  #: (Array[String]) -> Array[PriorFindingDecision]
38
45
  def of(kinds) = @decisions.select { |decision| kinds.include?(decision.kind) }
39
46
 
@@ -16,7 +16,7 @@ module Principles
16
16
  # lists them and checks the decisions; whether a finding still holds is the agent's judgement.
17
17
  class PriorFindings
18
18
  # record is the last audit's record, or nil; members are the map's members now, and now each one's hash.
19
- #: (record: AuditRecord?, members: MapMembers, now: Hash[String, String]) -> void
19
+ #: (record: AuditRecord?, members: PrincipleMembers, now: Hash[String, String]) -> void
20
20
  def initialize(record:, members:, now:)
21
21
  @record = record
22
22
  @left_open = record&.left_open || [] #: Array[OpenFinding]
@@ -42,6 +42,10 @@ module Principles
42
42
  #: () -> bool
43
43
  def assessed_change? = @maps.any?(&:assessed_change?)
44
44
 
45
+ # Whether any map's member no audit assessed was edited since the commit that mapped it (D44).
46
+ #: () -> bool
47
+ def unassessed_change? = @maps.any?(&:unassessed_change?)
48
+
45
49
  # For each map with a changed member a one-member audit may judge, the ids of those members, which
46
50
  # list-member-problems offers that audit for, one command each (#626, D56).
47
51
  #: () -> Hash[String, Array[String]]
@@ -52,10 +56,10 @@ module Principles
52
56
  # For each map with members no baseline holds, its map file and the files those members are in, and in git
53
57
  # only those of them that differ from HEAD or are untracked, since committing an unchanged file does nothing
54
58
  # (#710 X3). In git the list is empty when every one is committed already.
55
- #: (MemberMaps) -> Hash[String, Array[String]]
56
- def files_to_commit(member_maps)
59
+ #: (MappedPrinciples) -> Hash[String, Array[String]]
60
+ def files_to_commit(principles)
57
61
  no_baseline_paths.to_h do |id, paths|
58
- files = [member_maps.file(id), *paths]
62
+ files = [principles.file(id), *paths]
59
63
  [id, @history&.inside_git? ? @history.uncommitted(files) : files]
60
64
  end
61
65
  end