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
@@ -0,0 +1,90 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "answer_fields"
6
+ require_relative "answer_place"
7
+ require_relative "template_placeholders"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # The recent decision under a principle an assessment answer judges against its members' own words: either why
13
+ # none can be checked, or how one held up with pointers to where it is recorded. The record keeps none of it,
14
+ # but a completed audit asks to commit the files its evidence cites (#860).
15
+ class RecentDecision
16
+ # The placeholder start-audit --as template prints in each field of both forms, so the agent fills one form
17
+ # and leaves the other as printed, which is not giving it (#994).
18
+ PLACEHOLDERS = TemplatePlaceholders.new(
19
+ {
20
+ "unavailable_reason" => "Why no recent decision under this principle can be checked. Leave as printed " \
21
+ "to check one in assessment and evidence instead",
22
+ "assessment" => "To check a recent decision: how it held up against the members' own words. Leave as " \
23
+ "printed when unavailable_reason says why none can be checked",
24
+ "evidence" => "With assessment: pointers to where the decision is recorded, as [{\"path\": ..., " \
25
+ "\"heading\": ...}]. Leave as printed otherwise"
26
+ }
27
+ ) #: TemplatePlaceholders
28
+
29
+ # decision is the answer's recent_decision as given; each field left as its placeholder is not given.
30
+ #: (Hash[String, untyped]) -> void
31
+ def initialize(decision)
32
+ @sent_any = !decision.empty? #: bool
33
+ @decision = PLACEHOLDERS.given(decision) #: Hash[String, untyped]
34
+ freeze
35
+ end
36
+
37
+ # Whether the decision as sent gives fields and leaves every one as the template printed it, so gives neither
38
+ # form (#1010).
39
+ #: () -> bool
40
+ def left_as_printed? = @sent_any && @decision.empty?
41
+
42
+ # Refuses the decision unless it gives a written reason none is available, or a written assessment with
43
+ # evidence that fields locates, and one giving neither form, or both, by naming both.
44
+ #: (AnswerFields) -> void
45
+ def check(fields)
46
+ one_form
47
+ if @decision["unavailable_reason"]
48
+ fields.text(@decision["unavailable_reason"], "recent_decision.unavailable_reason")
49
+ else
50
+ fields.text(@decision["assessment"], "recent_decision.assessment")
51
+ fields.evidence(@decision["evidence"], AnswerPlace.new("/recent_decision/evidence", "Recent decision"))
52
+ end
53
+ end
54
+
55
+ # The paths its evidence cites, each once; none when the decision was unavailable.
56
+ #: () -> Array[String]
57
+ def paths
58
+ return [] if @decision["unavailable_reason"]
59
+
60
+ @decision.fetch("evidence").map { |item| item.fetch("path") }.uniq
61
+ end
62
+
63
+ private
64
+
65
+ # Refuses a decision that gives neither form, or both, whichever its fields show.
66
+ #: () -> void
67
+ def one_form
68
+ given = %w[unavailable_reason assessment].count { |field| @decision.key?(field) }
69
+ return if given == 1
70
+
71
+ given.zero? ? neither : both
72
+ end
73
+
74
+ #: () -> bot
75
+ def both
76
+ raise Error.new("invalid_answer", "recent_decision gives both unavailable_reason and assessment",
77
+ "Keep one form: to check a decision, leave unavailable_reason as printed or remove it; when " \
78
+ "none can be checked, do the same with assessment and evidence.")
79
+ end
80
+
81
+ #: () -> bot
82
+ def neither
83
+ raise Error.new("invalid_answer", "recent_decision gives neither unavailable_reason nor assessment",
84
+ "Replace unavailable_reason's placeholder with why no recent decision under this principle " \
85
+ "can be checked, or replace assessment's and evidence's with how one held up and where it " \
86
+ "is recorded.")
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,109 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require_relative "../error"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # An audit record's format: the number a copy compares with the newest it writes and rewrites without losing a
11
+ # field, and the first release that wrote it, which a copy that does not know the format names as the update to
12
+ # make (D85). A record without a format is older than format 1. An open record outside git keeps the last
13
+ # completed one whole, so that one's format counts too.
14
+ class RecordFormat
15
+ # The refusal of a record a later copy wrote at a format this copy cannot rewrite or read, which a read across
16
+ # principles, or one comparing members, catches by its kind rather than its code (D85, #1077).
17
+ class NewerFormatError < Error; end
18
+
19
+ # Raise NEWEST in the commit that adds a field an older copy would drop on a rewrite, and set FIRST_RELEASE by
20
+ # hand to the release that commit ships in.
21
+ NEWEST = 1
22
+ FIRST_RELEASE = "0.0.4"
23
+ FIELDS = %w[format format_first_release].freeze
24
+
25
+ #: (Hash[String, untyped]) -> void
26
+ def initialize(fields)
27
+ @fields = fields
28
+ freeze
29
+ end
30
+
31
+ # The record's fields as this copy writes them, its format and that format's first release ahead of the rest.
32
+ #: () -> Hash[String, untyped]
33
+ def stamped
34
+ { "format" => NEWEST, "format_first_release" => FIRST_RELEASE, **@fields.except(*FIELDS) }
35
+ end
36
+
37
+ # Refuses a record whose format, or its kept last completed record's, is above NEWEST, before this copy, at
38
+ # version, rewrites it and drops what it does not know. file is the record's, relative to the project.
39
+ #: (String, version: String) -> void
40
+ def refuse_rewrite(file, version:)
41
+ format, release = newest_held
42
+ return unless format > NEWEST
43
+
44
+ refuse(file, "#{format}, first written by release #{release}; this copy, #{version}, rewrites up to " \
45
+ "format #{NEWEST}", update(release, version))
46
+ end
47
+
48
+ # Refuses a record this copy's schema refused, when a later copy wrote it, so it is not reported as invalid.
49
+ # A read holds no version, so the repair names both ways to update (V3).
50
+ #: (String) -> void
51
+ def refuse_unreadable(file)
52
+ return unless newer?
53
+
54
+ refuse(file, "#{number}, first written by release #{first_release}; this copy reads up to format #{NEWEST}",
55
+ "#{update_either_way}, then run the command again.")
56
+ end
57
+
58
+ # Whether a later copy wrote the record, at a format above NEWEST.
59
+ #: () -> bool
60
+ def newer? = number > NEWEST
61
+
62
+ # The highest format the record holds, its own or its kept last completed record's; 0 for none.
63
+ #: () -> Integer
64
+ def number = newest_held.first
65
+
66
+ # The first release that wrote that format.
67
+ #: () -> String
68
+ def first_release = newest_held.last
69
+
70
+ # How to update to read the record, whatever copy runs: what a read without the running version says (V3, V5).
71
+ #: () -> String
72
+ def update_either_way
73
+ "Update the principles plugin or gem to #{first_release} or later, or a checkout or archive of principles " \
74
+ "to a later commit"
75
+ end
76
+
77
+ private
78
+
79
+ #: (String, String, String) -> bot
80
+ def refuse(file, format_stated, update)
81
+ raise NewerFormatError.new("newer_audit_record", "#{file} is format #{format_stated}",
82
+ "#{update} Leave the record as it is: it is not broken.", file)
83
+ end
84
+
85
+ # The highest format the record holds, with the release that first wrote it.
86
+ #: () -> [Integer, String]
87
+ def newest_held
88
+ kept = @fields["last_completed"]
89
+ [@fields, kept.is_a?(Hash) ? kept : {}].map do |fields|
90
+ [fields["format"].is_a?(Integer) ? fields["format"] : 0, fields["format_first_release"].to_s]
91
+ end.max_by(&:first) || [0, ""]
92
+ end
93
+
94
+ # What to update to read release's format: a published copy to that release, a development one, whose
95
+ # version is a prerelease, to a later commit; and a release above this copy's own may not be published yet.
96
+ #: (String, String) -> String
97
+ def update(release, version)
98
+ running = Gem::Version.new(version)
99
+ unpublished = Gem::Version.correct?(release) && Gem::Version.new(release) > running.release
100
+ how = if running.prerelease?
101
+ "Update this checkout or archive of principles to a later commit, then run the command again."
102
+ else
103
+ "Update the principles plugin or gem to #{release} or later, then run the command again."
104
+ end
105
+ unpublished ? "#{how} #{release} may not be published yet." : how
106
+ end
107
+ end
108
+ end
109
+ end
@@ -16,6 +16,12 @@ module Principles
16
16
  freeze
17
17
  end
18
18
 
19
+ # The key the record knows the member by: the key kept beside its entry when it differs from the id it was
20
+ # filed under, else that id. The one owner of that rule, which MemberHashesAsWritten reads a newer record by
21
+ # too (#1066).
22
+ #: () -> String
23
+ def key = @entry["key"] || @filed_id
24
+
19
25
  # The assessment the audit kept, with when it was made and what it was judged on; nil when it kept none.
20
26
  #: () -> Hash[String, untyped]?
21
27
  def assessment = @entry["assessment"]
@@ -34,6 +34,10 @@ module Principles
34
34
  #: () -> String?
35
35
  def action = @fields["action"]
36
36
 
37
+ # Why its audit left it unfixed, or nil when it was fixed or its record predates keeping the reason (#996).
38
+ #: () -> String?
39
+ def reason = @fields["reason"]
40
+
37
41
  # Where its write-up is, or nil when it was never written up.
38
42
  #: () -> WriteUpPointer?
39
43
  def recorded_at
@@ -0,0 +1,43 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # The member hashes a principle's audit record holds, by key, which its members now are compared with, and
8
+ # whether a later copy wrote that record, so its audits wait on an upgrade and the comparison is read-only
9
+ # (D85, V8, #1066, #1067). A principle with no record holds none.
10
+ class RecordedHashes
11
+ #: (Hash[String, String], ?waiting: bool) -> void
12
+ def initialize(by_key, waiting: false)
13
+ @by_key = by_key.freeze #: Hash[String, String]
14
+ @waiting = waiting #: bool
15
+ freeze
16
+ end
17
+
18
+ # The hash the record holds for the member known by key, or nil when it holds none.
19
+ #: (String) -> String?
20
+ def hash_for(key) = @by_key[key]
21
+
22
+ # Whether the record holds no hash, as for a principle with no record.
23
+ #: () -> bool
24
+ def empty? = @by_key.empty?
25
+
26
+ # Whether a later copy wrote the record these hashes come from.
27
+ #: () -> bool
28
+ def waiting? = @waiting
29
+
30
+ # Whether the member known by key, whose hash is now sha, has the text the record assessed: current or changed,
31
+ # and unassessed when the record holds no hash for it.
32
+ #: (String, String) -> String
33
+ def freshness(key, sha)
34
+ recorded = @by_key[key]
35
+ return "unassessed" unless recorded
36
+
37
+ recorded == sha ? "current" : "changed"
38
+ end
39
+
40
+ NONE = new({}) #: RecordedHashes
41
+ end
42
+ end
43
+ end
@@ -4,6 +4,7 @@
4
4
  require_relative "accepted_loading"
5
5
  require_relative "member"
6
6
  require_relative "recorded_entry"
7
+ require_relative "recorded_hashes"
7
8
 
8
9
  module Principles
9
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -40,17 +41,16 @@ module Principles
40
41
 
41
42
  # Whether the text of the member known by key, whose hash is now sha, is the text the record assessed.
42
43
  #: (String, String) -> String
43
- def freshness(key, sha)
44
- recorded = hash_for(key)
45
- return "unassessed" unless recorded
44
+ def freshness(key, sha) = hashes.freshness(key, sha)
46
45
 
47
- recorded == sha ? "current" : "changed"
48
- end
46
+ # The hashes the record assessed, which a member now is compared with.
47
+ #: () -> RecordedHashes
48
+ def hashes = RecordedHashes.new(hashes_by_key)
49
49
 
50
50
  # Each hash the record assessed, by the key of the member it belongs to.
51
51
  #: () -> Hash[String, String]
52
52
  def hashes_by_key
53
- @entries.to_h { |id, entry| [entry["key"] || id, entry.fetch("sha256")] }
53
+ @entries.to_h { |id, entry| [RecordedEntry.new(id, entry).key, entry.fetch("sha256")] }
54
54
  end
55
55
 
56
56
  # The hash the record assessed for the member known by key, or nil when it assessed no such member.
@@ -67,6 +67,21 @@ module Principles
67
67
  result.key?("exit_status") ? result.fetch("command") : nil
68
68
  end
69
69
 
70
+ # How check, the map's check now for the member known by key, stands to the one the record's audit ran:
71
+ # :unchanged when it ran this same command, or none for a member that has none; :removed when it ran one the
72
+ # member no longer has; :changed when it ran another; :not_run when it was told this one could not be run; :new
73
+ # when it reported none (D30, D63, #1071). The one owner of that comparison, which a full audit's template and a
74
+ # one-member audit both ask.
75
+ #: (String, String?) -> Symbol
76
+ def check_since(key, check)
77
+ ran = check_run_for(key)
78
+ return :unchanged if ran == check
79
+ return :removed unless check
80
+ return :changed if ran
81
+
82
+ entry_for(key)&.dig("check_result", "command") == check ? :not_run : :new
83
+ end
84
+
70
85
  # What the review of that run rested on, for the member known by key, as the record keeps it: its review_basis
71
86
  # and any review_basis_since, or nothing when the record ran no check for it or kept no line (D63).
72
87
  #: (String) -> Hash[String, untyped]
@@ -77,7 +92,7 @@ module Principles
77
92
  end
78
93
 
79
94
  # Each member's accepted loading decision, by its id now, found by the key it keeps through moves (#502).
80
- #: (MapMembers) -> Hash[String, AcceptedLoading]
95
+ #: (PrincipleMembers) -> Hash[String, AcceptedLoading]
81
96
  def loading_accepted(members)
82
97
  members.to_h do |member|
83
98
  entry = entry_for(member.key)
@@ -101,13 +116,15 @@ module Principles
101
116
  end.max_by(&:last)
102
117
  end
103
118
 
104
- # These entries with the member known by key moved to change's to_sha256, and change kept beside it (D33).
105
- #: (String, Hash[String, untyped]) -> RecordedMembers
106
- def acknowledged(key, change)
119
+ # These entries with the member known by key moved to change's to_sha256, and change kept beside it (D33), with
120
+ # check_result, when given, in place of the result it kept (#1071).
121
+ #: (String, Hash[String, untyped], ?check_result: Hash[String, untyped]?) -> RecordedMembers
122
+ def acknowledged(key, change, check_result: nil)
107
123
  RecordedMembers.new(@entries.to_h do |id, entry|
108
- next [id, entry] unless (entry["key"] || id) == key
124
+ next [id, entry] unless RecordedEntry.new(id, entry).key == key
109
125
 
110
- [id, entry.merge("sha256" => change.fetch("to_sha256"),
126
+ result = check_result ? { "check_result" => check_result } : {}
127
+ [id, entry.merge("sha256" => change.fetch("to_sha256"), **result,
111
128
  "acknowledgements" => [*entry["acknowledgements"], change])]
112
129
  end)
113
130
  end
@@ -115,13 +132,13 @@ module Principles
115
132
  # The key of the member filed under id: its stored key when it had moved, or else id.
116
133
  #: (String) -> String
117
134
  def key_of(id)
118
- @entries.dig(id, "key") || id
135
+ RecordedEntry.new(id, @entries.fetch(id, {})).key
119
136
  end
120
137
 
121
138
  # The entry of the member known by key, under the id it was filed under, or nil when the record has none.
122
139
  #: (String) -> RecordedEntry?
123
140
  def recorded(key)
124
- id, entry = @entries.find { |filed, each| (each["key"] || filed) == key }
141
+ id, entry = @entries.find { |filed, each| RecordedEntry.new(filed, each).key == key }
125
142
  RecordedEntry.new(id, entry) if id && entry
126
143
  end
127
144
 
@@ -132,7 +149,7 @@ module Principles
132
149
  RecordedMembers.new(@entries.to_h do |id, entry|
133
150
  next [id, entry] unless entry.dig("assessment", "carried_forward")
134
151
 
135
- [id, entry.merge("assessment" => last&.recorded(entry["key"] || id)&.assessment).compact]
152
+ [id, entry.merge("assessment" => last&.recorded(RecordedEntry.new(id, entry).key)&.assessment).compact]
136
153
  end)
137
154
  end
138
155
 
@@ -142,7 +159,7 @@ module Principles
142
159
  # two differ.
143
160
  #: (String) -> Hash[String, untyped]?
144
161
  def entry_for(key)
145
- @entries.find { |id, entry| (entry["key"] || id) == key }&.last
162
+ @entries.find { |id, entry| RecordedEntry.new(id, entry).key == key }&.last
146
163
  end
147
164
  end
148
165
  end
@@ -0,0 +1,21 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # A refusal an answer meets before its shape is checked, for a mistake the shape would refuse without naming, such
8
+ # as a placeholder left in a field of another type (#773, #1084, #1088). A phase lists its own, in order, and
9
+ # SentAnswer reads each, so a new one is declared here once.
10
+ # @interface
11
+ module RefusalBeforeShape
12
+ # Refuses answer, as sent from source, when it makes this mistake; nothing otherwise. shape_problems are the
13
+ # problems its shape check finds, as Data::SchemaCheck#problems gives them, which a refusal may name beside its
14
+ # own, so one refusal names every repair (#1106). Sorbet takes an abstract method only with a forwarding super
15
+ # for its body, which RuboCop would otherwise call useless.
16
+ # @abstract
17
+ #: (untyped, String, Array[Hash[String, String]]) -> void
18
+ def refuse_in(answer, source, shape_problems) = super # rubocop:disable Lint/UselessMethodDefinition
19
+ end
20
+ end
21
+ end
@@ -5,6 +5,8 @@ require_relative "../error"
5
5
  require_relative "answer_fields"
6
6
  require_relative "answer_place"
7
7
  require_relative "audit_record"
8
+ require_relative "audit_records"
9
+ require_relative "last_completed_revision"
8
10
  require_relative "project_history"
9
11
  require_relative "request_id"
10
12
  require_relative "write_up_repoint"
@@ -48,6 +50,17 @@ module Principles
48
50
  completed.repointed(given.map { |repoint, index| located(repoint, index, fields) }, at: at)
49
51
  end
50
52
 
53
+ # The record accepted from the answer, as accepted gives it, and the records it changes among records, not yet
54
+ # written: refused once the record changed after the request, whose revision the answer quotes back in its basis,
55
+ # was printed, unless it changes none.
56
+ #: (untyped, records: AuditRecords, at: String) { (Locator) -> void } -> [AuditRecord, Array[AuditRecord]]
57
+ def writable(response, records:, at:, &locate)
58
+ repointed = accepted(response, at:, &locate)
59
+ changes = records.changes(repointed)
60
+ LastCompletedRevision.new(response.dig("basis", "revision")).confirm_writable(@principle_id, @record, changes)
61
+ [repointed, changes]
62
+ end
63
+
51
64
  # The ids of the completed record's open findings that repointed, the record accepted, points elsewhere (T16).
52
65
  #: (AuditRecord) -> Array[String]
53
66
  def moved_ids(repointed) = repointed.write_ups_moved_since(completed)
@@ -5,6 +5,7 @@ require_relative "../error"
5
5
  require_relative "answer_place"
6
6
  require_relative "answer_text"
7
7
  require_relative "dated_line"
8
+ require_relative "template_placeholders"
8
9
 
9
10
  module Principles
10
11
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -13,18 +14,44 @@ module Principles
13
14
  # refuses a report that cannot be about the member's own check, and cannot confirm the run happened.
14
15
  class ReportedCheck
15
16
  SHAPES = "Give check_result as answer_guide.check_result shows."
17
+ # How review_basis records a review the agent made itself, which the placeholder and the repair both give.
18
+ SELF_REVIEWED = "\"Self-reviewed by the agent: <what you checked it against>\"" #: String
19
+ # The not_run_reason a template prints beside exit_status's placeholder, which an answer that leaves it as
20
+ # printed has not given, so filling exit_status alone reports a run (#993).
21
+ NOT_RUN_PLACEHOLDER = "Only if the command could not be run here: why, such as a missing tool or a sandbox. " \
22
+ "Leave this as printed once exit_status gives the run's status" #: String
23
+ # The review_basis a template prints for a check no audit ran, or one changed since, which an exit_status needs
24
+ # beside it, and which beside not_run_reason left as printed is not given (D63, #993).
25
+ REVIEW_BASIS_PLACEHOLDER = "One line saying what the review before the run rested on, such as who reviewed " \
26
+ "it or the document that confirms it; for your own review, #{SELF_REVIEWED}. " \
27
+ "Leave this as printed only beside not_run_reason".freeze #: String
28
+ # Why an exit status for a check no audit ran is refused without review_basis, and when given its placeholder.
29
+ NEEDS_BASIS = "check_result needs review_basis beside exit_status, since no audit ran this command" #: String
30
+ LEFT_BASIS = "check_result.review_basis is the template's placeholder, unchanged, and an exit_status for a " \
31
+ "command no audit ran needs it" #: String
32
+ # The placeholder a template prints in each field an answer may leave as printed to give none.
33
+ PLACEHOLDERS = TemplatePlaceholders.new({ "not_run_reason" => NOT_RUN_PLACEHOLDER,
34
+ "review_basis" => REVIEW_BASIS_PLACEHOLDER }) #: TemplatePlaceholders
35
+ # The review_basis a template prints for a check the last audit ran, which left as printed keeps the line that
36
+ # audit kept, and replaced gives a new one (#1010).
37
+ KEPT_BASIS_PLACEHOLDER = "Only to give a new line for what this run's review rested on; leave this as " \
38
+ "printed to keep the line the last audit kept, if any" #: String
39
+ # The placeholders a template prints for a check the last audit ran.
40
+ UNCHANGED_PLACEHOLDERS = TemplatePlaceholders.new(
41
+ { "not_run_reason" => NOT_RUN_PLACEHOLDER, "review_basis" => KEPT_BASIS_PLACEHOLDER }
42
+ ) #: TemplatePlaceholders
16
43
  BASIS = "Say in review_basis, in one line, what the review before the run rested on, such as " \
17
44
  "\"The owner reviewed the command in this session.\" or the document that confirms it. If you did " \
18
45
  "the review yourself, such as confirming against the documentation a check you changed, say so: " \
19
- "\"Self-reviewed by the agent: <what you checked it against>\". If no record of the review was " \
20
- "kept, say so, such as \"Reviewed in an earlier session; basis not kept.\"" #: String
46
+ "#{SELF_REVIEWED}. If no record of the review was " \
47
+ "kept, say so, such as \"Reviewed in an earlier session; basis not kept.\"".freeze #: String
21
48
 
22
49
  # assessment is the place of the member's assessment in the answer, whose check_result each refusal points
23
50
  # into (#817). ran is the command the principle's stored record was given an exit status for, nil when it ran
24
51
  # none; a check it did not run is reviewed before it runs, and the result says in review_basis what that review
25
52
  # rested on (D63). kept is the line the stored record keeps for that run's review, with its
26
53
  # review_basis_since, which an unchanged check's result carries until the answer gives another (D52).
27
- #: (AnswerPlace, String?, ran: String?, kept: Hash[String, untyped]) -> void
54
+ #: (AnswerPlace, String, ran: String?, kept: Hash[String, untyped]) -> void
28
55
  def initialize(assessment, check, ran:, kept:)
29
56
  @assessment = assessment
30
57
  @check = check
@@ -33,20 +60,32 @@ module Principles
33
60
  freeze
34
61
  end
35
62
 
36
- # The reported result, once it is checked against the member's check; nil when it has none.
37
- #: (untyped) -> Hash[String, untyped]?
63
+ # The reported result, once it is checked against the member's check.
64
+ #: (untyped) -> Hash[String, untyped]
38
65
  def result(reported)
39
- return no_check(reported) unless @check
40
-
41
66
  missing_result unless reported
42
- same_command(reported.fetch("command"))
43
- status_or_reason(reported)
44
- review_basis(reported)
45
- carrying_review(reported)
67
+ given = filled(reported)
68
+ same_command(given.fetch("command"))
69
+ unfilled_status(reported, given)
70
+ status_or_reason(given)
71
+ review_basis(given, left: placeholders.left?("review_basis", reported["review_basis"]))
72
+ carrying_review(given)
46
73
  end
47
74
 
48
75
  private
49
76
 
77
+ # The fields reported gives, leaving out those the template left as printed: an exit_status still the
78
+ # placeholder string that says how to run the check, and each field as its placeholder (#993).
79
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
80
+ def filled(reported)
81
+ placeholders.given(reported).reject { |field, value| field == "exit_status" && value.is_a?(String) }
82
+ end
83
+
84
+ # The placeholders the template printed for this check: for one the stored record ran, a review_basis that
85
+ # left as printed keeps its line; for any other, one an exit_status needs replaced (#1010).
86
+ #: () -> TemplatePlaceholders
87
+ def placeholders = @ran == @check ? UNCHANGED_PLACEHOLDERS : PLACEHOLDERS
88
+
50
89
  # The place of the reported check_result, or of one of its fields.
51
90
  #: (?String?) -> AnswerPlace
52
91
  def reported_at(field = nil)
@@ -64,14 +103,6 @@ module Principles
64
103
  "answer_guide.check_result.limits asks for one. #{SHAPES}")
65
104
  end
66
105
 
67
- #: (untyped) -> nil
68
- def no_check(reported)
69
- return unless reported
70
-
71
- refuse(reported_at, "the member has no check, so its assessment takes no check_result",
72
- "Remove check_result from this member's assessment.")
73
- end
74
-
75
106
  #: (String) -> void
76
107
  def same_command(command)
77
108
  return if command == @check
@@ -81,6 +112,17 @@ module Principles
81
112
  "answer_guide.check_result.limits asks for one.")
82
113
  end
83
114
 
115
+ # Refuses a result that gives neither field but text in exit_status: the template's placeholder, or other text
116
+ # written where only the status goes, so the repair says what replaces it (#993).
117
+ #: (Hash[String, untyped], Hash[String, untyped]) -> void
118
+ def unfilled_status(reported, given)
119
+ return if given.key?("exit_status") || given.key?("not_run_reason") || !reported["exit_status"].is_a?(String)
120
+
121
+ refuse(reported_at("exit_status"), "check_result.exit_status is text, not the command's exit status",
122
+ "Replace exit_status, which the template prints as text to replace, with the exit status as an " \
123
+ "integer once the command has run, or write why it could not run in not_run_reason.")
124
+ end
125
+
84
126
  #: (Hash[String, untyped]) -> void
85
127
  def status_or_reason(reported)
86
128
  unless reported.key?("exit_status") ^ reported.key?("not_run_reason")
@@ -96,9 +138,10 @@ module Principles
96
138
 
97
139
  # Refuses an exit status for a check the stored record did not run unless review_basis says what its review
98
140
  # rested on, and any review_basis that is not one written line. What the line says is the agent's: this tool
99
- # keeps it and cannot verify it.
100
- #: (Hash[String, untyped]) -> void
101
- def review_basis(reported)
141
+ # keeps it and cannot verify it. left says the template's placeholder was sent back in it, which the refusal
142
+ # names (#993).
143
+ #: (Hash[String, untyped], left: bool) -> void
144
+ def review_basis(reported, left:)
102
145
  if reported.key?("review_basis")
103
146
  return if AnswerText.new(reported["review_basis"]).one_line?
104
147
 
@@ -106,8 +149,7 @@ module Principles
106
149
  end
107
150
  return unless reported.key?("exit_status") && @ran != @check
108
151
 
109
- refuse(reported_at("review_basis"),
110
- "check_result needs review_basis beside exit_status, since no audit ran this command", BASIS)
152
+ refuse(reported_at("review_basis"), left ? LEFT_BASIS : NEEDS_BASIS, BASIS)
111
153
  end
112
154
 
113
155
  # The result as the record keeps it: an unchanged check's exit status with the kept line and its date when the
@@ -1,9 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "digest"
5
- require "json"
6
4
  require_relative "../error"
5
+ require_relative "json_digest"
7
6
 
8
7
  module Principles
9
8
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
@@ -21,10 +20,20 @@ module Principles
21
20
  #: String
22
21
  attr_reader :phase
23
22
 
24
- # The id of a request in phase for principle_id, which depends on parts.
23
+ # The id of a request in phase for principle_id, which depends on parts, digested by what they say, so an answer
24
+ # whose keys are reordered, as `jq -S` does, still matches (#1045).
25
25
  #: (principle_id: String, phase: String, parts: Array[untyped]) -> RequestId
26
26
  def self.for(principle_id:, phase:, parts:)
27
- new(principle_id, phase, Digest::SHA256.hexdigest(JSON.generate([principle_id, phase, *parts]))[0, 12].to_s)
27
+ new(principle_id, phase, JsonDigest.new([principle_id, phase, *parts]).to_s[0, 12].to_s)
28
+ end
29
+
30
+ # The id of a request whose answer hands part of it back: its digest's first half digests what is handed back
31
+ # alone and its second the parts this tool recomputes, so an answer that edited what it hands back is told apart
32
+ # from a project that changed (#1045).
33
+ #: (principle_id: String, phase: String, handed: untyped, parts: Array[untyped]) -> RequestId
34
+ def self.handing_back(principle_id:, phase:, handed:, parts:)
35
+ half = ->(digested) { JsonDigest.new([principle_id, phase, digested]).to_s[0, 6].to_s }
36
+ new(principle_id, phase, half.call(handed) + half.call(parts))
28
37
  end
29
38
 
30
39
  # An id as an agent passed it, refused unless it has the shape this tool prints.
@@ -56,6 +65,17 @@ module Principles
56
65
  "Start from the response_template of this request.")
57
66
  end
58
67
 
68
+ # What of a handing_back id differs in other: :handed, what the answer hands back, before :parts, what this tool
69
+ # recomputes, or nil when neither does.
70
+ #: (RequestId) -> Symbol?
71
+ def differs_from(other)
72
+ mine = to_s
73
+ theirs = other.to_s
74
+ return :handed unless mine[0...-6] == theirs[0...-6]
75
+
76
+ :parts unless mine == theirs
77
+ end
78
+
59
79
  #: () -> String
60
80
  def to_s
61
81
  "#{@principle_id}.#{@phase}.#{@digest}"