principles 0.0.1 → 0.0.5

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 (197) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +10 -2
  3. data/lib/principles/command_line.rb +46 -35
  4. data/lib/principles/command_routes.rb +4 -3
  5. data/lib/principles/controllers/acknowledgement.rb +84 -18
  6. data/lib/principles/controllers/answer.rb +56 -125
  7. data/lib/principles/controllers/answer_phase.rb +54 -0
  8. data/lib/principles/controllers/assessment.rb +132 -0
  9. data/lib/principles/controllers/audit.rb +45 -140
  10. data/lib/principles/controllers/audit_completion.rb +8 -8
  11. data/lib/principles/controllers/command.rb +29 -14
  12. data/lib/principles/controllers/correction.rb +23 -13
  13. data/lib/principles/controllers/full_audit_request.rb +190 -0
  14. data/lib/principles/controllers/inventory.rb +46 -79
  15. data/lib/principles/controllers/mapping.rb +3 -3
  16. data/lib/principles/controllers/member_entries.rb +24 -12
  17. data/lib/principles/controllers/member_problems_report.rb +79 -0
  18. data/lib/principles/controllers/members_a_commit_changed.rb +12 -3
  19. data/lib/principles/controllers/members_to_assess.rb +35 -20
  20. data/lib/principles/controllers/meta_principle_setup.rb +5 -5
  21. data/lib/principles/controllers/repoint.rb +19 -23
  22. data/lib/principles/controllers/running_tool.rb +1 -1
  23. data/lib/principles/data/audit_files.rb +11 -7
  24. data/lib/principles/data/bounded_file.rb +20 -4
  25. data/lib/principles/data/command-steps.json +14 -13
  26. data/lib/principles/data/map_files.rb +2 -2
  27. data/lib/principles/data/principles_subfolder.rb +8 -1
  28. data/lib/principles/data/project_files.rb +12 -15
  29. data/lib/principles/data/project_root.rb +48 -0
  30. data/lib/principles/data/schema_check.rb +39 -11
  31. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
  32. data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
  33. data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
  34. data/lib/principles/data/schemas/audit-record.schema.json +13 -1
  35. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  36. data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
  37. data/lib/principles/invocation_options.rb +1 -1
  38. data/lib/principles/models/acknowledgement.rb +73 -84
  39. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  40. data/lib/principles/models/answer_place.rb +4 -0
  41. data/lib/principles/models/assessment_answer.rb +19 -17
  42. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  43. data/lib/principles/models/audit.rb +24 -15
  44. data/lib/principles/models/audit_record.rb +19 -20
  45. data/lib/principles/models/audit_records.rb +77 -4
  46. data/lib/principles/models/audit_start.rb +3 -3
  47. data/lib/principles/models/candidate_files.rb +30 -7
  48. data/lib/principles/models/candidate_inventory.rb +23 -6
  49. data/lib/principles/models/candidate_listing.rb +12 -3
  50. data/lib/principles/models/candidate_outline.rb +195 -0
  51. data/lib/principles/models/carried_assessments.rb +1 -1
  52. data/lib/principles/models/carried_member.rb +42 -0
  53. data/lib/principles/models/check_since_last_audit.rb +22 -9
  54. data/lib/principles/models/command_steps.rb +17 -1
  55. data/lib/principles/models/correction_basis.rb +1 -1
  56. data/lib/principles/models/decided_prior_findings.rb +9 -19
  57. data/lib/principles/models/declared_map_changes.rb +13 -12
  58. data/lib/principles/models/disposition.rb +28 -24
  59. data/lib/principles/models/evidence_replacements.rb +8 -1
  60. data/lib/principles/models/fix_only_fields.rb +67 -0
  61. data/lib/principles/models/frontmatter_fields.rb +9 -8
  62. data/lib/principles/models/instruction_named.rb +35 -0
  63. data/lib/principles/models/kept_prior_finding.rb +12 -7
  64. data/lib/principles/models/left_as_printed.rb +39 -0
  65. data/lib/principles/models/loaded_files.rb +5 -3
  66. data/lib/principles/models/loading_decision.rb +9 -2
  67. data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
  68. data/lib/principles/models/member.rb +1 -1
  69. data/lib/principles/models/member_assessments.rb +32 -9
  70. data/lib/principles/models/member_file.rb +35 -11
  71. data/lib/principles/models/member_grounds.rb +2 -2
  72. data/lib/principles/models/member_hashes_as_written.rb +44 -0
  73. data/lib/principles/models/member_lines.rb +63 -15
  74. data/lib/principles/models/member_moves.rb +3 -3
  75. data/lib/principles/models/member_problems.rb +50 -24
  76. data/lib/principles/models/member_repair_moves.rb +54 -0
  77. data/lib/principles/models/members_sharing_lines.rb +3 -3
  78. data/lib/principles/models/missing_files.rb +2 -2
  79. data/lib/principles/models/new_findings.rb +55 -0
  80. data/lib/principles/models/open_finding.rb +23 -13
  81. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  82. data/lib/principles/models/other_principles.rb +1 -1
  83. data/lib/principles/models/other_templates_placeholders.rb +113 -0
  84. data/lib/principles/models/outline_budget.rb +127 -0
  85. data/lib/principles/models/outline_group.rb +31 -0
  86. data/lib/principles/models/outline_section.rb +56 -0
  87. data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
  88. data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
  89. data/lib/principles/models/{map_members.rb → principle_members.rb} +15 -4
  90. data/lib/principles/models/prior_decision_fields.rb +47 -0
  91. data/lib/principles/models/prior_finding_decision.rb +38 -7
  92. data/lib/principles/models/prior_finding_outcomes.rb +10 -3
  93. data/lib/principles/models/prior_findings.rb +1 -1
  94. data/lib/principles/models/problem_report.rb +7 -3
  95. data/lib/principles/models/project.rb +22 -17
  96. data/lib/principles/models/project_history.rb +2 -2
  97. data/lib/principles/models/quoted_change.rb +137 -0
  98. data/lib/principles/models/recent_decision.rb +90 -0
  99. data/lib/principles/models/record_format.rb +109 -0
  100. data/lib/principles/models/recorded_entry.rb +6 -0
  101. data/lib/principles/models/recorded_finding.rb +4 -0
  102. data/lib/principles/models/recorded_hashes.rb +43 -0
  103. data/lib/principles/models/recorded_members.rb +33 -16
  104. data/lib/principles/models/refusal_before_shape.rb +21 -0
  105. data/lib/principles/models/repoint.rb +13 -0
  106. data/lib/principles/models/reported_check.rb +66 -24
  107. data/lib/principles/models/request_id.rb +24 -4
  108. data/lib/principles/models/sent_answer.rb +51 -0
  109. data/lib/principles/models/sent_prior_decisions.rb +31 -0
  110. data/lib/principles/models/shape_problems_beside.rb +40 -0
  111. data/lib/principles/models/still_holds_restatement.rb +7 -10
  112. data/lib/principles/models/submitted_answer.rb +34 -0
  113. data/lib/principles/models/template_placeholders.rb +71 -0
  114. data/lib/principles/models/text_within.rb +55 -0
  115. data/lib/principles/models/unchecked_members.rb +76 -0
  116. data/lib/principles/models/write_up_opening.rb +21 -4
  117. data/lib/principles/session_start_options.rb +29 -0
  118. data/lib/principles/start_audit_options.rb +52 -0
  119. data/lib/principles/version.rb +2 -2
  120. data/lib/principles/views/acknowledgement_result.rb +15 -7
  121. data/lib/principles/views/answer_head.rb +29 -0
  122. data/lib/principles/views/assessed_members.rb +129 -0
  123. data/lib/principles/views/assessment_request.rb +139 -78
  124. data/lib/principles/views/audit_result.rb +55 -42
  125. data/lib/principles/views/candidate_files_result.rb +41 -19
  126. data/lib/principles/views/check_notes.rb +44 -0
  127. data/lib/principles/views/check_result_template.rb +42 -30
  128. data/lib/principles/views/correction_request.rb +64 -0
  129. data/lib/principles/views/first_audit.rb +71 -0
  130. data/lib/principles/views/help.rb +3 -2
  131. data/lib/principles/views/instruction.rb +74 -0
  132. data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
  133. data/lib/principles/views/loads_to_check_result.rb +13 -6
  134. data/lib/principles/views/map_added_to.rb +31 -0
  135. data/lib/principles/views/map_result.rb +38 -23
  136. data/lib/principles/views/member_change_since_baseline.rb +22 -5
  137. data/lib/principles/views/member_repairs.rb +21 -52
  138. data/lib/principles/views/members_a_commit_changed.rb +40 -10
  139. data/lib/principles/views/meta_principle_result.rb +3 -14
  140. data/lib/principles/views/one_member_check_result_template.rb +43 -0
  141. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  142. data/lib/principles/views/open_findings_line.rb +77 -23
  143. data/lib/principles/views/principle_read_result.rb +37 -28
  144. data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
  145. data/lib/principles/views/prior_findings_result.rb +30 -18
  146. data/lib/principles/views/problem_lines.rb +14 -11
  147. data/lib/principles/views/problem_result.rb +30 -16
  148. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  149. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  150. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
  151. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  152. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  153. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +6 -17
  154. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
  155. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  156. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  157. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  158. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  159. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  160. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  161. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  162. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
  163. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  164. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -4
  165. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  166. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  167. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
  168. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  169. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  170. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  171. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
  172. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
  173. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +21 -6
  174. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +25 -23
  175. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +18 -16
  176. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +4 -2
  177. data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
  178. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +7 -1
  179. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
  180. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +7 -6
  181. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
  182. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +30 -30
  183. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +39 -39
  184. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
  185. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  186. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
  187. data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
  188. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  189. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  190. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +11 -7
  191. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  192. data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
  193. data/lib/principles/views/request_part.rb +26 -6
  194. data/lib/principles/views/request_parts.rb +8 -0
  195. metadata +69 -9
  196. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  197. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -5,6 +5,7 @@ require_relative "../error"
5
5
  require_relative "answer_fields"
6
6
  require_relative "answer_place"
7
7
  require_relative "answer_text"
8
+ require_relative "fix_only_fields"
8
9
  require_relative "waits_on"
9
10
  require_relative "write_up_pointer"
10
11
 
@@ -75,11 +76,20 @@ module Principles
75
76
  TEXT_FIELDS = {
76
77
  "reason" => TextField.new(placeholder: "Why, and what remains",
77
78
  repair: "Write why you chose this action and what remains."),
78
- "reassessment" => TextField.new(placeholder: "When fixed, how the changed members now carry the principle",
79
+ "reassessment" => TextField.new(placeholder: "fixed only: how the changed members now carry the " \
80
+ "principle. Leave as printed otherwise",
79
81
  repair: "Write how the changed members now carry the principle.")
80
82
  }.freeze #: Hash[String, TextField]
81
83
  # The placeholder in each field, which the template prints.
82
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 (D81 step 3). 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 and evidence and gives a reassessment; deferred gives recorded_at, " \
89
+ "where the write-up is, and may give waits_on; any other action leaves changed_members, " \
90
+ "evidence and reassessment as printed" #: String
91
+ # Every placeholder a correction's template prints: each text field's, and the action's.
92
+ TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION_PLACEHOLDER).freeze #: Hash[String, String]
83
93
 
84
94
  # at is the disposition's place in the answer, such as /dispositions/0, which a refusal about its pointers names.
85
95
  # samples is the answer guide's disposition for each action, whose text illustrates each field (#789).
@@ -105,19 +115,21 @@ module Principles
105
115
  #: () -> bool
106
116
  def fixed? = action == "fixed"
107
117
 
108
- # The members a fix says it changed.
118
+ # The members a fix says it changed; none from a disposition that omits them, as one not fixed may (#997).
109
119
  #: () -> Array[String]
110
- def changed_members = @disposition.fetch("changed_members")
120
+ def changed_members = @disposition.fetch("changed_members", [])
111
121
 
112
122
  # The file where the finding is written up, if anywhere.
113
123
  #: () -> String?
114
124
  def recorded_path = recorded_at&.path
115
125
 
116
- # What the audit record keeps of this disposition beside its finding: the action, where the finding is
117
- # written up and what a deferral waits on, when given (D52).
126
+ # What the audit record keeps of this disposition beside its finding: the action, and why a finding left
127
+ # unfixed was left so, which a fix's reassessment answers instead (#996); where the finding is written up and
128
+ # what a deferral waits on, when given (D52).
118
129
  #: () -> Hash[String, untyped]
119
130
  def recorded_outcome
120
- { "action" => action, "recorded_at" => recorded_at&.to_h, "waits_on" => @disposition["waits_on"] }.compact
131
+ { "action" => action, "reason" => (@disposition["reason"] unless fixed?), "recorded_at" => recorded_at&.to_h,
132
+ "waits_on" => @disposition["waits_on"] }.compact
121
133
  end
122
134
 
123
135
  # Where the finding is written up, if anywhere, as checked_fields located it.
@@ -140,21 +152,22 @@ module Principles
140
152
  def claimed_members(changed)
141
153
  action = @disposition["action"]
142
154
  checked_fields
143
- members = @fields.array(@disposition["changed_members"], "changed_members")
155
+ members = @fields.array(fix_fields.list("changed_members"), "changed_members")
144
156
  entries = @disposition.fetch("changed_map_entries", [])
145
- action == "fixed" ? fixed_members(members, entries, changed) : unclaimed(members, entries)
157
+ action == "fixed" ? fixed_members(members, entries, changed) : fix_fields.unclaimed(members, entries)
146
158
  end
147
159
 
148
160
  private
149
161
 
150
- # The template leaves each action null, since choosing it is the agent's call; a null or unknown one is
151
- # left for the agent, with the four to choose from (#708).
162
+ # The template leaves each action null, or as its placeholder, since choosing it is the agent's call; a null,
163
+ # placeholder or unknown one is left for the agent, with the four to choose from (#708).
152
164
  #: () -> UnfinishedField?
153
165
  def unchosen_action
154
166
  action = @disposition["action"]
155
167
  return if ACTIONS.include?(action)
156
168
 
157
- problem = action.nil? ? "is not chosen" : "is #{action.inspect}, not one of the four"
169
+ unchosen = action.nil? || action == ACTION_PLACEHOLDER
170
+ problem = unchosen ? "is not chosen" : "is #{action.inspect}, not one of the four"
158
171
  UnfinishedField.new(@place.child("action"), "action",
159
172
  problem:, repair: "Set its action to one of fixed, deferred, accepted or disagreed.")
160
173
  end
@@ -201,10 +214,13 @@ module Principles
201
214
  .check(code: "invalid_disposition", subject: "Finding #{finding_id}")
202
215
  end
203
216
 
217
+ #: () -> FixOnlyFields
218
+ def fix_fields = FixOnlyFields.new(@disposition, left_reassessment: PLACEHOLDERS.fetch("reassessment"))
219
+
204
220
  # Each piece of evidence, and where the finding is written up, located in the project.
205
221
  #: () -> void
206
222
  def locate_pointers
207
- @fields.evidence(@disposition["evidence"], @place.child("evidence"))
223
+ @fields.evidence(fix_fields.list("evidence"), @place.child("evidence"))
208
224
  @fields.pointer(@disposition["recorded_at"], @place.child("recorded_at")) if @disposition["recorded_at"]
209
225
  end
210
226
 
@@ -216,18 +232,6 @@ module Principles
216
232
  "Set recorded_at to where the finding is written up, as {\"path\": ..., \"heading\": ...}, " \
217
233
  "or to null when it is written up nowhere.")
218
234
  end
219
-
220
- #: (Array[untyped], Array[untyped]) -> Array[untyped]
221
- def unclaimed(members, entries)
222
- unless entries.empty?
223
- raise Error.new("invalid_disposition", "Only a fixed disposition may list changed_map_entries",
224
- "Mark it fixed with a reassessment, or omit changed_map_entries.")
225
- end
226
- return [] if members.empty?
227
-
228
- raise Error.new("invalid_disposition", "Only a fixed disposition may claim changed members",
229
- "Mark it fixed with a reassessment, or omit changed_members.")
230
- end
231
235
  end
232
236
  end
233
237
  end
@@ -68,7 +68,7 @@ module Principles
68
68
  unnamed(id, refuse) if named.any?(nil)
69
69
  stray = named.grep_v(0...@kept.size).first
70
70
  if stray
71
- refuse.call("replaces #{stray} names no item of its evidence",
71
+ refuse.call(stray_problem(stray),
72
72
  "Name by replaces a position in #{id}'s evidence, from 0 to #{@kept.size - 1}.")
73
73
  end
74
74
  twice = named.find { |index| named.count(index) > 1 } or return
@@ -76,6 +76,13 @@ module Principles
76
76
  "Give each item of #{id}'s evidence at most one entry in its problem_evidence.")
77
77
  end
78
78
 
79
+ # What is wrong with a replaces naming no kept item: text is only ever the template's placeholder, which the
80
+ # answer's schema lets through for it (#1043).
81
+ #: (untyped) -> String
82
+ def stray_problem(stray)
83
+ stray.is_a?(String) ? "replaces is left as printed" : "replaces #{stray} names no item of its evidence"
84
+ end
85
+
79
86
  # Refuses entries that do not say which kept item each replaces, since the record keeps the evidence it was
80
87
  # raised with.
81
88
  #: (String, ^(String, String?) -> void) -> void
@@ -0,0 +1,67 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "answer_text"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # The fields of a disposition that only a fix uses, changed_members, changed_map_entries, evidence and
11
+ # reassessment, and what its action allows of them: a fix gives them, and any other action may omit them, or leave
12
+ # them as printed, and claims no change (#997).
13
+ class FixOnlyFields
14
+ # 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
17
+ def initialize(disposition, left_reassessment:)
18
+ @disposition = disposition
19
+ @left_reassessment = left_reassessment
20
+ freeze
21
+ end
22
+
23
+ # The list field name gives, as given, or an empty list when a disposition not fixed omits it; a fix omitting
24
+ # it is refused, naming the field.
25
+ #: (String) -> untyped
26
+ def list(name) = @disposition.fetch(name) { fixed? ? missing_from_fix(name) : [] }
27
+
28
+ # The members a disposition not fixed claims, none, refusing one that lists changed members or map entries,
29
+ # writes a reassessment or lists evidence, each of which it would drop unread though the agent may have meant
30
+ # a fix.
31
+ #: (Array[untyped], Array[untyped]) -> Array[untyped]
32
+ def unclaimed(members, entries)
33
+ unless entries.empty?
34
+ raise Error.new("invalid_disposition", "Only a fixed disposition may list changed_map_entries",
35
+ "Mark it fixed with a reassessment, or omit changed_map_entries.")
36
+ end
37
+ fix_text_unclaimed
38
+ return [] if members.empty?
39
+
40
+ raise Error.new("invalid_disposition", "Only a fixed disposition may claim changed members",
41
+ "Mark it fixed with a reassessment, or omit changed_members.")
42
+ end
43
+
44
+ private
45
+
46
+ #: () -> bool
47
+ def fixed? = @disposition["action"] == "fixed"
48
+
49
+ #: (String) -> bot
50
+ def missing_from_fix(name)
51
+ raise Error.new("invalid_disposition", "Finding #{@disposition["finding_id"]} is fixed, so it needs #{name}",
52
+ "List in #{name} what the fix changed, or choose another action.")
53
+ end
54
+
55
+ # Refuses a reassessment written, or evidence listed, on a disposition not fixed; each left as printed is not
56
+ # given.
57
+ #: () -> void
58
+ def fix_text_unclaimed
59
+ reassessment = @disposition["reassessment"]
60
+ written = reassessment != @left_reassessment && AnswerText.new(reassessment).written?
61
+ field = ("reassessment" if written) || ("evidence" unless list("evidence").empty?) or return
62
+ raise Error.new("invalid_disposition", "Only a fixed disposition may give #{field}",
63
+ "Mark it fixed, or leave #{field} as printed.")
64
+ end
65
+ end
66
+ end
67
+ end
@@ -59,6 +59,15 @@ module Principles
59
59
  raise unless e.payload.fetch("code") == "field_not_found"
60
60
  end
61
61
 
62
+ # The index of the --- that closes the frontmatter, or nil when the text opens with none; the
63
+ # file's body starts after it.
64
+ #: () -> Integer?
65
+ def closing_line
66
+ return nil unless @lines.first&.chomp == "---"
67
+
68
+ (1...@lines.length).find { |i| @lines.fetch(i).chomp == "---" }
69
+ end
70
+
62
71
  private
63
72
 
64
73
  # Each top-level field's name and line range, in order; refused on a line this tool would misread.
@@ -71,14 +80,6 @@ module Principles
71
80
  end
72
81
  end
73
82
 
74
- # The index of the --- that closes the frontmatter, or nil when the text opens with none.
75
- #: () -> Integer?
76
- def closing_line
77
- return nil unless @lines.first&.chomp == "---"
78
-
79
- (1...@lines.length).find { |i| @lines.fetch(i).chomp == "---" }
80
- end
81
-
82
83
  # The last line from start to last that is not blank, so trailing blank lines stay out of a field.
83
84
  #: (Integer, Integer) -> Integer
84
85
  def last_filled(start, last)
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+
7
+ module Principles
8
+ # The domain of principles and their maps: each model owns its rules and loads and saves itself through data/.
9
+ module Models
10
+ # The instruction field start-audit --instruction names, read whole from the request a full audit asks (D81 step
11
+ # 2, #983). Only a field the request prints an instruction under can be read: the others explain fields it does
12
+ # not hold.
13
+ class InstructionNamed
14
+ #: (String, principle_id: String, printed: Array[String]) -> void
15
+ def initialize(field, principle_id:, printed:)
16
+ @field = field
17
+ @id = principle_id
18
+ @printed = printed
19
+ freeze
20
+ end
21
+
22
+ # The field, refused unless the request prints an instruction under it.
23
+ #: () -> String
24
+ def field
25
+ return @field if @printed.include?(@field)
26
+
27
+ refusal = Error.new("unknown_instruction",
28
+ "This request prints no instruction named #{@field}. It prints #{ProseList.new(@printed)}.",
29
+ "")
30
+ raise refusal.ending_with([Error::RepairCommand.new(purpose: "To print one whole", command: "start-audit",
31
+ values: [@id], usage: "--instruction FIELD")])
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "first_raised_claim"
5
- require_relative "map_members"
5
+ require_relative "principle_members"
6
6
  require_relative "open_finding"
7
7
  require_relative "waits_on"
8
8
 
@@ -14,7 +14,7 @@ module Principles
14
14
  class KeptPriorFinding
15
15
  # decision is the checked still_holds decision on finding, the prior finding as its record left it open; members
16
16
  # are the map's members now, under whose ids it is recorded.
17
- #: (Hash[String, untyped], OpenFinding, MapMembers) -> void
17
+ #: (Hash[String, untyped], OpenFinding, PrincipleMembers) -> void
18
18
  def initialize(decision, finding, members)
19
19
  @decision = decision
20
20
  @finding = finding
@@ -22,9 +22,10 @@ module Principles
22
22
  freeze
23
23
  end
24
24
 
25
- # The finding as the record keeps it, with any problem, action or pointer its decision gave, and any earlier
26
- # first_raised_at it claimed with the commit it cited (D53); a null pointer drops the one it had. Its evidence is
27
- # as OpenFinding#evidence_after says, from its own state rather than as the request printed it (D64, D70).
25
+ # The finding as the record keeps it, with any problem, pointer, or action and its reason, its decision gave
26
+ # (#996), and any earlier first_raised_at it claimed with the commit it cited (D53); a null pointer drops the one
27
+ # it had. Its evidence is as OpenFinding#evidence_after says, from its own state rather than as the request
28
+ # printed it (D64, D70).
28
29
  #: () -> Hash[String, untyped]
29
30
  def to_h = @record
30
31
 
@@ -45,16 +46,20 @@ module Principles
45
46
  { "finding_id" => @finding.id, **@finding.waiting }
46
47
  end
47
48
 
49
+ # The problem its decision restated, as it was and is now, or nil when it restated none (D82).
50
+ #: () -> Hash[String, String]?
51
+ def problem_restated = @finding.restated(@decision["problem"])
52
+
48
53
  # Each kept evidence item its decision gave a new place, as it was and is now (D70).
49
54
  #: () -> Array[Hash[String, untyped]]
50
55
  def swaps = @finding.replacements(@decision["problem_evidence"]).swaps(@finding.id)
51
56
 
52
57
  private
53
58
 
54
- #: (MapMembers) -> Hash[String, untyped]
59
+ #: (PrincipleMembers) -> Hash[String, untyped]
55
60
  def record(members)
56
61
  kept = @finding.kept_against(members)
57
- .merge(@decision.slice("problem", "action", "recorded_at", *FirstRaisedClaim::FIELDS),
62
+ .merge(@decision.slice("problem", "action", "reason", "recorded_at", *FirstRaisedClaim::FIELDS),
58
63
  { "evidence" => @finding.evidence_after(@decision["problem_evidence"]) }).compact
59
64
  kept.merge(waiting_after(kept))
60
65
  end
@@ -0,0 +1,39 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "shape_problems_beside"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # The judgements an answer leaves as its template printed them, each named with its pointer, which the answer
12
+ # refuses in one refusal, so a copied template takes one repair (#991, #1010, #1040).
13
+ class LeftAsPrinted
14
+ # The problem with a judgement sent back as its placeholder.
15
+ UNCHANGED = "is the template's placeholder, unchanged" #: String
16
+
17
+ # pointers holds each judgement left as printed, by its name, with its JSON pointer.
18
+ #: (Hash[String, String]) -> void
19
+ def initialize(pointers)
20
+ @pointers = pointers.freeze #: Hash[String, String]
21
+ freeze
22
+ end
23
+
24
+ # Refuses the answer naming each judgement left as printed, then each of besides, problems its shape has
25
+ # elsewhere, so one refusal names every repair (#1106); one at or under a pointer named is left out, since
26
+ # writing the judgement repairs it. Nothing when none is left as printed, so the shape's own refusal names them.
27
+ #: (?besides: Array[Hash[String, String]]) -> void
28
+ def refuse(besides: [])
29
+ return if @pointers.empty?
30
+
31
+ elsewhere = ShapeProblemsBeside.new(besides, named: @pointers.values)
32
+ raise Error.new("invalid_answer", elsewhere.message("Still to write: #{ProseList.new(@pointers.keys)}"),
33
+ "#{elsewhere.repair("Replace each placeholder named in fields with your own judgement",
34
+ ", and repair each other field listed there")}.",
35
+ fields: @pointers.values.map { { "pointer" => it, "problem" => UNCHANGED } } + elsewhere.fields)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -13,7 +13,7 @@ module Principles
13
13
  # size and is not totalled.
14
14
  class LoadedFiles
15
15
  # The files members load, each read whole once, as files hold it.
16
- #: (Data::ProjectFiles, MapMembers, hooks: HookCommands) -> LoadedFiles
16
+ #: (Data::ProjectFiles, PrincipleMembers, hooks: HookCommands) -> LoadedFiles
17
17
  def self.read(files, members, hooks:)
18
18
  new(members.paths.to_h { |path| [path, MemberLoads.of_file(files, path, hooks: hooks)] })
19
19
  end
@@ -25,13 +25,15 @@ module Principles
25
25
  freeze
26
26
  end
27
27
 
28
- # files_loaded and session_start_total, each left out when it would be empty.
28
+ # The aggregate's derivation basis, files_loaded and session_start_total, empty lists/totals omitted.
29
29
  #: () -> Hash[String, untyped]
30
30
  def to_h
31
31
  return {} if @loads.empty?
32
32
 
33
33
  total = session_start_total
34
- { "files_loaded" => @loads.map { |path, file| { "path" => path }.merge(file.claude_code) },
34
+ { "loading_basis" => { "host" => "claude_code", "kind" => "documented_prediction",
35
+ "session_start_assumption" => "project_root" },
36
+ "files_loaded" => @loads.map { |path, file| { "path" => path }.merge(file.claude_code) },
35
37
  **(total ? { "session_start_total" => total } : {}) }
36
38
  end
37
39
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "answer_text"
6
+ require_relative "template_placeholders"
6
7
 
7
8
  module Principles
8
9
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -11,10 +12,16 @@ module Principles
11
12
  # activation (#355). Whether the member should load as it does is the agent's judgement; this tool checks the
12
13
  # decision's shape.
13
14
  class LoadingDecision
14
- # decision is as the answer gave it; index is its place in loading_decisions.
15
+ # The reason start-audit --as template prints in each decision, which left as printed is not given (#994).
16
+ PLACEHOLDERS = TemplatePlaceholders.new(
17
+ { "reason" => "One line saying why the member loads as it does" }
18
+ ) #: TemplatePlaceholders
19
+
20
+ # decision is as the answer gave it, a reason left as its placeholder not given; index is its place in
21
+ # loading_decisions.
15
22
  #: (untyped, Integer) -> void
16
23
  def initialize(decision, index)
17
- @decision = decision.is_a?(Hash) ? decision : {} #: Hash[String, untyped]
24
+ @decision = decision.is_a?(Hash) ? PLACEHOLDERS.given(decision) : {} #: Hash[String, untyped]
18
25
  @index = index
19
26
  freeze
20
27
  end
@@ -3,14 +3,14 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "../data/map_files"
6
- require_relative "member_map"
6
+ require_relative "principle"
7
7
  require_relative "meta_principle"
8
8
 
9
9
  module Principles
10
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
- # Every member map in the project, loaded and saved through Data::MapFiles.
13
- class MemberMaps
12
+ # Every principle the project maps, each loaded and saved as its map through Data::MapFiles.
13
+ class MappedPrinciples
14
14
  # A principle id names its principle in lower-kebab-case.
15
15
  ID_FORMAT = Data::PrincipleId::FORMAT #: Regexp
16
16
 
@@ -63,39 +63,39 @@ module Principles
63
63
  end
64
64
 
65
65
  # The map named id, refused when there is none; Data::MapFiles refuses one that is unparseable.
66
- #: (String) -> MemberMap
66
+ #: (String) -> Principle
67
67
  def find(id)
68
68
  refuse_unknown(id)
69
- unique(MemberMap.new(id, @files.read(id)))
69
+ unique(Principle.new(id, @files.read(id)))
70
70
  end
71
71
 
72
72
  # The map id as text read elsewhere holds it, such as its file at commit, the one an audit began from.
73
- #: (String, String, ?commit: String?) -> MemberMap
73
+ #: (String, String, ?commit: String?) -> Principle
74
74
  def parsed(id, text, commit: nil)
75
- unique(MemberMap.new(id, @files.parse(id, text, commit: commit)), commit)
75
+ unique(Principle.new(id, @files.parse(id, text, commit: commit)), commit)
76
76
  end
77
77
 
78
78
  # A new map for id with no members, not yet saved. It is refused unless id is lower-kebab-case and not
79
79
  # yet mapped, and is not the meta-principle's, which setup starts; only then is the description asked for.
80
- #: (String) { () -> String } -> MemberMap
80
+ #: (String) { () -> String } -> Principle
81
81
  def create(id, &)
82
82
  refuse_unavailable(id)
83
83
  refuse_meta_principle_id(id)
84
- MemberMap.new(id, { "description" => yield, "members" => [] })
84
+ Principle.new(id, { "description" => yield, "members" => [] })
85
85
  end
86
86
 
87
87
  # The map a new member of principle id joins: the map named id, or, while the meta-principle has none, the map
88
88
  # it starts with, not yet saved, so that map is written only with its first member (T74). Any other id no map
89
89
  # has is refused, as find refuses it.
90
- #: (String) -> MemberMap
90
+ #: (String) -> Principle
91
91
  def addable(id)
92
92
  return find(id) if mapped?(id) || !started_by_setup?(id)
93
93
 
94
- MemberMap.new(id, MetaPrinciple.starting_fields)
94
+ Principle.new(id, MetaPrinciple.starting_fields)
95
95
  end
96
96
 
97
97
  # The map named id, refused when it has no members to audit.
98
- #: (String) -> MemberMap
98
+ #: (String) -> Principle
99
99
  def auditable(id)
100
100
  map = find(id)
101
101
  return map unless map.members.empty?
@@ -105,7 +105,7 @@ module Principles
105
105
  end
106
106
 
107
107
  # Writes map's file and names it, relative to the project.
108
- #: (MemberMap) -> String
108
+ #: (Principle) -> String
109
109
  def save(map)
110
110
  @files.write(map.id, map.to_h)
111
111
  file(map.id)
@@ -130,8 +130,8 @@ module Principles
130
130
  #: (String) -> bool
131
131
  def started_by_setup?(id) = id == MetaPrinciple::ID
132
132
 
133
- # map, refused when two of its members share an id or a key, as MapMembers#refuse_repeats says.
134
- #: (MemberMap, ?String?) -> MemberMap
133
+ # map, refused when two of its members share an id or a key, as PrincipleMembers#refuse_repeats says.
134
+ #: (Principle, ?String?) -> Principle
135
135
  def unique(map, commit = nil)
136
136
  where = commit ? "#{file(map.id)} at commit #{commit[0, 12]}" : file(map.id)
137
137
  map.members.refuse_repeats(where: where, file: file(map.id))
@@ -35,7 +35,7 @@ module Principles
35
35
  LOCATORS = %w[path section starting_at ending_at query].freeze #: [String, String, String, String, String]
36
36
 
37
37
  # fields is copied and frozen, so no caller changes a member through the hash it was built from or handed;
38
- # the copy is shallow, so its strings are the caller's. MemberMap builds its members from strings it has
38
+ # the copy is shallow, so its strings are the caller's. Principle builds its members from strings it has
39
39
  # copied and frozen, so a member in a map shares nothing (#654).
40
40
  #: (Hash[String, untyped]) -> void
41
41
  def initialize(fields)
@@ -6,11 +6,13 @@ require_relative "locator"
6
6
  require_relative "answer_fields"
7
7
  require_relative "answer_place"
8
8
  require_relative "carried_assessments"
9
- require_relative "map_members"
9
+ require_relative "principle_members"
10
10
  require_relative "member_sighting"
11
11
  require_relative "misspelt_member_id"
12
12
  require_relative "record_judged_against"
13
13
  require_relative "reported_check"
14
+ require_relative "template_placeholders"
15
+ require_relative "unchecked_members"
14
16
 
15
17
  module Principles
16
18
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -22,15 +24,28 @@ module Principles
22
24
  # What a record entry keeps for a member carried forward, until completion puts back its last assessment.
23
25
  CARRIED = { "carried_forward" => true }.freeze #: Hash[String, untyped]
24
26
 
27
+ # The text a fresh member's template prints in its assessment, which an answer may not send back unchanged, as a
28
+ # correction may not send back its own (#991).
29
+ PLACEHOLDER = "Your assessment, including its context cost" #: String
30
+
31
+ # The text the template printed alone gives a sighting's fields beside delivery, each left as printed when the
32
+ # delivery gives none (#1010).
33
+ SIGHTING = TemplatePlaceholders.new(
34
+ { "observation" => "Only with delivery observed: what you saw the member do, where, and what you did not see",
35
+ "observed_at" => "Only for a sighting before this audit: when, in UTC, or a dated record's date " \
36
+ "at 00:00:00Z" }
37
+ ) #: TemplatePlaceholders
38
+
25
39
  # assessments is the answer's member_assessments; members are the mapped members, with each checked one's
26
40
  # check; fields checks each field and locates each piece of evidence; judged_against is the principle's record
27
41
  # as it stands, which says which members' last assessments may be carried forward, marked {"member_id",
28
42
  # "carried_forward": true} (D49), and which command it ran for each member's check (D63); answered_at is when
29
43
  # the answer came, which no sighting it reports is after (#699).
30
- #: (untyped, MapMembers, fields: AnswerFields, answered_at: String, ?judged_against: RecordJudgedAgainst?)
44
+ #: (untyped, PrincipleMembers, fields: AnswerFields, answered_at: String, ?judged_against: RecordJudgedAgainst?)
31
45
  #| -> void
32
46
  def initialize(assessments, members, fields:, answered_at:, judged_against: nil)
33
- @assessments = assessments
47
+ @sent = assessments #: untyped
48
+ @assessments = given(assessments) #: untyped
34
49
  @members = members
35
50
  @answered_at = answered_at
36
51
  @fields = fields
@@ -73,6 +88,14 @@ module Principles
73
88
 
74
89
  private
75
90
 
91
+ # assessments without the sighting fields each leaves as printed, which it does not give (#1010).
92
+ #: (untyped) -> untyped
93
+ def given(assessments)
94
+ return assessments unless assessments.is_a?(Array)
95
+
96
+ assessments.map { |assessment| assessment.is_a?(Hash) ? SIGHTING.given(assessment) : assessment }
97
+ end
98
+
76
99
  # Refuses answered, the ids the assessments name, unless they are the mapped ids, each once, hinting at any
77
100
  # mapped id an unmapped one is spelled like.
78
101
  #: (Array[untyped]) -> void
@@ -87,9 +110,7 @@ module Principles
87
110
 
88
111
  # The place of the assessment at index in the answer, whose fields each refusal about it points into.
89
112
  #: (untyped, Integer) -> AnswerPlace
90
- def place_of(assessment, index)
91
- AnswerPlace.new("/member_assessments/#{index}", "Member #{assessment["member_id"]}")
92
- end
113
+ def place_of(assessment, index) = AnswerPlace.member_assessment(index, assessment["member_id"])
93
114
 
94
115
  #: (untyped, AnswerPlace) -> void
95
116
  def member_assessment(assessment, place)
@@ -130,13 +151,15 @@ module Principles
130
151
  "the request asks to judge it: judge_because #{reason}" if reason
131
152
  end
132
153
 
133
- # The result reported for the member assessed at place, checked against its check.
154
+ # The result reported for the member assessed at place, checked against its check; nil for a member with none,
155
+ # whose assessment UncheckedMembers refuses if it gives one.
134
156
  #: (untyped, AnswerPlace) -> Hash[String, untyped]?
135
157
  def reported(assessment, place)
136
158
  id = assessment["member_id"]
137
159
  key = @members.found(id).key
138
- ReportedCheck.new(place, @members.check(id), ran: @judged_against&.check_run_for(key),
139
- kept: @judged_against&.check_review_for(key) || {})
160
+ check = @members.check(id) or return UncheckedMembers.new(@members).refuse_at(place, assessment["check_result"])
161
+ ReportedCheck.new(place, check, ran: @judged_against&.check_run_for(key),
162
+ kept: @judged_against&.check_review_for(key) || {})
140
163
  .result(assessment["check_result"])
141
164
  end
142
165
  end