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,129 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "check_result_template"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # The members an assessment request lists, each a plain entry of id, role, first_line, last_line, the evidence
10
+ # that locates it and, for a member with a check, the check whose result the template asks for (D30): what the
11
+ # request shows of each, the template entry each starts with, and what they carry that the request explains.
12
+ class AssessedMembers
13
+ # What the request shows of each member.
14
+ SHOWN = %w[id role first_line last_line check check_since_last_audit check_hidden_characters
15
+ acknowledged_since_last_audit carried_forward open_finding_ids judge_because moved_from read_the_change
16
+ mapped_elsewhere].freeze #: Array[String]
17
+
18
+ # reviewed_check_placeholders is the text a checked member's template prints in each field it may leave as
19
+ # printed to give none, for a check reviewed before it runs (#993); unchanged_check_placeholders, for one the
20
+ # last audit ran (#1010).
21
+ # assessment_placeholder is the text a fresh member's assessment prints, which an answer may not send back
22
+ # (#991). sighting_placeholders is the text the template printed alone gives observation and observed_at beside
23
+ # delivery, which a delivery not observed leaves as printed (#1010).
24
+ #: (Array[Hash[String, untyped]], reviewed_check_placeholders: Hash[String, String],
25
+ #| unchanged_check_placeholders: Hash[String, String], assessment_placeholder: String,
26
+ #| sighting_placeholders: Hash[String, String]) -> void
27
+ def initialize(members, reviewed_check_placeholders:, unchanged_check_placeholders:, assessment_placeholder:,
28
+ sighting_placeholders:)
29
+ @assessment_placeholder = assessment_placeholder
30
+ @sighting_placeholders = sighting_placeholders
31
+ @members = members
32
+ @reviewed_check_placeholders = reviewed_check_placeholders
33
+ @unchanged_check_placeholders = unchanged_check_placeholders
34
+ freeze
35
+ end
36
+
37
+ # What the request shows of a carried member no flag fires on (D93): what names it and its check, whose result
38
+ # the template still asks for, and of its carried assessment only its dates and flags.
39
+ COMPACT = %w[id role check check_since_last_audit check_hidden_characters carried_forward].freeze #: Array[String]
40
+ # What a compact member shows of its carried assessment.
41
+ CARRIED_COMPACTLY = %w[assessed_at observed_at observed_at_from_assessed_at evidence_changed
42
+ file_changed_outside_member].freeze #: Array[String]
43
+
44
+ # Each member as the request's context shows it, its fields in SHOWN's order; a carried member no flag fires on
45
+ # compactly, as COMPACT and CARRIED_COMPACTLY say, its stored assessment one show-audit away (D93).
46
+ #: () -> Array[Hash[String, untyped]]
47
+ def shown
48
+ @members.map do |member|
49
+ next fields(member, SHOWN) unless compact?(member)
50
+
51
+ fields(member, COMPACT).merge("carried_forward" => member.fetch("carried_forward").slice(*CARRIED_COMPACTLY))
52
+ end
53
+ end
54
+
55
+ # Each member's template entry: a fresh assessment to fill in, or, for a member whose last assessment is
56
+ # carried forward, the marker that keeps it (D49); either with its check's result when it has a check.
57
+ #: () -> Array[Hash[String, untyped]]
58
+ def templates = @members.map { |member| template(member) }
59
+
60
+ # Each member's template entry as the template printed alone gives it: a fresh assessment also prints
61
+ # observation and observed_at after delivery, so reporting a sighting fills them (#1010).
62
+ #: () -> Array[Hash[String, untyped]]
63
+ def templates_to_fill
64
+ templates.map do |entry|
65
+ next entry unless entry.key?("delivery")
66
+
67
+ entry.flat_map { |field, value| [[field, value], *(@sighting_placeholders if field == "delivery")] }.to_h
68
+ end
69
+ end
70
+
71
+ # Whether any member has a check, whose result's shapes the answer guide then shows (D30).
72
+ #: () -> bool
73
+ def checked? = @members.any? { |member| member["check"] }
74
+
75
+ # Whether any member's check is new or changed, so no audit ran it as it is now, to review before it runs (D63).
76
+ #: () -> bool
77
+ def check_to_review?
78
+ @members.any? { |member| member["check"] && member.dig("check_since_last_audit", "status") != "unchanged" }
79
+ end
80
+
81
+ # Whether the request carries any member's last assessment forward (D49).
82
+ #: () -> bool
83
+ def carried_forward? = @members.any? { |member| member["carried_forward"] }
84
+
85
+ # Whether any member is judged afresh, whose template then gives a delivery (#983).
86
+ #: () -> bool
87
+ def judged_afresh? = @members.any? { |member| !member["carried_forward"] }
88
+
89
+ # Whether a carried member no flag fires on prints compactly, with no assessment (D93).
90
+ #: () -> bool
91
+ def carried_compactly? = @members.any? { |member| compact?(member) }
92
+
93
+ # Each reason a member is judged afresh, once (D61).
94
+ #: () -> Array[String]
95
+ def judge_because = @members.filter_map { |member| member["judge_because"] }.uniq
96
+
97
+ # Each entry naming another principle's role for a member's lines (#719).
98
+ #: () -> Array[Hash[String, untyped]]
99
+ def mapped_elsewhere = shown.flat_map { |member| member["mapped_elsewhere"] || [] }
100
+
101
+ private
102
+
103
+ # Whether member is carried with no flag firing on it, so it prints compactly (D93).
104
+ #: (Hash[String, untyped]) -> bool
105
+ def compact?(member) = member["carried_forward"] && !member["flagged"]
106
+
107
+ # member's fields named in names, in that order.
108
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
109
+ def fields(member, names) = names.select { member.key?(it) }.to_h { [it, member[it]] }
110
+
111
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
112
+ def template(member)
113
+ assessed = member["carried_forward"] ? carried(member) : fresh(member)
114
+ template = CheckResultTemplate.for(member, reviewed_placeholders: @reviewed_check_placeholders,
115
+ unchanged_placeholders: @unchanged_check_placeholders)
116
+ template ? assessed.merge("check_result" => template) : assessed
117
+ end
118
+
119
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
120
+ def carried(member) = { "member_id" => member.fetch("id"), "carried_forward" => true }
121
+
122
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
123
+ def fresh(member)
124
+ { "member_id" => member.fetch("id"), "assessment" => @assessment_placeholder,
125
+ "delivery" => "not_observed", "evidence" => member.fetch("evidence") }
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,130 +1,191 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "check_result_template"
4
+ require_relative "answer_head"
5
+ require_relative "assessed_members"
6
+ require_relative "instruction"
5
7
  require_relative "prompts"
6
8
  require_relative "request_parts"
7
9
 
8
10
  module Principles
9
11
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
12
  module Views
11
- # One assessment request start-audit prints: the principle and its members as the agent assesses them, and
12
- # the answer's template. Each member is an entry of id, role, first_line, last_line, the evidence that locates
13
- # it and, for a member with a check, the check whose result the template asks for (D30). Its hash travels in
14
- # the request id, not here.
13
+ # One assessment request start-audit prints: the principle and its members as the agent assesses them, as
14
+ # AssessedMembers, and the answer's template. Its hash travels in the request id, not here.
15
15
  class AssessmentRequest
16
- # The question every member's assessment answers, which a completed record digests with the description (D49).
16
+ # The recent_decision the request's template prints, which names the other form in the guide beside it.
17
+ IN_GUIDE = {
18
+ "unavailable_reason" => "Or use the assessed shape in answer_guide.recent_decision."
19
+ }.freeze #: Hash[String, String]
20
+ # How mapped_elsewhere_instruction's paragraph on open findings elsewhere begins, which prints only when an
21
+ # entry names one (#808).
22
+ OPEN_FINDINGS_ELSEWHERE = "Where an entry names `open_finding_ids`" #: String
23
+
24
+ # The question every member's assessment answers, which a completed record digests with the description (D49):
25
+ # the whole question, what observed means too, however much of it a request prints (#983).
17
26
  #: () -> String
18
- def self.question = Prompts.text("assess-every-member/assess-each-member-and-the-set")
19
-
20
- # basis is what the answer hands back unchanged: the base commit and the last completed record's revision.
21
- # parts are what the agent reads beside the members before the question, such as the files outside the map
22
- # that differ from the base commit (#409), each with any slots it adds to the template (D60).
23
- #: (principle_id: String, description: untyped, members: Array[Hash[String, untyped]],
24
- #| basis: Hash[String, untyped], ?parts: Array[RequestPart]) -> void
25
- def initialize(principle_id:, description:, members:, basis:, parts: [])
26
- @principle_id = principle_id
27
- @description = description
27
+ def self.question = question_paragraphs.join(" ")
28
+
29
+ # The question's two parts: what to assess, and what observed means, which only a member judged afresh needs.
30
+ #: () -> [String, String]
31
+ def self.question_paragraphs
32
+ [Prompts.text("assess-every-member/assess-each-member-and-the-set"),
33
+ Prompts.text("assess-every-member/say-what-observed-means")]
34
+ end
35
+
36
+ # principle is the principle_id and description it names. head is what the answer hands back unchanged: the
37
+ # request's id and its basis, the base commit and the last completed record's revision. parts are what the
38
+ # agent reads beside the members before the question, such as the files outside the map that differ from the
39
+ # base commit (#409), each with any slots it adds to the template (D60). placeholders is what the answer's own
40
+ # fields print, by field, which their models own: collective_assessment's, which an answer may not send back
41
+ # (#991), and recent_decision's, each field of both its forms, in the template alone, which the agent fills one
42
+ # of (#994).
43
+ #: (principle: Hash[String, untyped], members: AssessedMembers, head: AnswerHead,
44
+ #| placeholders: Hash[String, untyped], ?parts: Array[RequestPart]) -> void
45
+ def initialize(principle:, members:, head:, placeholders:, parts: [])
46
+ @principle = principle
47
+ @placeholders = placeholders
28
48
  @members = members
29
- @basis = basis
49
+ @head = head
30
50
  @parts = RequestParts.new(parts) #: RequestParts
31
51
  freeze
32
52
  end
33
53
 
54
+ # The id the request is answered under.
55
+ #: () -> String
56
+ def request_id = @head.request_id
57
+
34
58
  # What the agent assesses, its other parts, the question and a guide to the answer's shapes.
35
59
  #: () -> Hash[String, untyped]
36
60
  def context
37
- listed = { "principle_id" => @principle_id, "description" => @description,
38
- "members" => @members.map do |member|
39
- member.slice("id", "role", "first_line", "last_line", "check", "check_since_last_audit",
40
- "check_hidden_characters", "acknowledged_since_last_audit", "carried_forward",
41
- "judge_because", "moved_from", "read_the_change", "mapped_elsewhere")
42
- end }
61
+ listed = @principle.merge("members" => @members.shown)
43
62
  @parts.shown_after(listed).merge(asked)
44
63
  end
45
64
 
65
+ # The fields the request prints an instruction under, in the order it prints them: the question, the answer
66
+ # guide and each field named for an instruction (D81 step 2).
67
+ #: () -> Array[String]
68
+ def instruction_fields = printed_instructions.map(&:field)
69
+
70
+ # The principle the request audits.
71
+ #: () -> String
72
+ def principle_id = @principle.fetch("principle_id")
73
+
74
+ # The instruction fields the request prints only in part, leaving out paragraphs for cases it does not hold.
75
+ #: () -> Array[String]
76
+ def trimmed_instruction_fields = printed_instructions.select(&:trimmed?).map(&:field)
77
+
78
+ # The instruction field whole: every paragraph, the ones for cases the request does not hold too.
79
+ #: (String) -> untyped
80
+ def whole_instruction(field) = printed_instructions.find { it.field == field }&.whole
81
+
46
82
  # The answer to fill in: one assessment per member, and the set's.
47
83
  #: () -> Hash[String, untyped]
48
84
  def template
49
- assessed = {
50
- "basis" => @basis,
51
- "member_assessments" => @members.map { |member| member_assessment_template(member) },
52
- "collective_assessment" => "How the members reinforce the principle, and any contradiction or " \
53
- "missing connection.",
54
- "recent_decision" => { "unavailable_reason" => "Or use the assessed shape in answer_guide.recent_decision." },
55
- "findings" => []
56
- }
57
- @parts.slotted_after(assessed)
85
+ @head.leading(@parts.slotted_after(assessed(IN_GUIDE, @members.templates)))
86
+ end
87
+
88
+ # The answer to fill in as printed alone, with no request beside it: each placeholder says what its field
89
+ # takes, and points at nothing left unprinted (D81 step 1), after one note saying how a field left as printed is
90
+ # read (#1043, D88).
91
+ #: () -> Hash[String, untyped]
92
+ def template_to_fill
93
+ filled = assessed(@placeholders.fetch("recent_decision"), @members.templates_to_fill)
94
+ @head.leading(@parts.filled_after({ "left_as_printed_rule" => @placeholders.fetch("left_as_printed_rule"),
95
+ **filled, "findings" => [@placeholders.fetch("new_finding")] }))
58
96
  end
59
97
 
60
98
  private
61
99
 
62
- # What the request asks of what the agent read: the question, why members are judged afresh, how to treat the
63
- # members it carries forward and the roles other principles give their lines, and the guide to the answer's
64
- # shapes.
100
+ # The answer's fields after its head and before its parts' slots, recent_decision and the members' templates as
101
+ # given.
102
+ #: (Hash[String, String], Array[Hash[String, untyped]]) -> Hash[String, untyped]
103
+ def assessed(recent_decision, members)
104
+ { "member_assessments" => members,
105
+ "collective_assessment" => @placeholders.fetch("collective_assessment"),
106
+ "recent_decision" => recent_decision, "findings" => [] }
107
+ end
108
+
109
+ # The instructions the request prints, in order: each part's, after its list, then its own.
110
+ #: () -> Array[Instruction | GuideInstruction]
111
+ def printed_instructions = [*@parts.instructions, *instructions].reject { it.printed.empty? }
112
+
113
+ # What the request asks of what the agent read, each of its own instructions as the request prints it.
65
114
  #: () -> Hash[String, untyped]
66
- def asked
67
- { "question" => AssessmentRequest.question }.merge(judge_because_instruction, carried_forward_instruction,
68
- mapped_elsewhere_instruction)
69
- .merge("answer_guide" => answer_guide)
115
+ def asked = instructions.reduce({}) { |all, instruction| all.merge(instruction.printed) }
116
+
117
+ # The request's own instructions: the question, why members are judged afresh, how to treat the members it
118
+ # carries forward and the roles other principles give their lines, and the guide to the answer's shapes.
119
+ #: () -> Array[Instruction | GuideInstruction]
120
+ def instructions
121
+ [question, judge_because_instruction,
122
+ carried_forward_instruction, mapped_elsewhere_instruction, answer_guide]
123
+ end
124
+
125
+ # The question, defining observed only when a member is judged afresh, whose delivery it guides (#983).
126
+ #: () -> Instruction
127
+ def question
128
+ assess, observed = AssessmentRequest.question_paragraphs
129
+ Instruction.new("question", [[assess, true], [observed, @members.judged_afresh?]])
70
130
  end
71
131
 
72
132
  # Why each member with judge_because is judged afresh, explaining only the values the members carry, so the
73
133
  # agent meets each value's meaning where it meets the value (D61); nothing when no member gives one.
74
- #: () -> Hash[String, untyped]
134
+ #: () -> Instruction
75
135
  def judge_because_instruction
76
- reasons = @members.filter_map { |member| member["judge_because"] }.uniq
77
- return {} if reasons.empty?
78
-
79
- intro, *meanings = Prompts.text("assess-every-member/why-each-member-is-judged-again").split("\n\n")
80
- shown = meanings.select { |meaning| reasons.any? { |reason| meaning.start_with?("`#{reason}`:") } }
81
- { "judge_because_instruction" => [intro, *shown].join("\n\n") }
136
+ reasons = @members.judge_because
137
+ text = Prompts.text("assess-every-member/why-each-member-is-judged-again")
138
+ Instruction.of_paragraphs("judge_because_instruction", text) do |paragraph|
139
+ reasons.any? && (!paragraph.start_with?("`") || reasons.any? { paragraph.start_with?("`#{it}`:") })
140
+ end
82
141
  end
83
142
 
84
143
  # How to judge the roles other principles give a member's lines, printed only when a member shares lines with
85
144
  # another principle's (#719, D61), and, when an entry names findings open on its member, where to read how to
86
145
  # treat them, which prints apart, before the question (#808).
87
- #: () -> Hash[String, untyped]
146
+ #: () -> Instruction
88
147
  def mapped_elsewhere_instruction
89
- entries = @members.flat_map { |member| member["mapped_elsewhere"] || [] }
90
- return {} if entries.empty?
91
-
92
- roles, open_findings = Prompts.text("assess-every-member/check-roles-other-principles-give-these-lines")
93
- .split("\n\n")
94
- shown = entries.any? { |entry| entry["open_finding_ids"] } ? [roles, open_findings] : [roles]
95
- { "mapped_elsewhere_instruction" => shown.join("\n\n") }
148
+ entries = @members.mapped_elsewhere
149
+ open = entries.any? { |entry| entry["open_finding_ids"] }
150
+ text = Prompts.text("assess-every-member/check-roles-other-principles-give-these-lines")
151
+ Instruction.of_paragraphs("mapped_elsewhere_instruction", text) do |paragraph|
152
+ entries.any? && (open || !paragraph.start_with?(OPEN_FINDINGS_ELSEWHERE))
153
+ end
96
154
  end
97
155
 
98
- # The answer guide, showing the check result's shapes only when a member has a check, so an audit
99
- # with no checks costs no more context than before (D30).
100
- #: () -> Hash[String, untyped]
156
+ # The answer guide, showing check_result's fields only when a member has a check, so an audit
157
+ # with no checks costs no more context than before (D30), and delivery's shapes only when a member is judged
158
+ # afresh, since a carried member's marker gives none (#983). check_result's limits say how to review a check
159
+ # before running it only when a check is new or changed, as that check's own template says too (#983).
160
+ #: () -> GuideInstruction
101
161
  def answer_guide
102
162
  guide = Prompts.data("assess-every-member/answer-guide")
103
- @members.any? { |member| member["check"] } ? guide : guide.except("check_result")
163
+ narrowed = @members.check_to_review? ? {} : guide.slice("check_result")
164
+ GuideInstruction.new("answer_guide", guide.merge("check_result" => reviewed(guide.fetch("check_result"))),
165
+ narrowed:) do |entry|
166
+ case entry
167
+ when "check_result" then @members.checked?
168
+ when "member_delivery" then @members.judged_afresh?
169
+ else true
170
+ end
171
+ end
104
172
  end
105
173
 
106
- # How to answer when the request carries some members' last assessments forward; nothing when it carries none.
107
- #: () -> Hash[String, untyped]
108
- def carried_forward_instruction
109
- return {} unless @members.any? { |member| member["carried_forward"] }
110
-
111
- { "carried_forward_instruction" => Prompts.text("assess-every-member/judge-the-set-with-carried-assessments") }
174
+ # check_result's guide entry whole, its limits ending with how to review a new or changed check before running it.
175
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
176
+ def reviewed(check_result)
177
+ review = Prompts.text("assess-every-member/review-a-new-or-changed-check-before-running-it")
178
+ check_result.merge("limits" => "#{check_result.fetch("limits")} #{review}")
112
179
  end
113
180
 
114
- # A member's template entry: a fresh assessment to fill in, or, for a member whose last assessment is carried
115
- # forward, the marker that keeps it (D49); either with its check's result when it has a check.
116
- #: (Hash[String, untyped]) -> Hash[String, untyped]
117
- def member_assessment_template(member)
118
- assessed = if member["carried_forward"]
119
- { "member_id" => member.fetch("id"), "carried_forward" => true }
120
- else
121
- { "member_id" => member.fetch("id"), "assessment" => "Your assessment, including its context cost",
122
- "delivery" => "not_observed", "evidence" => member.fetch("evidence") }
123
- end
124
- check = member["check"] or return assessed
125
- template = CheckResultTemplate.new(check, member["check_since_last_audit"],
126
- member.fetch("check_hidden_characters", []))
127
- assessed.merge("check_result" => template.to_h)
181
+ # How to answer when the request carries some members' last assessments forward; nothing when it carries none.
182
+ # What a compact carried member shows, and what prints one whole, only when one prints compactly (#983).
183
+ #: () -> Instruction
184
+ def carried_forward_instruction
185
+ carry = Prompts.text("assess-every-member/judge-the-set-with-carried-assessments")
186
+ compact = Prompts.text("assess-every-member/read-a-compact-carried-member")
187
+ Instruction.new("carried_forward_instruction",
188
+ [[carry, @members.carried_forward?], [compact, @members.carried_compactly?]])
128
189
  end
129
190
  end
130
191
  end
@@ -1,8 +1,10 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../prose_list"
4
5
  require_relative "assessment_request"
5
6
  require_relative "audit_changes"
7
+ require_relative "correction_request"
6
8
  require_relative "invocation"
7
9
  require_relative "prior_finding_decisions_result"
8
10
  require_relative "prompts"
@@ -22,11 +24,28 @@ module Principles
22
24
  freeze
23
25
  end
24
26
 
25
- #: (Hash[String, untyped]) -> Hash[String, untyped]
27
+ # An answer's result as submit-answer prints it: a correction request in full, with how to answer it.
28
+ #: (Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
26
29
  def present(output)
30
+ output = correction_request(output) if output.is_a?(CorrectionRequest)
27
31
  output["status"] == "agent_judgement_required" ? request(output) : output
28
32
  end
29
33
 
34
+ # show-answer-check's acceptable result, with the correction's answer an accepted assessment leads to, alone, to
35
+ # save and fill, and how to submit it after the assessment, which outside git writes the open record it is
36
+ # checked against; next_action still ends with the checked answer's submit command (#859). The result is
37
+ # unchanged for any other answer (D81 step 3).
38
+ #: (Hash[String, untyped], Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
39
+ def with_correction_to_fill(acceptable, output)
40
+ return acceptable unless output.is_a?(CorrectionRequest)
41
+
42
+ save = "Once this answer is submitted with the last line's command, save correction_template, the " \
43
+ "correction's answer it leads to, to a file outside the project, such as under $TMPDIR, fill only " \
44
+ "its dispositions, and submit it: #{@invocation.submit_answer(output.request_id)}"
45
+ acceptable.merge("correction_template" => output.template,
46
+ "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
47
+ end
48
+
30
49
  # show-answer-check: the answer passed every check, and what submitting it would write. open_findings_will_print
31
50
  # previews each written-up finding's write_up_opening, and is nil when the record would keep none (#411).
32
51
  # map_entry_changes gives each claimed map entry's changed role and check, left out when there is none (#462).
@@ -35,7 +54,7 @@ module Principles
35
54
  #| ?map_entry_changes: Array[Hash[String, untyped]]) -> Hash[String, untyped]
36
55
  def acceptable(request_id, would_write, answer_file:, open_findings_will_print: nil, map_entry_changes: [])
37
56
  submit = @invocation.submit_answer(request_id, file: answer_file)
38
- waits = "Submitting it writes nothing yet: the audit record is written when the audit completes.\n"
57
+ waits = "Submitting this answer writes nothing yet: the audit record is written when the audit completes.\n"
39
58
  waits = "" unless would_write.empty?
40
59
  result = { "status" => "answer_acceptable", "request_id" => request_id, "would_write" => would_write }
41
60
  result = result.merge("open_findings_will_print" => open_findings_will_print) if open_findings_will_print
@@ -43,30 +62,28 @@ module Principles
43
62
  result.merge("next_action" => "#{waits}Submit the same answer unchanged, as you gave it: #{submit}")
44
63
  end
45
64
 
46
- # start-audit: the assessment request, as a judgement to answer under request_id.
47
- #: (request_id: String, request: AssessmentRequest) -> Hash[String, untyped]
48
- def assessment_request(request_id:, request:)
49
- judgement("assessment", request_id, request.context, request.template)
65
+ # start-audit: the assessment request, as a judgement to answer under its request id, its context naming the
66
+ # instructions it prints only in part and the flag that prints one whole, so a trimmed field is not taken for
67
+ # the whole (#983), without the command the agent just ran (#1125).
68
+ #: (AssessmentRequest) -> Hash[String, untyped]
69
+ def assessment_request(request)
70
+ output = judgement("assessment", request)
71
+ trimmed = request.trimmed_instruction_fields
72
+ return output if trimmed.empty?
73
+
74
+ note = Prompts.text("assess-every-member/read-a-trimmed-instruction-whole", fields: ProseList.new(trimmed).to_s)
75
+ output.merge("context" => output.fetch("context").merge("trimmed_instructions" => note))
50
76
  end
51
77
 
52
- # The correction request that follows an assessment with findings: one disposition for each, with a guide
53
- # to every disposition's shape (#414). It says what was stored, so an assessment submitted twice plainly
54
- # replaced nothing: in git nothing is, and outside git, where basis has no base commit, the open record
55
- # keeps what the audit began from.
56
- # placeholders is the text the template leaves in each field the agent writes (#725).
57
- #: (request_id: String, principle_id: String, findings: Array[untyped], basis: Hash[String, untyped],
58
- #| placeholders: Hash[String, String]) -> Hash[String, untyped]
59
- def correction_request(request_id:, principle_id:, findings:, basis:, placeholders:)
60
- context = { "principle_id" => principle_id, "findings" => findings,
61
- "question" => Prompts.text("dispose-of-each-finding/fix-or-record-each-finding"),
62
- "answer_guide" => Prompts.data("dispose-of-each-finding/answer-guide") }
63
- template = { "basis" => basis, "dispositions" => findings.map do |finding|
64
- { "finding_id" => finding["id"], "action" => nil, "reason" => placeholders.fetch("reason"),
65
- "changed_members" => [], "evidence" => [],
66
- "reassessment" => placeholders.fetch("reassessment"), "recorded_at" => nil,
67
- "waits_on" => nil }
68
- end }
69
- judgement("correction", request_id, context, template).merge("stored" => stored(basis["base_commit"]))
78
+ # start-audit --as template: the assessment's answer alone, to fill and submit (D81 step 1).
79
+ #: (AssessmentRequest) -> Hash[String, untyped]
80
+ def answer_to_fill(request) = request.template_to_fill
81
+
82
+ # submit-answer: the correction request that follows an assessment with findings, as a judgement to answer
83
+ # under its request id, saying what submitting the assessment stored.
84
+ #: (CorrectionRequest) -> Hash[String, untyped]
85
+ def correction_request(request)
86
+ judgement("correction", request).merge("stored" => request.stored)
70
87
  end
71
88
 
72
89
  # A completed audit: its resolved and open findings, the files to commit and, in git, each changed
@@ -88,6 +105,15 @@ module Principles
88
105
  "full_record" => @invocation.in_project("show-audit", principle_id))
89
106
  end
90
107
 
108
+ # completed, a completed audit's result, offering to set principles up after its next_action, as it does
109
+ # while nothing keeps them held between audits (D95).
110
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
111
+ def offering_set_up(completed)
112
+ offer = Prompts.text("set-principles-up/keep-them-held-between-audits",
113
+ command: @invocation.in_project("show-meta-principle-passage"))
114
+ completed.merge("next_action" => "#{completed.fetch("next_action")}\n#{offer}")
115
+ end
116
+
91
117
  # The notice start-audit adds when the last audit's record is not committed.
92
118
  #: (String) -> String
93
119
  def uncommitted_record_notice(file)
@@ -96,24 +122,11 @@ module Principles
96
122
 
97
123
  private
98
124
 
99
- # What submitting the assessment stored, and what submitting it again would do: in git, where the
100
- # audit has a base commit, nothing; outside git, the open record.
101
- #: (String?) -> String
102
- def stored(base_commit)
103
- again = "Submitting the same assessment again prints this same request"
104
- unless base_commit
105
- return "This audit's open record, listed under wrote when it was first written, keeps what the audit " \
106
- "began from. #{again} and leaves that record as it is."
107
- end
108
-
109
- "Nothing is stored yet: this request was computed from your assessment and the project. #{again} and " \
110
- "replaces nothing; the audit record is written when the audit completes."
111
- end
112
-
113
- #: (String, String, Hash[String, untyped], Hash[String, untyped]) -> Hash[String, untyped]
114
- def judgement(phase, request_id, context, template)
115
- { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => phase,
116
- "context" => context, "response_template" => { "request_id" => request_id }.merge(template),
125
+ # request as a judgement to answer in phase, under its id, which its template's head also gives.
126
+ #: (String, AssessmentRequest | CorrectionRequest) -> Hash[String, untyped]
127
+ def judgement(phase, request)
128
+ { "status" => "agent_judgement_required", "request_id" => request.request_id, "phase" => phase,
129
+ "context" => request.context, "response_template" => request.template,
117
130
  "limits" => Prompts.text("answer-any-judgement-request/what-a-self-audit-cannot-show") }
118
131
  end
119
132