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
@@ -2,10 +2,14 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
+ require_relative "../prose_list"
5
6
  require_relative "answer_fields"
7
+ require_relative "answer_place"
6
8
  require_relative "loads_to_check"
7
9
  require_relative "member_assessments"
8
10
  require_relative "misspelt_member_id"
11
+ require_relative "new_findings"
12
+ require_relative "recent_decision"
9
13
  require_relative "record_judged_against"
10
14
 
11
15
  module Principles
@@ -18,7 +22,16 @@ module Principles
18
22
  # whose loading it must decide (#355) and the assessments it may carry (D49); answered_at is when it came, which
19
23
  # no sighting it reports is after (#699).
20
24
  class AssessmentAnswer
21
- #: (untyped, MapMembers, answered_at: String, ?judged_against: RecordJudgedAgainst?)
25
+ # The text the template prints in collective_assessment, which an answer may not send back unchanged (#991).
26
+ COLLECTIVE_PLACEHOLDER = "How the members reinforce the principle, and any contradiction or missing " \
27
+ "connection." #: String
28
+ # How a field --as template's answer leaves as printed is read, printed once at the template's head in
29
+ # left_as_printed_rule, where an agent filling it reads, which the answer may send back and this tool ignores
30
+ # (#1043, D88).
31
+ LEFT_AS_PRINTED_RULE = "A field left as printed is read as omitted, as is this one: one saying \"else kept\" " \
32
+ "keeps what it had, and null drops it where offered." #: String
33
+
34
+ #: (untyped, PrincipleMembers, answered_at: String, ?judged_against: RecordJudgedAgainst?)
22
35
  #| { (Locator) -> Hash[String, untyped] } -> void
23
36
  def initialize(response, members, answered_at:, judged_against: nil, &locate)
24
37
  @response = response
@@ -36,7 +49,7 @@ module Principles
36
49
  def findings
37
50
  member_assessments.check
38
51
  @fields.text(@response["collective_assessment"], "collective_assessment")
39
- recent_decision
52
+ recent_decision.check(@fields)
40
53
  checked_findings
41
54
  end
42
55
 
@@ -63,10 +76,7 @@ module Principles
63
76
  # commit when they differ from HEAD (#860); none when the decision was unavailable.
64
77
  #: () -> Array[String]
65
78
  def recent_decision_paths
66
- decision = @response.fetch("recent_decision")
67
- return [] if decision["unavailable_reason"]
68
-
69
- decision.fetch("evidence").map { |item| item.fetch("path") }.uniq
79
+ recent_decision.paths
70
80
  end
71
81
 
72
82
  private
@@ -78,20 +88,12 @@ module Principles
78
88
  answered_at: @answered_at)
79
89
  end
80
90
 
81
- #: () -> void
82
- def recent_decision
83
- decision = @response.fetch("recent_decision")
84
- if decision["unavailable_reason"]
85
- @fields.text(decision["unavailable_reason"], "recent_decision.unavailable_reason")
86
- else
87
- @fields.text(decision["assessment"], "recent_decision.assessment")
88
- @fields.evidence(decision["evidence"], AnswerPlace.new("/recent_decision/evidence", "Recent decision"))
89
- end
90
- end
91
+ #: () -> RecentDecision
92
+ def recent_decision = RecentDecision.new(@response.fetch("recent_decision"))
91
93
 
92
94
  #: () -> Array[untyped]
93
95
  def checked_findings
94
- findings = @fields.array(@response["findings"], "findings")
96
+ findings = NewFindings.new(@fields.array(@response["findings"], "findings")).raised
95
97
  finding_ids = findings.each_with_index.map { |finding, index| finding_id(finding, index) }
96
98
  unless finding_ids.uniq == finding_ids
97
99
  raise Error.new("duplicate_finding", "Finding ids repeat",
@@ -0,0 +1,81 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_place"
5
+ require_relative "left_as_printed"
6
+ require_relative "member_assessments"
7
+ require_relative "new_findings"
8
+ require_relative "recent_decision"
9
+ require_relative "refusal_before_shape"
10
+ require_relative "sent_prior_decisions"
11
+
12
+ module Principles
13
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
14
+ module Models
15
+ # The judgements a full audit's answer, as sent, leaves as its template printed them: the members', the set's,
16
+ # the recent decision's, a raised finding's text fields and a prior finding's decision (#991, #1010, #1040). It
17
+ # reads only what it finds in the shape it expects, so it may read an answer whose shape is still to be checked.
18
+ class AssessmentLeftAsPrinted
19
+ include RefusalBeforeShape
20
+
21
+ # Refuses answer naming each judgement it leaves as printed, then each of shape_problems elsewhere; nothing
22
+ # when it leaves none. source is unused, as other refusals before the shape name it.
23
+ # @override
24
+ #: (untyped, String, Array[Hash[String, String]]) -> void
25
+ def refuse_in(answer, _source, shape_problems)
26
+ of(answer).refuse(besides: shape_problems) if answer.is_a?(Hash)
27
+ end
28
+
29
+ private
30
+
31
+ # Each judgement answer leaves as printed, named, with its pointer.
32
+ #: (Hash[String, untyped]) -> LeftAsPrinted
33
+ def of(answer)
34
+ left = members_left(answer["member_assessments"])
35
+ left["collective_assessment"] = "/collective_assessment" if
36
+ answer["collective_assessment"] == AssessmentAnswer::COLLECTIVE_PLACEHOLDER
37
+ left["recent_decision"] = "/recent_decision" if recent_decision_left?(answer["recent_decision"])
38
+ LeftAsPrinted.new(left.merge(listed_left(answer)))
39
+ end
40
+
41
+ # Each judgement a member's assessment leaves as printed, named by whose it is and what: its assessment, and an
42
+ # observed delivery's observation.
43
+ #: (untyped) -> Hash[String, String]
44
+ def members_left(assessments)
45
+ return {} unless assessments.is_a?(Array)
46
+
47
+ assessments.each_with_index.flat_map do |assessment, index|
48
+ next [] unless assessment.is_a?(Hash)
49
+
50
+ place = AnswerPlace.member_assessment(index, assessment["member_id"])
51
+ unwritten_fields(assessment).map { |field| ["#{place.subject} #{field}", place.child(field).pointer] }
52
+ end.to_h
53
+ end
54
+
55
+ # The fields of assessment, as sent, that are still the text the template printed there and must be written.
56
+ #: (Hash[String, untyped]) -> Array[String]
57
+ def unwritten_fields(assessment)
58
+ [("assessment" if assessment["assessment"] == MemberAssessments::PLACEHOLDER),
59
+ ("observation" if assessment["delivery"] == "observed" &&
60
+ MemberAssessments::SIGHTING.left?("observation", assessment["observation"]))].compact
61
+ end
62
+
63
+ # Each judgement the answer's lists leave as printed: a raised finding's text fields, and a prior finding's
64
+ # decision.
65
+ #: (Hash[String, untyped]) -> Hash[String, String]
66
+ def listed_left(answer)
67
+ findings, decisions = answer.values_at("findings", "prior_finding_decisions")
68
+ { **(NewFindings.new(findings).left_as_printed if findings.is_a?(Array)),
69
+ **(SentPriorDecisions.new(decisions).left_as_printed if decisions.is_a?(Array)) }
70
+ end
71
+
72
+ # Whether decision gives fields and leaves each as the template printed it.
73
+ #: (untyped) -> bool
74
+ def recent_decision_left?(decision)
75
+ return false unless decision.is_a?(Hash)
76
+
77
+ RecentDecision.new(decision).left_as_printed?
78
+ end
79
+ end
80
+ end
81
+ end
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
- require_relative "member_map"
5
+ require_relative "principle"
6
6
  require_relative "declared_map_changes"
7
7
  require_relative "request_id"
8
8
  require_relative "correction_basis"
@@ -25,13 +25,13 @@ module Principles
25
25
  # has changed since. A correction is based on the map's version and each finding's members, never on
26
26
  # the agent's prose.
27
27
  class Audit
28
- #: MemberMap
28
+ #: Principle
29
29
  attr_reader :map
30
30
  # Each member's hash now.
31
31
  #: Hash[String, String]
32
32
  attr_reader :now
33
33
 
34
- #: (map: MemberMap, now: Hash[String, String]) -> void
34
+ #: (map: Principle, now: Hash[String, String]) -> void
35
35
  def initialize(map:, now:)
36
36
  @map = map
37
37
  @now = now
@@ -79,7 +79,7 @@ module Principles
79
79
  #: (untyped, RecordJudgedAgainst, String) { (Locator) -> Hash[String, untyped] }
80
80
  #| -> AssessmentAnswer
81
81
  def assessment(response, judged_against, answered_at, &)
82
- AssessmentAnswer.new(response, map_members, answered_at: answered_at, judged_against: judged_against, &)
82
+ AssessmentAnswer.new(response, members, answered_at: answered_at, judged_against: judged_against, &)
83
83
  end
84
84
 
85
85
  # A digest of what this audit's assessments answer: its description and question (D49).
@@ -110,7 +110,7 @@ module Principles
110
110
  # The map the audit began from: the current one when it is unchanged and the answer declares no change; or,
111
111
  # in git, the map at the base commit, which the block reads, refused unless the declared changes and any
112
112
  # members added explain every change. Outside git, a map that changed is refused.
113
- #: (CorrectionBasis, DeclaredMapChanges, map_file: String) { (String) -> MemberMap } -> MemberMap
113
+ #: (CorrectionBasis, DeclaredMapChanges, map_file: String) { (String) -> Principle } -> Principle
114
114
  def map_started_from(basis, changes, map_file:, &)
115
115
  base = changes.base_to_read(basis.base_commit, @map, map_version: basis.map_version, map_file: map_file)
116
116
  return @map unless base
@@ -121,10 +121,12 @@ module Principles
121
121
  end
122
122
 
123
123
  # The hashes the audit began from (before), refused unless they were found and request_id is the one
124
- # printed for them and basis.
124
+ # printed for them and basis; a basis the answer edited is refused as that, not as a stale request (#1045).
125
125
  #: (RequestId, CorrectionBasis, Hash[String, String]?) -> Hash[String, String]
126
126
  def confirmed_start(request_id, basis, before)
127
- raise stale_request unless before && basis.request_id(id, before) == request_id
127
+ differs = basis.request_id(id, before || {}).differs_from(request_id)
128
+ raise basis_edited(request_id) if differs == :handed
129
+ raise stale_request unless before && differs.nil?
128
130
 
129
131
  before
130
132
  end
@@ -144,13 +146,13 @@ module Principles
144
146
  # What each member's assessment is judged on beside its text, from each member's loads: its map entry and when
145
147
  # it loads (D49).
146
148
  #: (Hash[String, MemberLoads]) -> MemberGrounds
147
- def grounds(loads) = MemberGrounds.new(map_members, loads)
149
+ def grounds(loads) = MemberGrounds.new(members, loads)
148
150
 
149
151
  # Which members' last assessments this audit carries forward, from the principle's record now, grounds, and the
150
152
  # question the request asks (D49).
151
153
  #: (AuditRecord?, grounds: MemberGrounds, question: String) -> CarriedAssessments
152
154
  def carried_assessments(record, grounds:, question:)
153
- CarriedAssessments.new(record, members: map_members, judged_against: judged_against(question), now: @now,
155
+ CarriedAssessments.new(record, members: members, judged_against: judged_against(question), now: @now,
154
156
  grounds: grounds)
155
157
  end
156
158
 
@@ -160,13 +162,13 @@ module Principles
160
162
  def loads_to_check(loads, record = nil)
161
163
  completed = record&.last_completed
162
164
  LoadsToCheck.new(activation: @map.activation, loads: loads, hashes: @now,
163
- accepted: completed ? completed.members.loading_accepted(map_members) : {})
165
+ accepted: completed ? completed.members.loading_accepted(members) : {})
164
166
  end
165
167
 
166
168
  # The findings the last audit left for this one to decide (D35), from its record.
167
169
  #: (AuditRecord?) -> PriorFindings
168
170
  def prior_findings(record)
169
- PriorFindings.new(record: record, now: @now, members: map_members)
171
+ PriorFindings.new(record: record, now: @now, members: members)
170
172
  end
171
173
 
172
174
  # The project files the dispositions say changed: each fixed member's file, then each file where a
@@ -179,20 +181,27 @@ module Principles
179
181
 
180
182
  # The path of the member with member_id in the map, refused as unknown_member when no member has it (#778).
181
183
  #: (String) -> String
182
- def path_of(member_id) = map_members.found(member_id).path
184
+ def path_of(member_id) = members.found(member_id).path
183
185
 
184
186
  private
185
187
 
186
188
  # The members as the map lists them, which say each one's id and check.
187
- #: () -> MapMembers
188
- def map_members = @map.members
189
+ #: () -> PrincipleMembers
190
+ def members = @map.members
191
+
192
+ #: (RequestId) -> Error
193
+ def basis_edited(request_id)
194
+ Error.new("invalid_answer", "basis is not as request #{request_id} printed it",
195
+ "Give basis back as that request printed it; its keys may be in any order.",
196
+ fields: [{ "pointer" => "/basis", "problem" => "edited since it was printed" }])
197
+ end
189
198
 
190
199
  #: () -> Error
191
200
  def stale_request
192
201
  Error.new("stale_request", "This request no longer matches #{id}: its map, a member, the commit it " \
193
202
  "was based on, or what says when a listed member loads and how big it is " \
194
203
  "(project settings, frontmatter or a listed file), has changed since it was " \
195
- "printed",
204
+ "printed, or another release or checkout of principles printed it",
196
205
  "Start the audit again and answer the new request: #{Error::EXECUTABLE} start-audit #{id}")
197
206
  end
198
207
  end
@@ -7,6 +7,7 @@ require_relative "decided_prior_findings"
7
7
  require_relative "open_finding"
8
8
  require_relative "principles_package"
9
9
  require_relative "recorded_findings"
10
+ require_relative "record_format"
10
11
  require_relative "recorded_members"
11
12
  require_relative "json_digest"
12
13
  require_relative "write_up_repoint"
@@ -51,6 +52,11 @@ module Principles
51
52
  @fields
52
53
  end
53
54
 
55
+ # The record as this copy writes it, as RecordFormat stamps it. Only a write stamps it, so a record read without
56
+ # a format keeps its revision (D85).
57
+ #: () -> Hash[String, untyped]
58
+ def stamped = RecordFormat.new(@fields).stamped
59
+
54
60
  # A digest of the whole record. A correction carries the last completed record's from when its request was
55
61
  # printed, so it is refused once that record changed (#646). A formatter that only reorders its keys changes
56
62
  # neither what the record says nor its revision, as same_as? already compares it (#656).
@@ -68,15 +74,16 @@ module Principles
68
74
  @fields["base_members"]
69
75
  end
70
76
 
71
- # Whether other says what this record says, apart from when it and its assessments were made.
77
+ # Whether other says what this record says, apart from when it and its assessments were made and the format
78
+ # stamped when it is written.
72
79
  #: (AuditRecord?) -> bool
73
80
  def same_as?(other)
74
81
  !other.nil? && other.undated == undated
75
82
  end
76
83
 
77
- # What this record says, without when it and each of its assessments were made.
84
+ # What this record says as it is written, without when it and each of its assessments were made.
78
85
  #: () -> Hash[String, untyped]
79
- def undated = @fields.except("audited_at").merge("members" => members.undated)
86
+ def undated = stamped.except("audited_at").merge("members" => members.undated)
80
87
 
81
88
  # The commit the audit began from, or nil outside git.
82
89
  #: () -> String?
@@ -91,20 +98,6 @@ module Principles
91
98
  "map_changed" => @fields["map_version"] != map_version }
92
99
  end
93
100
 
94
- # Why a one-member audit cannot judge member's change against this record, or nil when it can (D33): the
95
- # record must be completed and have assessed the member, the member's text must differ from the one it
96
- # assessed, and the member must have no check. The one owner of these preconditions, which list-member-problems
97
- # asks before offering the audit that Acknowledgement refuses by them (#626, #632); git is the callers' to know.
98
- #: (Member, now_sha256: String?) -> Symbol?
99
- def acknowledgement_refusal(member, now_sha256:)
100
- recorded = members.hash_for(member.key)
101
- return :not_completed unless completed?
102
- return :not_assessed unless recorded
103
- return :unchanged if recorded == now_sha256
104
-
105
- :checked if member.check
106
- end
107
-
108
101
  # Whether the audit this record describes completed, rather than being left open outside git.
109
102
  #: () -> bool
110
103
  def completed?
@@ -155,9 +148,10 @@ module Principles
155
148
 
156
149
  # This record with the member known by key moved to change's to_sha256, and change kept beside it (D33).
157
150
  # Nothing else changes: the map version, base commit and findings stay the audit's own.
158
- #: (String, Hash[String, untyped]) -> AuditRecord
159
- def acknowledged(key, change)
160
- AuditRecord.new(@fields.merge("members" => members.acknowledged(key, change).to_h))
151
+ # check_result is the result reported for the member's check, which replaces the one the record kept (#1071).
152
+ #: (String, Hash[String, untyped], ?check_result: Hash[String, untyped]?) -> AuditRecord
153
+ def acknowledged(key, change, check_result: nil)
154
+ AuditRecord.new(@fields.merge("members" => members.acknowledged(key, change, check_result:).to_h))
161
155
  end
162
156
 
163
157
  # This record with each finding a repoint names moved by it at at (D59); the last repoint naming a finding
@@ -190,6 +184,11 @@ module Principles
190
184
  #: () -> Array[String]
191
185
  def open_ids = left_open.map(&:id)
192
186
 
187
+ # The ids of the findings it leaves open on the member known by key, which the next full audit decides beside
188
+ # it (D93).
189
+ #: (String) -> Array[String]
190
+ def open_ids_on(key) = left_open.select { it.on?(key) }.map(&:id)
191
+
193
192
  # The ids of the findings its audit resolved: those it fixed, and each prior finding decided resolved, never
194
193
  # one withdrawn (#714).
195
194
  #: (DecidedPriorFindings) -> Array[String]
@@ -4,6 +4,8 @@
4
4
  require_relative "../error"
5
5
  require_relative "../data/audit_files"
6
6
  require_relative "audit_record"
7
+ require_relative "member_hashes_as_written"
8
+ require_relative "recorded_hashes"
7
9
  require_relative "project_history"
8
10
 
9
11
  module Principles
@@ -24,15 +26,16 @@ module Principles
24
26
  def at(id, commit)
25
27
  [file(id), earlier_file(id)].each do |path|
26
28
  text = @history.text_at(commit, path) or next
27
- return [path, AuditRecord.new(@files.parse(id, text))]
29
+ return [path, AuditRecord.new(@files.parse(id, text) { refuse_unreadable(it, path) })]
28
30
  end
29
31
  nil
30
32
  end
31
33
 
32
- # id's record, or nil when it has none; Data::AuditFiles refuses one that is unparseable.
34
+ # id's record, or nil when it has none; Data::AuditFiles refuses one that is unparseable, and one its schema
35
+ # refuses, unless a later copy wrote it (D85).
33
36
  #: (String) -> AuditRecord?
34
37
  def find(id)
35
- fields = @files.read(id)
38
+ fields = @files.read(id) { refuse_unreadable(it, file(id)) }
36
39
  fields && AuditRecord.new(fields)
37
40
  end
38
41
 
@@ -46,10 +49,55 @@ module Principles
46
49
  []
47
50
  end
48
51
 
52
+ # Refuses to let this copy, at version, rewrite id's record when a later copy wrote it at a newer format,
53
+ # read afresh so a record that lands mid-audit is caught too (D85).
54
+ #: (String, version: String) -> void
55
+ def refuse_newer(id, version:)
56
+ record = find(id) or return
57
+ RecordFormat.new(record.to_h).refuse_rewrite(file(id), version: version)
58
+ end
59
+
60
+ # The format of id's record when a later copy wrote it, read whether or not this copy's schema accepts it; nil
61
+ # when it has none, is not newer, or is refused for another reason, which reading it reports (D85).
62
+ #: (String) -> RecordFormat?
63
+ def newer_format(id)
64
+ fields = @files.read(id) { |raw| return newer_of(raw) }
65
+ fields && newer_of(fields)
66
+ rescue Error
67
+ nil
68
+ end
69
+
70
+ # The member hashes id's record holds, which its members are compared with: the record's own when this copy can
71
+ # read it, and as written when its schema refuses one a later copy wrote, marked waiting when a later copy wrote
72
+ # it, so the comparison is read-only (D85 V8, #1066, #1067); none when it has no record.
73
+ #: (String) -> RecordedHashes
74
+ def hashes_to_compare(id)
75
+ audit = find(id) or return RecordedHashes::NONE
76
+ RecordedHashes.new(audit.members.hashes_by_key, waiting: RecordFormat.new(audit.to_h).newer?)
77
+ rescue RecordFormat::NewerFormatError
78
+ RecordedHashes.new(member_hashes_as_written(id).by_key, waiting: true)
79
+ end
80
+
81
+ # id's record if this copy can read it; nil when it has none, or a later copy wrote it in a form this copy
82
+ # cannot read, whose audits wait on an upgrade (D85, V8).
83
+ #: (String) -> AuditRecord?
84
+ def readable(id)
85
+ find(id)
86
+ rescue RecordFormat::NewerFormatError
87
+ nil
88
+ end
89
+
49
90
  # The record of each of ids that has one.
50
91
  #: (Array[String]) -> Array[AuditRecord]
51
92
  def of(ids) = ids.filter_map { |id| find(id) }
52
93
 
94
+ # The record of each of ids that this copy can read, leaving out one a later copy wrote that it cannot, so a
95
+ # read across principles is not refused for that one, whose audits wait on an upgrade (D85, V8).
96
+ #: (Array[String]) -> Array[AuditRecord]
97
+ def readable_of(ids)
98
+ ids.filter_map { readable(it) }
99
+ end
100
+
53
101
  # id's record, refused when it has none.
54
102
  #: (String) -> AuditRecord
55
103
  def fetch(id)
@@ -83,7 +131,7 @@ module Principles
83
131
  #: (AuditRecord) -> String
84
132
  def save(record)
85
133
  id = record.principle_id
86
- @files.write(id, record.to_h)
134
+ @files.write(id, record.stamped)
87
135
  file(id)
88
136
  end
89
137
 
@@ -98,6 +146,31 @@ module Principles
98
146
  def earlier_file(id)
99
147
  @files.earlier_relative(id)
100
148
  end
149
+
150
+ private
151
+
152
+ # The member hashes of id's record as a later copy wrote it, read without this copy's schema, which refuses it;
153
+ # none when it cannot be parsed at all (#1066).
154
+ #: (String) -> MemberHashesAsWritten
155
+ def member_hashes_as_written(id)
156
+ fields = @files.read(id) { |raw| return MemberHashesAsWritten.new(raw) }
157
+ MemberHashesAsWritten.new(fields)
158
+ rescue Error
159
+ MemberHashesAsWritten.new(nil)
160
+ end
161
+
162
+ #: (untyped) -> RecordFormat?
163
+ def newer_of(fields)
164
+ format = RecordFormat.new(fields) if fields.is_a?(Hash)
165
+ format if format&.newer?
166
+ end
167
+
168
+ # Refuses fields, a record at file the schema refused, as one a later copy wrote when its format says so, so
169
+ # its repair is never to repair or restore a record that is not broken (D85, V3).
170
+ #: (untyped, String) -> void
171
+ def refuse_unreadable(fields, file)
172
+ RecordFormat.new(fields).refuse_unreadable(file) if fields.is_a?(Hash)
173
+ end
101
174
  end
102
175
  end
103
176
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require_relative "assessment_report"
5
5
  require_relative "json_digest"
6
- require_relative "member_map"
6
+ require_relative "principle"
7
7
 
8
8
  module Principles
9
9
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -21,10 +21,10 @@ module Principles
21
21
  attr_reader :reported
22
22
 
23
23
  # The map of the principle the audit is of.
24
- #: MemberMap
24
+ #: Principle
25
25
  attr_reader :map
26
26
 
27
- #: (map: MemberMap, base: String?, before: Hash[String, String], ?reported: AssessmentReport) -> void
27
+ #: (map: Principle, base: String?, before: Hash[String, String], ?reported: AssessmentReport) -> void
28
28
  def initialize(map:, base:, before:, reported: AssessmentReport::NONE)
29
29
  @map = map
30
30
  @base = base
@@ -1,6 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "candidate_outline"
5
+
4
6
  module Principles
5
7
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
6
8
  module Models
@@ -17,19 +19,33 @@ module Principles
17
19
  IN_SKILL = %r{(?:\A|/)\.claude/skills/[^/]+/}
18
20
  SKILL_ENTRY = %r{(?:\A|/)\.claude/skills/[^/]+/SKILL\.md\z}
19
21
 
20
- #: (Array[Hash[String, untyped]]) -> void
21
- def initialize(files)
22
+ #: (Array[Hash[String, untyped]], text_of: ^(String) -> String) -> void
23
+ def initialize(files, text_of:)
22
24
  @files = files #: Array[Hash[String, untyped]]
25
+ @text_of = text_of
23
26
  freeze
24
27
  end
25
28
 
26
- # The inventory's files, the other files counted by directory, and those test-data hints that name a
27
- # listed file.
29
+ # The inventory's files, each Markdown one the survey reads with its outline, the other files counted by
30
+ # directory, and those test-data hints that name a listed file, whose files the survey leaves out unread (#1153).
28
31
  #: (Array[Hash[String, untyped]]) -> Hash[String, untyped]
29
32
  def listing(test_data_hints)
30
- paths = listed.map { |file| file.fetch("path") }
31
- { "files" => listed, "other_files_by_directory" => other_files_by_directory,
32
- "possibly_test_data" => test_data_hints.select { |hint| paths.include?(hint.fetch("path")) } }
33
+ outlines = outlines(test_data_hints)
34
+ files = listed.map do |file|
35
+ outline = outlines[file.fetch("path")]
36
+ outline ? file.merge(outline.to_h) : file
37
+ end
38
+ { "files" => files,
39
+ "other_files_by_directory" => other_files_by_directory, "possibly_test_data" => hints(test_data_hints) }
40
+ end
41
+
42
+ # The outline of each listed Markdown file the survey reads, by path: every one but those the test-data hints
43
+ # name (#1153), which the budget cuts by (#1155).
44
+ #: (Array[Hash[String, untyped]]) -> Hash[String, CandidateOutline]
45
+ def outlines(test_data_hints)
46
+ test_data = hints(test_data_hints).map { |hint| hint.fetch("path") }
47
+ paths = listed.map { |file| file.fetch("path") }.grep(MARKDOWN)
48
+ (paths - test_data).to_h { |path| [path, CandidateOutline.new(@text_of.call(path))] }
33
49
  end
34
50
 
35
51
  # Each Markdown or settings file, with its size.
@@ -49,6 +65,13 @@ module Principles
49
65
 
50
66
  private
51
67
 
68
+ # The test-data hints that name a listed file.
69
+ #: (Array[Hash[String, untyped]]) -> Array[Hash[String, untyped]]
70
+ def hints(test_data_hints)
71
+ paths = listed.map { |file| file.fetch("path") }
72
+ test_data_hints.select { |hint| paths.include?(hint.fetch("path")) }
73
+ end
74
+
52
75
  #: (String) -> String
53
76
  def directory(path)
54
77
  parent = path.rpartition("/").first
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "candidate_listing"
5
+ require_relative "outline_budget"
5
6
  require_relative "project_history"
6
7
 
7
8
  module Principles
@@ -21,10 +22,14 @@ module Principles
21
22
 
22
23
  # What the project's inventory lists, and which listed files, or files their links lead to, history says
23
24
  # git does not track.
24
- #: (Hash[String, untyped], ProjectHistory) -> CandidateInventory
25
- def self.found(inventory, history)
26
- listed = CandidateListing.new(inventory).to_h
27
- new(listed, untracked: history.untracked(listed.fetch("files").map { it.fetch("path") }))
25
+ # Each listed file's text, which its outline is read from, is what the block gives for its path.
26
+ #: (Hash[String, untyped], ProjectHistory) { (String) -> String } -> CandidateInventory
27
+ def self.found(inventory, history, &text_of)
28
+ texts = {} #: Hash[String, String]
29
+ listing = CandidateListing.new(inventory, text_of: ->(path) { texts[path] ||= text_of.call(path) })
30
+ listed = listing.to_h
31
+ new(listed, untracked: history.untracked(listed.fetch("files").map { it.fetch("path") }),
32
+ outlines: listing.outlines)
28
33
  end
29
34
 
30
35
  # The listing, as list-candidate-files prints it.
@@ -36,10 +41,12 @@ module Principles
36
41
  #: Array[String]?
37
42
  attr_reader :untracked
38
43
 
39
- #: (Hash[String, untyped], untracked: Array[String]?) -> void
40
- def initialize(listing, untracked:)
44
+ # outlines holds each outlined file's outline, by path, which within_budget cuts by.
45
+ #: (Hash[String, untyped], untracked: Array[String]?, ?outlines: Hash[String, CandidateOutline]) -> void
46
+ def initialize(listing, untracked:, outlines: {})
41
47
  @listing = listing
42
48
  @untracked = untracked
49
+ @outlines = outlines
43
50
  @lists = listing.merge("untracked" => untracked) #: Hash[String, untyped]
44
51
  freeze
45
52
  end
@@ -47,6 +54,13 @@ module Principles
47
54
  #: () -> Hash[String, untyped]
48
55
  def to_h = @listing
49
56
 
57
+ # This inventory with its files' list items cut to OutlineBudget, the block giving the bytes each inventory tried
58
+ # prints as (#1155).
59
+ #: () { (CandidateInventory) -> Integer } -> CandidateInventory
60
+ def within_budget(&printed_bytes)
61
+ with(OutlineBudget.new(@outlines).cut(@listing) { |listing| printed_bytes.call(with(listing)) })
62
+ end
63
+
50
64
  # Each list that names a file, in OWNER_ASK_KEYS' order, with the paths its ask names inline: all of
51
65
  # them when there are at most NAMED_INLINE_AT_MOST, and none beyond.
52
66
  #: () -> Hash[String, Array[String]]
@@ -59,6 +73,9 @@ module Principles
59
73
 
60
74
  private
61
75
 
76
+ #: (Hash[String, untyped]) -> CandidateInventory
77
+ def with(listing) = CandidateInventory.new(listing, untracked: @untracked, outlines: @outlines)
78
+
62
79
  # The path one list entry names: a file's path, a folder, or the path itself.
63
80
  #: (untyped) -> String
64
81
  def named(entry) = entry.is_a?(Hash) ? entry.fetch("path") { entry.fetch("folder") } : entry