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
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "json"
5
5
  require_relative "../error"
6
+ require_relative "../prose_list"
6
7
  require_relative "expected_type"
7
8
  require_relative "known_fields"
8
9
 
@@ -18,12 +19,28 @@ module Principles
18
19
  # This tool's own schema keyword, on an object that refuses fields it does not name: for a field an agent
19
20
  # may put there by mistake, where it belongs instead, which its refusal adds (#769), as {field => text}.
20
21
  UNREAD_FIELD_ADVICE = "x-unread-field-advice"
22
+ # This tool's own schema keyword, on a string with a pattern: what to say when the value does not match, in place
23
+ # of the pattern, for a field whose pattern holds a template's placeholder, which another template's wording
24
+ # fails (#1082).
25
+ UNMATCHED_ADVICE = "x-unmatched-advice"
21
26
  # Keywords that only describe, and check nothing; the refusal advice is worded into a refusal.
22
- ANNOTATIONS = %W[$schema $id title description #{ExpectedType::ADVICE} #{UNREAD_FIELD_ADVICE}].freeze
27
+ ANNOTATIONS = %W[$schema $id title description #{ExpectedType::ADVICE} #{UNREAD_FIELD_ADVICE}
28
+ #{UNMATCHED_ADVICE}].freeze
23
29
 
24
- #: (String) -> void
25
- def initialize(name)
26
- @schema = JSON.parse(File.read(File.join(__dir__, "schemas", "#{name}.schema.json"))) #: Hash[String, untyped]
30
+ # schema is the one named, unless a narrower one is given.
31
+ #: (String, ?Hash[String, untyped]) -> void
32
+ def initialize(name, schema = JSON.parse(File.read(File.join(__dir__, "schemas", "#{name}.schema.json"))))
33
+ @name = name
34
+ @schema = schema #: Hash[String, untyped]
35
+ end
36
+
37
+ # The check of only the top-level fields named, any other field let through, so the part a later step depends
38
+ # on is checked before the rest, as an answer's head is (#1052).
39
+ #: (Array[String]) -> SchemaCheck
40
+ def only(fields)
41
+ SchemaCheck.new(@name, @schema.merge("properties" => @schema.fetch("properties", {}).slice(*fields),
42
+ "required" => @schema.fetch("required", []) & fields,
43
+ "additionalProperties" => true))
27
44
  end
28
45
 
29
46
  # Each place data breaks the schema, as a JSON pointer and what is wrong there, sorted by pointer.
@@ -40,13 +57,14 @@ module Principles
40
57
  KnownFields.new(@schema).of(data)
41
58
  end
42
59
 
43
- # data when it fits the schema; otherwise a refusal with code, naming source and each failing field.
44
- #: (untyped, code: String, source: String, repair: String) -> untyped
45
- def checked(data, code:, source:, repair:)
60
+ # data when it fits the schema; otherwise a refusal with code, giving source and each failing field, whose
61
+ # message calls data named.
62
+ #: (untyped, code: String, source: String, repair: String, ?named: String) -> untyped
63
+ def checked(data, code:, source:, repair:, named: source)
46
64
  found = problems(data)
47
65
  return data if found.empty?
48
66
 
49
- raise Error.new(code, "#{source} is not in the shape this tool reads", repair, source, fields: found)
67
+ raise Error.new(code, "#{named} is not in the shape this tool reads", repair, source, fields: found)
50
68
  end
51
69
 
52
70
  private
@@ -71,7 +89,9 @@ module Principles
71
89
  #: (Hash[String, untyped], String, String, Array[Hash[String, String]]) -> void
72
90
  def check_string(schema, value, pointer, found)
73
91
  found << problem(pointer, "must not be empty") if too_short?(schema, value)
74
- found << problem(pointer, "must match #{schema["pattern"]}") if unmatched?(schema, value)
92
+ return unless unmatched?(schema, value)
93
+
94
+ found << problem(pointer, schema[UNMATCHED_ADVICE] || "must match #{schema["pattern"]}")
75
95
  end
76
96
 
77
97
  #: (Hash[String, untyped], String) -> bool
@@ -113,11 +133,19 @@ module Principles
113
133
  if property.is_a?(Hash)
114
134
  check(property, value, child(pointer, key), found)
115
135
  elsif property == false
116
- advice = schema.fetch(UNREAD_FIELD_ADVICE, {})[key]
117
- found << problem(child(pointer, key), ["is not a field this tool reads here", *advice].join("; "))
136
+ found << problem(child(pointer, key), unread(schema, key))
118
137
  end
119
138
  end
120
139
 
140
+ # Why key is refused in an object schema checks: not a field read there, the fields that are, so the agent need
141
+ # not guess them (#1115), and what the schema says of key, if anything (#769).
142
+ #: (Hash[String, untyped], String) -> String
143
+ def unread(schema, key)
144
+ read = schema.fetch("properties", {}).keys
145
+ ["is not a field this tool reads here", *("it reads #{ProseList.new(read)}" unless read.empty?),
146
+ *schema.fetch(UNREAD_FIELD_ADVICE, {})[key]].join("; ")
147
+ end
148
+
121
149
  #: (Hash[String, untyped], Array[untyped], String, Array[Hash[String, String]]) -> void
122
150
  def check_items(schema, value, pointer, found)
123
151
  items = schema["items"] or return
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "acknowledgement-answer.schema.json",
4
4
  "title": "Acknowledgement answer",
5
- "description": "What an agent answers a one-member audit with (D33): the request's id and basis, whether the change keeps the member's meaning, a one-line reason, and a line quoted from the member's text before the change and one from after it. Fields this tool does not read are refused (D29). Models::Acknowledgement checks the quotes and the reason.",
5
+ "description": "What an agent answers a one-member audit with (D33): the request's id and basis, whether the change keeps the member's meaning, a one-line reason, and a line quoted from the member's text before the change and one from after it, or \"\" for a side with no line the other lacks. Fields this tool does not read are refused (D29). Models::Acknowledgement checks the quotes and the reason.",
6
6
  "type": "object",
7
7
  "additionalProperties": false,
8
8
  "required": ["request_id", "basis", "meaning_kept", "reason", "old_line", "new_line"],
@@ -19,7 +19,21 @@
19
19
  },
20
20
  "meaning_kept": { "type": "boolean" },
21
21
  "reason": { "type": "string", "minLength": 1 },
22
- "old_line": { "type": "string", "minLength": 1 },
23
- "new_line": { "type": "string", "minLength": 1 }
22
+ "old_line": { "type": "string" },
23
+ "new_line": { "type": "string" },
24
+ "check_result": {
25
+ "type": "object",
26
+ "additionalProperties": false,
27
+ "x-unread-field-advice": {
28
+ "not_run_reason": "a check that cannot be run here needs a full audit: start one instead"
29
+ },
30
+ "required": ["command"],
31
+ "description": "The result of the member's check, which the answer reports when the member has one: the command as the map names it and its exit_status, which must be 0, since a check that fails or cannot be run is a full audit's to judge, with review_basis when a new line says what its review rested on (D30, D63, #1115). Models::ReportedCheck checks it.",
32
+ "properties": {
33
+ "command": { "type": "string" },
34
+ "exit_status": { "type": ["integer", "string"] },
35
+ "review_basis": { "type": "string" }
36
+ }
37
+ }
24
38
  }
25
39
  }
@@ -80,18 +80,13 @@
80
80
  "reassessment": { "type": "string" },
81
81
  "check_result": {
82
82
  "type": "object",
83
- "required": ["ran", "not_run", "limits"],
83
+ "required": ["command", "exit_status", "review_basis", "not_run_reason", "limits"],
84
84
  "additionalProperties": false,
85
85
  "properties": {
86
- "ran": {
87
- "type": "object", "required": ["command", "exit_status"], "additionalProperties": false,
88
- "properties": { "command": { "type": "string" }, "exit_status": { "type": "integer" },
89
- "review_basis": { "type": "string" } }
90
- },
91
- "not_run": {
92
- "type": "object", "required": ["command", "not_run_reason"], "additionalProperties": false,
93
- "properties": { "command": { "type": "string" }, "not_run_reason": { "type": "string" } }
94
- },
86
+ "command": { "type": "string" },
87
+ "exit_status": { "type": "integer" },
88
+ "review_basis": { "type": "string" },
89
+ "not_run_reason": { "type": "string" },
95
90
  "limits": { "type": "string" }
96
91
  }
97
92
  }
@@ -112,7 +112,8 @@
112
112
  "type": "string"
113
113
  },
114
114
  "exit_status": {
115
- "type": "integer"
115
+ "type": ["integer", "string"],
116
+ "description": "The run's exit status. A string is the template's placeholder, left unfilled, which Models::ReportedCheck reads as not given (#993)."
116
117
  },
117
118
  "not_run_reason": {
118
119
  "type": "string"
@@ -125,6 +126,10 @@
125
126
  }
126
127
  }
127
128
  },
129
+ "left_as_printed_rule": {
130
+ "type": "string",
131
+ "description": "The note start-audit --as template prints at its head saying how a field left as printed is read, which an answer may send back and Models::AssessmentAnswer ignores, whatever it holds (#1043, D88)."
132
+ },
128
133
  "collective_assessment": {
129
134
  "type": "string"
130
135
  },
@@ -139,7 +144,8 @@
139
144
  "type": "string"
140
145
  },
141
146
  "evidence": {
142
- "type": "array",
147
+ "type": ["array", "string"],
148
+ "description": "Pointers to where the decision is recorded. A string is the template's placeholder, left as printed, which Models::RecentDecision reads as not given (#994).",
143
149
  "items": {
144
150
  "type": "object",
145
151
  "required": [
@@ -202,8 +208,9 @@
202
208
  },
203
209
  "raised_in": {
204
210
  "type": "string",
205
- "pattern": "^[0-9a-f]{40}([0-9a-f]{24})?$",
206
- "description": "The full sha of the commit whose audit record, at .principles/audits/ID.json or the earlier .memeplex/audits/ID.json, left this finding open at first_raised_at (D53)."
211
+ "pattern": "^([0-9a-f]{40}([0-9a-f]{24})?|With first_raised_at: its record's commit, full sha; else leave)$",
212
+ "x-unmatched-advice": "is not this template's placeholder nor a full commit sha, as an answer filled from another template leaves it: start from this request's response_template",
213
+ "description": "The full sha of the commit whose audit record, at .principles/audits/ID.json or the earlier .memeplex/audits/ID.json, left this finding open at first_raised_at (D53). The one other value is the template's placeholder, word for word, which Models::PriorFindingDecision reads as not given, so only a sha reaches git (#994)."
207
214
  },
208
215
  "waits_on": {
209
216
  "type": ["string", "null"],
@@ -217,7 +224,8 @@
217
224
  ],
218
225
  "says": "plus starting_at (or heading) when the file holds more than this finding"
219
226
  },
220
- "type": ["object", "null"],
227
+ "type": ["object", "null", "string"],
228
+ "description": "On a still_holds decision, a new pointer to the write-up, or null for none. A string is the template's placeholder, left as printed (#994).",
221
229
  "required": ["path"],
222
230
  "additionalProperties": false,
223
231
  "properties": {
@@ -229,7 +237,8 @@
229
237
  }
230
238
  },
231
239
  "evidence": {
232
- "type": "array",
240
+ "type": ["array", "string"],
241
+ "description": "On a resolved decision, pointers to where the fix shows. A string is the template's placeholder, left as printed, which Models::PriorFindingDecision reads as not given (#994).",
233
242
  "items": {
234
243
  "type": "object",
235
244
  "required": ["path"],
@@ -244,8 +253,8 @@
244
253
  }
245
254
  },
246
255
  "problem_evidence": {
247
- "description": "On a still_holds decision, pointers to where the problem is: for a finding marked evidence_not_kept, its evidence, which the record keeps (D64); for one whose record keeps evidence, each the new place of the kept item named by replaces, its position in the finding's evidence, which must no longer be found (D70). Models::StillHoldsRestatement refuses any other.",
248
- "type": "array",
256
+ "description": "On a still_holds decision, pointers to where the problem is: for a finding marked evidence_not_kept, its evidence, which the record keeps (D64); for one whose record keeps evidence, each the new place of the kept item named by replaces, its position in the finding's evidence, which must no longer be found (D70). Models::StillHoldsRestatement refuses any other. A string is the template's placeholder, left as printed (#994).",
257
+ "type": ["array", "string"],
249
258
  "items": {
250
259
  "type": "object",
251
260
  "required": ["path"],
@@ -256,7 +265,7 @@
256
265
  "starting_at": { "type": "string" },
257
266
  "ending_at": { "type": "string" },
258
267
  "query": { "type": "string" },
259
- "replaces": { "type": "integer" }
268
+ "replaces": { "type": ["integer", "string"], "description": "The position of the kept item it replaces. A string is the template's placeholder, which Models::EvidenceReplacements refuses as naming no item (#1042)." }
260
269
  }
261
270
  }
262
271
  }
@@ -6,6 +6,8 @@
6
6
  "type": "object",
7
7
  "required": ["principle_id", "status", "map_version", "base_commit", "audited_at", "members", "findings"],
8
8
  "properties": {
9
+ "format": { "type": "integer", "description": "The record format, raised when a field is added that an older copy would drop on a rewrite. A record without it is older than format 1, and any copy may rewrite it (D85)." },
10
+ "format_first_release": { "type": "string", "minLength": 1, "description": "The first release that wrote this format, which a copy that does not know it names as the update to make (D85)." },
9
11
  "principle_id": { "type": "string", "minLength": 1 },
10
12
  "status": { "enum": ["open", "completed"] },
11
13
  "map_version": { "type": "string", "minLength": 1 },
@@ -196,7 +198,16 @@
196
198
  "reason": { "type": "string", "minLength": 1 },
197
199
  "acknowledged_at": { "type": "string", "minLength": 1 },
198
200
  "deferred_findings": { "type": "array", "items": { "type": "string", "minLength": 1 } },
199
- "accepted_findings": { "type": "array", "items": { "type": "string", "minLength": 1 } }
201
+ "accepted_findings": { "type": "array", "items": { "type": "string", "minLength": 1 } },
202
+ "check_result": {
203
+ "description": "The run of the member's check the acknowledgement's answer reported, which passed (#1112).",
204
+ "type": "object",
205
+ "required": ["command", "exit_status"],
206
+ "properties": {
207
+ "command": { "type": "string", "minLength": 1 },
208
+ "exit_status": { "type": "integer" }
209
+ }
210
+ }
200
211
  }
201
212
  }
202
213
  }
@@ -243,6 +254,7 @@
243
254
  "first_raised_at": { "type": "string", "minLength": 1, "description": "When an earlier audit first raised this finding, kept or raised again since (D35). Absent means this record's audited_at." },
244
255
  "raised_in": { "type": "string", "minLength": 1, "description": "The commit whose record a full audit cited for an earlier first_raised_at, checked to leave this finding open then (D53)." },
245
256
  "action": { "type": "string", "minLength": 1 },
257
+ "reason": { "type": "string", "minLength": 1, "description": "On a finding not fixed, why its answer chose its action, as the correction's disposition or a still_holds decision changing the action gave it, kept by each later audit that keeps the finding (#996). Absent from a fixed finding and from one recorded before it was kept." },
246
258
  "waits_on": { "type": "string", "minLength": 1, "description": "On a deferred finding, the one line its answer gave saying whom it waits on and to decide what (D52)." },
247
259
  "waits_on_since": { "type": "string", "minLength": 1, "description": "When an earlier audit asked waits_on, carried since. Absent means this record's audited_at; only principles writes it (D52)." },
248
260
  "recorded_at": {
@@ -72,7 +72,8 @@
72
72
  "usage": { "$ref": "#/$defs/prose" },
73
73
  "group": { "$ref": "#/$defs/slug" },
74
74
  "options": { "type": "array", "uniqueItems": true,
75
- "items": { "enum": ["description", "path", "section", "starting-at", "ending-at", "query", "role", "check", "file", "short", "session-start", "commits-after", "hook-event", "member", "when-files", "when-invoked", "always", "write-ups"] } },
75
+ "items": { "enum": ["description", "path", "section", "starting-at", "ending-at", "query", "role", "check", "file", "short", "session-start", "commits-after", "hook-event", "member", "when-files", "when-invoked", "always", "write-ups", "as", "instruction"] } },
76
+ "requires": { "type": "array", "uniqueItems": true, "items": { "enum": ["file"] } },
76
77
  "summary": { "$ref": "#/$defs/prose" },
77
78
  "help": { "type": "string", "pattern": "^[a-z]+(-[a-z]+)+/[a-z]+(-[a-z]+)+$" },
78
79
  "steps": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/step" } }
@@ -185,10 +185,9 @@
185
185
  "required": [
186
186
  "finding_id",
187
187
  "action",
188
- "reason",
189
- "evidence",
190
- "changed_members"
188
+ "reason"
191
189
  ],
190
+ "description": "changed_members, evidence and reassessment are a fix's; Models::Disposition refuses a fixed disposition missing one, and any other may omit them (#997).",
192
191
  "properties": {
193
192
  "finding_id": {
194
193
  "type": "string"
@@ -9,7 +9,7 @@ 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 member session-start commits-after hook-event].freeze #: Array[String]
12
+ check member session-start commits-after hook-event as instruction].freeze #: Array[String]
13
13
  # The options that take no value, as list-member-problems --short (#291).
14
14
  FLAG_OPTIONS = %w[short when-invoked always write-ups].freeze #: Array[String]
15
15
  # The options that may be given more than once, each value kept in order, as change-activation --when-files.
@@ -2,10 +2,16 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
+ require_relative "acknowledgement_refusal"
5
6
  require_relative "request_id"
6
7
  require_relative "audit_record"
7
8
  require_relative "member"
9
+ require_relative "member_lines"
8
10
  require_relative "placement"
11
+ require_relative "quoted_change"
12
+ require_relative "reported_check"
13
+ require_relative "answer_place"
14
+ require_relative "template_placeholders"
9
15
 
10
16
  module Principles
11
17
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -14,28 +20,23 @@ module Principles
14
20
  # from before and after it, so the record's baseline for that member moves on and --short stops repeating it.
15
21
  # Refused outside git, for a member no completed audit assessed, and for an unchanged or checked member.
16
22
  class Acknowledgement
17
- # One side of the change a quote is checked against: the member's lines then, and when they read.
18
- class SideOfTheChange
19
- #: String
20
- attr_reader :reads_at
21
-
22
- #: (Array[String], String) -> void
23
- def initialize(lines, reads_at)
24
- @lines = lines.map(&:chomp) #: Array[String]
25
- @reads_at = reads_at
26
- freeze
27
- end
28
-
29
- #: (String) -> bool
30
- def whole_line?(quote) = @lines.include?(quote)
31
-
32
- #: (String) -> bool
33
- def holds?(text) = @lines.any? { |line| line.include?(text) }
34
- end
35
-
36
23
  PHASE = "acknowledgement"
37
- # The fewest characters a quoted fragment of a line may have, so it shows which edit was read (#352).
38
- FRAGMENT_LENGTH = 30
24
+ # The text the answer's template prints in each field the agent judges, which an answer may not send back, so
25
+ # a template returned as printed acknowledges nothing (#773). Its quotes print first_changed_lines instead,
26
+ # which the answer may send back as printed (#1111). After a pure insertion, meaning_kept's says that an
27
+ # inserted line usually adds a rule, for an agent that reads the template alone (#1142).
28
+ PLACEHOLDERS = TemplatePlaceholders.new(
29
+ { "meaning_kept" => "true only if the member still says the same thing",
30
+ "reason" => "Why, in one line of your own" },
31
+ also_printed: { "meaning_kept" => "true only if the member still says the same thing; old_line \"\" means a " \
32
+ "line was inserted, which usually adds a rule" }
33
+ ) #: TemplatePlaceholders
34
+
35
+ # The placeholders the template prints beside quotes, its first_changed_lines.
36
+ #: (Hash[String, String]) -> Hash[String, untyped]
37
+ def self.placeholders_beside(quotes)
38
+ quotes["old_line"] == "" ? PLACEHOLDERS.with_other_text_in("meaning_kept") : PLACEHOLDERS.to_h
39
+ end
39
40
 
40
41
  # before holds the member's lines at its baseline commit, now its lines and hash at base, HEAD.
41
42
  #: (principle_id: String, member: Member, record: AuditRecord?, base: String?, now_sha256: String) -> void
@@ -109,95 +110,83 @@ module Principles
109
110
  end
110
111
 
111
112
  # The record with this member's baseline moved to its text now, once the answer is checked against the
112
- # member's lines at the baseline commit and now.
113
- #: (untyped, before: Array[String], now: Array[String], at: String) -> AuditRecord
114
- def accepted(answer, before:, now:, at:)
115
- checked(answer, before, now)
113
+ # member's lines at the baseline commit and now. The change keeps the check run the answer reported, which the
114
+ # member's check_result cannot show was this run when the last audit's passed with the same command (#1112).
115
+ #: (untyped, MemberLines, at: String) -> AuditRecord
116
+ def accepted(answer, lines, at:)
117
+ checked(answer, lines)
118
+ result = check_result(answer)
119
+ run = result ? { "check_result" => result.slice("command", "exit_status") } : {}
116
120
  acknowledgeable.acknowledged(@member.key, { "from_sha256" => acknowledgeable.members.hash_for(@member.key),
117
121
  "to_sha256" => @now_sha256, "commit" => @base,
118
122
  "reason" => answer.fetch("reason"), "acknowledged_at" => at,
119
- **open_findings })
123
+ **open_findings, **run }, check_result: result)
124
+ end
125
+
126
+ # The result the answer reports for the member's check, checked against the check the record ran and carrying
127
+ # the line its last review rested on (D30, D63), once it passed: a check that failed or could not run is a full
128
+ # audit's to judge (#1071). nil for a member without a check, whose answer may report none.
129
+ #: (untyped) -> Hash[String, untyped]?
130
+ def check_result(answer)
131
+ check = @member.check
132
+ refuse("it has no check, so its answer reports no check_result") if !check && answer.key?("check_result")
133
+ return unless check
134
+
135
+ record = acknowledgeable
136
+ passed(ReportedCheck.new(AnswerPlace.new("", "The acknowledgement"), check,
137
+ ran: record.check_run_for(@member.key), kept: record.check_review_for(@member.key))
138
+ .result(answer["check_result"]))
120
139
  end
121
140
 
141
+ # The first line on each side of the change that the other lacks, which the request hints the quotes from.
142
+ #: (MemberLines) -> Hash[String, String]
143
+ def first_changed_lines(lines) = quoted_change(lines).first_changed_lines
144
+
122
145
  private
123
146
 
124
- # The ids of the findings the last audit left open on this member with action.
147
+ # result, once its check exited 0. It always gives an exit status, since the answer's schema refuses
148
+ # not_run_reason (#1115).
149
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
150
+ def passed(result)
151
+ status = result.fetch("exit_status")
152
+ return result if status.zero?
153
+
154
+ refuse("its check `#{result.fetch("command")}` exited #{status}, so a full audit judges it")
155
+ end
156
+
157
+ # The change the answer quotes, between the member's lines at the baseline and now.
158
+ #: (MemberLines) -> QuotedChange
159
+ def quoted_change(lines) = QuotedChange.new(lines, member_id: @member.id)
160
+
161
+ # The ids of the findings the last audit left open on this member with action, found by key, so a member moved
162
+ # since keeps its findings (#547).
125
163
  #: (String) -> Array[String]
126
164
  def findings_on_member(action)
127
- acknowledgeable.open_findings
128
- .select { |finding| finding.fetch("action") == action }
129
- .select { |finding| finding.fetch("member_ids").any? { |id| on_member?(id) } }
130
- .map { |finding| finding.fetch("finding_id") }
165
+ acknowledgeable.left_open.select { |finding| finding.action == action && finding.on?(@member.key) }.map(&:id)
131
166
  end
132
167
 
133
- # Whether the record's id names this member, by key, so a member moved since keeps its findings (#547).
134
- #: (String) -> bool
135
- def on_member?(id) = acknowledgeable.members.key_of(id) == @member.key
136
-
137
168
  # The completed record, once the member can be acknowledged.
138
169
  #: () -> AuditRecord
139
170
  def acknowledgeable
140
171
  refuse("an acknowledgement is judged against committed text, so it needs git") unless @base
141
172
  record = @record or no_completed_audit
142
- refused_for(record.acknowledgement_refusal(@member, now_sha256: @now_sha256))
173
+ AcknowledgementRefusal.of(record, @member, now_sha256: @now_sha256)&.raise!
143
174
  record
144
175
  end
145
176
 
146
- # Raises the refusal the record gives for this member, if any.
147
- #: (Symbol?) -> void
148
- def refused_for(reason)
149
- case reason
150
- when :not_completed then no_completed_audit
151
- when :not_assessed then refuse("no completed audit assessed #{@member.id}")
152
- when :unchanged then nothing_to_acknowledge
153
- when :checked then refuse("#{@member.id} has a check, and acknowledging a checked member is not built yet")
154
- when nil then nil
155
- else raise ArgumentError, "unknown acknowledgement refusal #{reason}"
156
- end
157
- end
158
-
159
- #: (untyped, Array[String], Array[String]) -> void
160
- def checked(answer, before, now)
177
+ #: (untyped, MemberLines) -> void
178
+ def checked(answer, lines)
161
179
  refuse("the answer says the change does not keep #{@member.id}'s meaning") unless answer["meaning_kept"] == true
162
180
  reason = answer.fetch("reason").to_s
163
181
  refuse("the reason must be one line") if reason.include?("\n")
164
- then_side = SideOfTheChange.new(before, "before the change")
165
- now_side = SideOfTheChange.new(now, "at HEAD")
166
- quoted(answer.fetch("old_line"), then_side, now_side)
167
- quoted(answer.fetch("new_line"), now_side, then_side)
168
- end
169
-
170
- # A quote is a whole line of this side, or a fragment long enough to show the edit that only this side reads.
171
- #: (String, SideOfTheChange, SideOfTheChange) -> void
172
- def quoted(line, side, other)
173
- return if side.whole_line?(line) || (line.length >= FRAGMENT_LENGTH && side.holds?(line) && !other.holds?(line))
174
-
175
- raise Error.new("quote_not_found", "#{line.inspect} is not a line of #{@member.id} #{side.reads_at}",
176
- "Quote a whole line of the member as it reads #{side.reads_at}, or at least " \
177
- "#{FRAGMENT_LENGTH} characters of one that the member #{other.reads_at} does not hold, " \
178
- "from the change the request names.")
182
+ quoted_change(lines).check(old_line: answer.fetch("old_line"), new_line: answer.fetch("new_line"))
179
183
  end
180
184
 
181
- #: () -> bot
182
- def no_completed_audit = refuse("#{@principle_id} has no completed audit, so no baseline has been judged")
185
+ #: (String) -> bot
186
+ def refuse(why) = AcknowledgementRefusal.new(@member, @principle_id).refuse(why)
183
187
 
184
- # A member whose text is the one last judged, as after a pure move, needs nothing: not an acknowledgement, and
185
- # not the full audit the other refusals send the agent to (#553).
186
188
  #: () -> bot
187
- def nothing_to_acknowledge
188
- raise Error.new("cannot_acknowledge",
189
- "#{@member.id}'s text is the one last judged, so there is nothing to acknowledge",
190
- "Nothing needs doing.")
191
- .ending_with([Error::RepairCommand.new(purpose: "After a committed edit changes it, acknowledge it",
192
- command: "start-audit", values: [@principle_id],
193
- options: ["--member", @member.id])])
194
- end
195
-
196
- #: (String) -> bot
197
- def refuse(why)
198
- raise Error.new("cannot_acknowledge", "#{@member.id} cannot be acknowledged: #{why}",
199
- "For a full audit instead: #{Error::EXECUTABLE} start-audit #{@principle_id}")
200
- end
189
+ def no_completed_audit = AcknowledgementRefusal.new(@member, @principle_id, :not_completed).raise!
201
190
  end
202
191
  end
203
192
  end
@@ -0,0 +1,90 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "member"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # Why a one-member audit cannot judge a member's change (D33), as the audit record finds it: each sends the agent
11
+ # to the full audit, but a member whose text is the one last judged needs nothing at all (#553).
12
+ class AcknowledgementRefusal
13
+ # Why a one-member audit cannot judge member's change against record, or nil when it can (D33): the record must
14
+ # be completed and have assessed the member, the member's text must differ from the one it assessed, its check
15
+ # must be the one the record ran, so none new, changed, removed or last not run escapes a full audit's review
16
+ # (D33, #1071). The one owner of these preconditions, which
17
+ # list-member-problems asks before offering the audit that Acknowledgement refuses by them (#626, #632); git is
18
+ # the callers' to know.
19
+ #: (AuditRecord, Member, now_sha256: String?) -> AcknowledgementRefusal?
20
+ def self.of(record, member, now_sha256:)
21
+ members = record.members
22
+ recorded = members.hash_for(member.key)
23
+ check = members.check_since(member.key, member.check)
24
+ reason = if !record.completed? then :not_completed
25
+ elsif !recorded then :not_assessed
26
+ elsif recorded == now_sha256 then :unchanged
27
+ elsif check != :unchanged then check
28
+ end
29
+ new(member, record.principle_id, reason, ran: members.check_run_for(member.key)) if reason
30
+ end
31
+
32
+ # principle_id is the member's principle, whose full audit each refusal names. reason, which raise! raises, is
33
+ # :not_completed, :not_assessed, :unchanged, or how the member's check stands to the one the record
34
+ # ran, as RecordedMembers#check_since says; ran is the command that record ran, if any. Without a reason it
35
+ # only refuses for a reason its caller states.
36
+ #: (Member, String, ?Symbol?, ?ran: String?) -> void
37
+ def initialize(member, principle_id, reason = nil, ran: nil)
38
+ @reason = reason
39
+ @member = member
40
+ @principle_id = principle_id
41
+ @ran = ran
42
+ freeze
43
+ end
44
+
45
+ # Refuses the member's acknowledgement for why, sending the agent to its principle's full audit instead.
46
+ #: (String) -> bot
47
+ def refuse(why)
48
+ raise Error.new("cannot_acknowledge", "#{@member.id} cannot be acknowledged: #{why}",
49
+ "For a full audit instead: #{Error::EXECUTABLE} start-audit #{@principle_id}")
50
+ end
51
+
52
+ # Raises it.
53
+ #: () -> bot
54
+ def raise!
55
+ case @reason
56
+ when :unchanged then nothing_to_acknowledge
57
+ when :not_completed then refuse("#{@principle_id} has no completed audit, so no baseline has been judged")
58
+ when :not_assessed then refuse("no completed audit assessed #{@member.id}")
59
+ else refuse("#{check_since_record}, so a full audit reviews it")
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ # How the member's check stands to the one the record ran, which a full audit reviews before it runs (#1071).
66
+ #: () -> String
67
+ def check_since_record
68
+ case @reason
69
+ when :removed then "its check was removed since the last completed audit ran `#{@ran}`"
70
+ when :changed then "its check `#{@member.check}` changed since the last completed audit ran `#{@ran}`"
71
+ when :not_run then "the last completed audit reported its check `#{@member.check}` not run"
72
+ when :new then "its check `#{@member.check}` is new since the last completed audit"
73
+ else raise ArgumentError, "unknown acknowledgement refusal #{@reason}"
74
+ end
75
+ end
76
+
77
+ # A member whose text is the one last judged, as after a pure move, needs nothing: not an acknowledgement, and
78
+ # not the full audit the other refusals send the agent to (#553).
79
+ #: () -> bot
80
+ def nothing_to_acknowledge
81
+ raise Error.new("cannot_acknowledge",
82
+ "#{@member.id}'s text is the one last judged, so there is nothing to acknowledge",
83
+ "Nothing needs doing.")
84
+ .ending_with([Error::RepairCommand.new(purpose: "After a committed edit changes it, acknowledge it",
85
+ command: "start-audit", values: [@principle_id],
86
+ options: ["--member", @member.id])])
87
+ end
88
+ end
89
+ end
90
+ end
@@ -20,6 +20,10 @@ module Principles
20
20
  #: String
21
21
  attr_reader :subject
22
22
 
23
+ # The place of the member assessment at index in an answer, which names the member it assesses.
24
+ #: (Integer, untyped) -> AnswerPlace
25
+ def self.member_assessment(index, member_id) = new("/member_assessments/#{index}", "Member #{member_id}")
26
+
23
27
  #: (String, String) -> void
24
28
  def initialize(pointer, subject)
25
29
  @pointer = pointer