principles 0.0.4 → 0.0.6

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 (227) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/cli.rb +3 -1
  4. data/lib/principles/command_line.rb +38 -26
  5. data/lib/principles/command_routes.rb +11 -4
  6. data/lib/principles/controllers/acknowledgement.rb +93 -17
  7. data/lib/principles/controllers/answer.rb +45 -76
  8. data/lib/principles/controllers/answer_phase.rb +54 -0
  9. data/lib/principles/controllers/assessment.rb +46 -11
  10. data/lib/principles/controllers/audit.rb +17 -6
  11. data/lib/principles/controllers/audit_completion.rb +9 -5
  12. data/lib/principles/controllers/command.rb +5 -4
  13. data/lib/principles/controllers/correction.rb +22 -10
  14. data/lib/principles/controllers/full_audit_request.rb +11 -1
  15. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  16. data/lib/principles/controllers/inventory.rb +15 -29
  17. data/lib/principles/controllers/mapping.rb +9 -1
  18. data/lib/principles/controllers/member_addition.rb +65 -0
  19. data/lib/principles/controllers/member_entries.rb +6 -24
  20. data/lib/principles/controllers/member_problems_report.rb +13 -6
  21. data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
  22. data/lib/principles/controllers/members_to_assess.rb +21 -13
  23. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  24. data/lib/principles/controllers/repoint.rb +22 -23
  25. data/lib/principles/controllers/survey.rb +60 -0
  26. data/lib/principles/data/audit_files.rb +4 -0
  27. data/lib/principles/data/bounded_file.rb +9 -4
  28. data/lib/principles/data/candidate_files_found.rb +48 -13
  29. data/lib/principles/data/command-steps.json +85 -24
  30. data/lib/principles/data/committed_tree.rb +84 -0
  31. data/lib/principles/data/first_parent_log.rb +48 -0
  32. data/lib/principles/data/first_parent_range.rb +122 -0
  33. data/lib/principles/data/git_command.rb +37 -0
  34. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  35. data/lib/principles/data/map_files.rb +35 -10
  36. data/lib/principles/data/principles_directory.rb +40 -0
  37. data/lib/principles/data/principles_subfolder.rb +39 -16
  38. data/lib/principles/data/project_files.rb +22 -11
  39. data/lib/principles/data/repository.rb +55 -29
  40. data/lib/principles/data/requested_candidate_files.rb +43 -0
  41. data/lib/principles/data/running_version.rb +3 -5
  42. data/lib/principles/data/schema_check.rb +16 -6
  43. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +18 -5
  44. data/lib/principles/data/schemas/answer-guide.schema.json +255 -68
  45. data/lib/principles/data/schemas/audit-record.schema.json +10 -1
  46. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  47. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  48. data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
  49. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  50. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  51. data/lib/principles/data/verified_head.rb +162 -0
  52. data/lib/principles/invocation_options.rb +3 -3
  53. data/lib/principles/models/acknowledgement.rb +95 -84
  54. data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
  55. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  56. data/lib/principles/models/answer_place.rb +4 -0
  57. data/lib/principles/models/assessment_answer.rb +0 -45
  58. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  59. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  60. data/lib/principles/models/audit_record.rb +12 -16
  61. data/lib/principles/models/audit_records.rb +52 -23
  62. data/lib/principles/models/candidate_files.rb +44 -10
  63. data/lib/principles/models/candidate_inventory.rb +69 -8
  64. data/lib/principles/models/candidate_outline.rb +195 -0
  65. data/lib/principles/models/captured_head.rb +72 -0
  66. data/lib/principles/models/carried_member.rb +42 -0
  67. data/lib/principles/models/check_since_last_audit.rb +20 -11
  68. data/lib/principles/models/command_steps.rb +17 -1
  69. data/lib/principles/models/declared_map_changes.rb +29 -12
  70. data/lib/principles/models/declared_member_removals.rb +75 -0
  71. data/lib/principles/models/disposition.rb +4 -2
  72. data/lib/principles/models/fix_only_fields.rb +12 -0
  73. data/lib/principles/models/frontmatter_fields.rb +9 -8
  74. data/lib/principles/models/guidance_search_path.rb +26 -0
  75. data/lib/principles/models/guidance_search_paths.rb +57 -0
  76. data/lib/principles/models/instruction_named.rb +35 -0
  77. data/lib/principles/models/left_as_printed.rb +39 -0
  78. data/lib/principles/models/line_span.rb +6 -0
  79. data/lib/principles/models/loaded_files.rb +1 -2
  80. data/lib/principles/models/loading_scope.rb +61 -0
  81. data/lib/principles/models/locator.rb +6 -0
  82. data/lib/principles/models/mapped_principles.rb +39 -37
  83. data/lib/principles/models/member_assessments.rb +9 -31
  84. data/lib/principles/models/member_file.rb +20 -47
  85. data/lib/principles/models/member_hashes_as_written.rb +10 -6
  86. data/lib/principles/models/member_history.rb +7 -5
  87. data/lib/principles/models/member_lines.rb +63 -15
  88. data/lib/principles/models/member_loading_scopes.rb +49 -0
  89. data/lib/principles/models/member_loads.rb +4 -0
  90. data/lib/principles/models/member_mapping_run.rb +30 -0
  91. data/lib/principles/models/member_moves.rb +4 -0
  92. data/lib/principles/models/member_problems.rb +63 -33
  93. data/lib/principles/models/member_region.rb +129 -0
  94. data/lib/principles/models/member_repair_moves.rb +52 -0
  95. data/lib/principles/models/member_snapshots.rb +14 -1
  96. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  97. data/lib/principles/models/meta_principle.rb +14 -0
  98. data/lib/principles/models/missing_files.rb +2 -2
  99. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  100. data/lib/principles/models/other_templates_placeholders.rb +81 -42
  101. data/lib/principles/models/outline_budget.rb +142 -0
  102. data/lib/principles/models/outline_group.rb +31 -0
  103. data/lib/principles/models/outline_section.rb +56 -0
  104. data/lib/principles/models/principle.rb +14 -7
  105. data/lib/principles/models/principle_file_revision.rb +48 -0
  106. data/lib/principles/models/principle_history.rb +46 -19
  107. data/lib/principles/models/principle_lineage.rb +118 -0
  108. data/lib/principles/models/principle_map_revision.rb +39 -0
  109. data/lib/principles/models/principle_mapping_history.rb +132 -0
  110. data/lib/principles/models/principle_members.rb +25 -0
  111. data/lib/principles/models/principle_predecessor.rb +45 -0
  112. data/lib/principles/models/principle_publication.rb +177 -0
  113. data/lib/principles/models/principle_revision.rb +104 -0
  114. data/lib/principles/models/prior_decision_fields.rb +3 -2
  115. data/lib/principles/models/prior_finding_decision.rb +14 -4
  116. data/lib/principles/models/problem_report.rb +17 -5
  117. data/lib/principles/models/project.rb +46 -39
  118. data/lib/principles/models/project_history.rb +45 -25
  119. data/lib/principles/models/quoted_change.rb +137 -0
  120. data/lib/principles/models/record_format.rb +12 -2
  121. data/lib/principles/models/recorded_entry.rb +6 -0
  122. data/lib/principles/models/recorded_hashes.rb +7 -3
  123. data/lib/principles/models/recorded_members.rb +27 -15
  124. data/lib/principles/models/refusal_before_shape.rb +21 -0
  125. data/lib/principles/models/repoint.rb +13 -0
  126. data/lib/principles/models/reported_check.rb +5 -14
  127. data/lib/principles/models/sent_answer.rb +61 -0
  128. data/lib/principles/models/shape_problems_beside.rb +40 -0
  129. data/lib/principles/models/submitted_answer.rb +34 -0
  130. data/lib/principles/models/survey_search_paths.rb +26 -0
  131. data/lib/principles/models/template_placeholders.rb +34 -4
  132. data/lib/principles/models/text_within.rb +55 -0
  133. data/lib/principles/models/unchecked_members.rb +76 -0
  134. data/lib/principles/models/uncommitted_files.rb +50 -0
  135. data/lib/principles/models/unknown_principle.rb +29 -0
  136. data/lib/principles/models/write_up_opening.rb +21 -4
  137. data/lib/principles/positional_arguments.rb +37 -0
  138. data/lib/principles/session_start_options.rb +2 -2
  139. data/lib/principles/start_audit_options.rb +19 -4
  140. data/lib/principles/version.rb +2 -2
  141. data/lib/principles/views/acknowledgement_result.rb +23 -11
  142. data/lib/principles/views/added_member.rb +41 -0
  143. data/lib/principles/views/answered_request.rb +21 -0
  144. data/lib/principles/views/assessed_members.rb +43 -10
  145. data/lib/principles/views/assessment_request.rb +91 -31
  146. data/lib/principles/views/audit_result.rb +40 -28
  147. data/lib/principles/views/candidate_files_result.rb +85 -19
  148. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  149. data/lib/principles/views/check_notes.rb +44 -0
  150. data/lib/principles/views/check_result_template.rb +14 -23
  151. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  152. data/lib/principles/views/correction_request.rb +32 -1
  153. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  154. data/lib/principles/views/instruction.rb +74 -0
  155. data/lib/principles/views/json_with_entries_on_lines.rb +59 -0
  156. data/lib/principles/views/loads_to_check_result.rb +2 -2
  157. data/lib/principles/views/map_added_to.rb +56 -2
  158. data/lib/principles/views/map_result.rb +23 -43
  159. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  160. data/lib/principles/views/member_change_since_baseline.rb +23 -5
  161. data/lib/principles/views/member_repairs.rb +22 -52
  162. data/lib/principles/views/members_a_commit_changed.rb +16 -6
  163. data/lib/principles/views/new_loading_scope.rb +31 -0
  164. data/lib/principles/views/one_member_check_result_template.rb +47 -0
  165. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  166. data/lib/principles/views/open_findings_line.rb +77 -23
  167. data/lib/principles/views/principle_read_result.rb +24 -29
  168. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  169. data/lib/principles/views/prior_findings_result.rb +23 -15
  170. data/lib/principles/views/problem_lines.rb +3 -1
  171. data/lib/principles/views/problem_result.rb +8 -3
  172. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  173. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  174. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -48
  175. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  176. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  177. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
  178. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  179. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  180. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  181. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  182. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  183. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  184. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  185. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +16 -3
  186. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  187. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  188. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  189. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  190. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  191. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +11 -5
  192. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  193. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  194. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  195. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  196. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  197. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  198. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  199. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  200. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  201. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  202. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +55 -7
  203. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +9 -8
  204. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  205. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
  206. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  207. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  208. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  209. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +27 -1
  210. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  211. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
  212. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
  213. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  214. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  215. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  216. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  217. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  218. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
  219. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  220. data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
  221. data/lib/principles/views/request_part.rb +16 -8
  222. data/lib/principles/views/request_parts.rb +4 -0
  223. metadata +92 -7
  224. data/lib/principles/models/candidate_listing.rb +0 -32
  225. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  226. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
  227. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "invocation"
5
+ require_relative "answered_request"
5
6
  require_relative "member_change_since_baseline"
6
7
  require_relative "prompts"
7
8
 
@@ -16,28 +17,39 @@ module Principles
16
17
  freeze
17
18
  end
18
19
 
19
- # change is the member's change since its baseline; open_findings, the record's findings on the member. What
20
- # the agent judges is under context, the question last, as in a full audit's request (D60).
20
+ # change is the member's change since its baseline; context, what the request's context shows beside it, such
21
+ # as the record's findings on the member; placeholders, the text the template prints in each field the agent
22
+ # writes. What the agent judges is under context, the question last, as in a full audit's request (D60).
21
23
  #: (request_id: String, principle_id: String, change: MemberChangeSinceBaseline,
22
- #| open_findings: Hash[String, Array[String]]) -> Hash[String, untyped]
23
- def request(request_id:, principle_id:, change:, open_findings:)
24
+ #| context: Hash[String, untyped], placeholders: Hash[String, untyped]) -> Hash[String, untyped]
25
+ def request(request_id:, principle_id:, change:, context:, placeholders:)
24
26
  { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "acknowledgement",
25
- "context" => { "principle_id" => principle_id, **change.to_h, **open_findings,
27
+ "context" => { "principle_id" => principle_id, **change.to_h, **context,
26
28
  "question" => Prompts.text("acknowledge-a-change/say-whether-the-change-keeps-the-meaning") },
27
- "response_template" => { "request_id" => request_id,
28
- "basis" => { "base_commit" => change.base_commit, "member_id" => change.member_id },
29
- "meaning_kept" => true, "reason" => "", "old_line" => "", "new_line" => "" },
29
+ "response_template" => answer_to_fill(request_id:, change:, placeholders:),
30
30
  "answer_with" => @invocation.submit_answer(request_id) }
31
31
  end
32
32
 
33
+ # The answer to the request request_id names, to fill: the request prints it as response_template, and
34
+ # start-audit --member --as template prints it alone, each field the agent writes holding its placeholder (#773),
35
+ # and only those: the fields the answer may add, the question names (#1170).
36
+ #: (request_id: String, change: MemberChangeSinceBaseline, placeholders: Hash[String, untyped])
37
+ #| -> Hash[String, untyped]
38
+ def answer_to_fill(request_id:, change:, placeholders:)
39
+ { "request_id" => request_id, "basis" => { "member_id" => change.member_id }, **placeholders }
40
+ end
41
+
33
42
  # The acknowledgement was accepted and file holds it.
34
- #: (principle_id: String, member_id: String, file: String) -> Hash[String, untyped]
43
+ #: (principle_id: String, member_id: String, file: String) -> AnsweredRequest
35
44
  def acknowledged(principle_id:, member_id:, file:)
36
- { "status" => "acknowledged", "principle_id" => principle_id, "member_id" => member_id,
45
+ fields = {
46
+ "status" => "acknowledged", "principle_id" => principle_id, "member_id" => member_id,
37
47
  "files_to_commit" => [file],
38
48
  "next_action" => "Commit #{file}. #{member_id} reads as judged until it is edited again.\n" \
39
49
  "After committing, this no longer lists it: " \
40
- "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}" }
50
+ "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
51
+ }
52
+ AnsweredRequest.new(fields)
41
53
  end
42
54
  end
43
55
  end
@@ -0,0 +1,41 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "lines_shared_with_member"
5
+ require_relative "consecutive_sections_elsewhere"
6
+
7
+ module Principles
8
+ module Views
9
+ # The member just added: its id, current lines and check, beside its shared/consecutive location facts.
10
+ class AddedMember
11
+ #: (Hash[String, untyped], shared: LinesSharedWithMember, consecutive: ConsecutiveSectionsElsewhere) -> void
12
+ def initialize(added, shared:, consecutive:)
13
+ @added = added.merge(shared.to_h).merge(consecutive.to_h) #: Hash[String, untyped]
14
+ @shared = shared
15
+ @consecutive = consecutive
16
+ freeze
17
+ end
18
+
19
+ #: () -> String
20
+ def id = @added.fetch("id")
21
+
22
+ #: () -> Hash[String, untyped]
23
+ def to_h = @added
24
+
25
+ # The same location/remapping opening precedes the map's own after-add guidance.
26
+ #: () -> String
27
+ def opening
28
+ "#{span}#{@shared.note}#{@consecutive.note}Add the next member the same way. "
29
+ end
30
+
31
+ private
32
+
33
+ # The lines a member spans, said so that a passage cut short shows; it ends with a space.
34
+ #: () -> String
35
+ def span
36
+ "#{id} spans lines #{@added.fetch("first_line")} to #{@added.fetch("last_line")}; " \
37
+ "if that is not the passage you meant, move it with move-member. "
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ module Views
6
+ # An answered request's terminal result fields, with no further correction template to fill.
7
+ class AnsweredRequest
8
+ #: (Hash[String, untyped]) -> void
9
+ def initialize(fields)
10
+ @fields = fields
11
+ freeze
12
+ end
13
+
14
+ #: (AuditResult, String, String) -> Hash[String, untyped]
15
+ def presented_with(_view, _source_request_id, _answer_file) = @fields
16
+
17
+ #: (Hash[String, untyped], Invocation, String) -> Hash[String, untyped]
18
+ def with_correction_to_fill(acceptable, _invocation, _answer_file) = acceptable
19
+ end
20
+ end
21
+ end
@@ -12,7 +12,7 @@ module Principles
12
12
  class AssessedMembers
13
13
  # What the request shows of each member.
14
14
  SHOWN = %w[id role first_line last_line check check_since_last_audit check_hidden_characters
15
- acknowledged_since_last_audit carried_forward judge_because moved_from read_the_change
15
+ acknowledged_since_last_audit carried_forward open_finding_ids judge_because moved_from read_the_change
16
16
  mapped_elsewhere].freeze #: Array[String]
17
17
 
18
18
  # reviewed_check_placeholders is the text a checked member's template prints in each field it may leave as
@@ -34,9 +34,23 @@ module Principles
34
34
  freeze
35
35
  end
36
36
 
37
- # Each member as the request's context shows it, its fields in SHOWN's order.
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).
38
46
  #: () -> Array[Hash[String, untyped]]
39
- def shown = @members.map { |member| SHOWN.select { member.key?(it) }.to_h { [it, member[it]] } }
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
40
54
 
41
55
  # Each member's template entry: a fresh assessment to fill in, or, for a member whose last assessment is
42
56
  # carried forward, the marker that keeps it (D49); either with its check's result when it has a check.
@@ -58,29 +72,48 @@ module Principles
58
72
  #: () -> bool
59
73
  def checked? = @members.any? { |member| member["check"] }
60
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
+
61
81
  # Whether the request carries any member's last assessment forward (D49).
62
82
  #: () -> bool
63
83
  def carried_forward? = @members.any? { |member| member["carried_forward"] }
64
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
+
65
93
  # Each reason a member is judged afresh, once (D61).
66
94
  #: () -> Array[String]
67
95
  def judge_because = @members.filter_map { |member| member["judge_because"] }.uniq
68
96
 
69
97
  # Each entry naming another principle's role for a member's lines (#719).
70
98
  #: () -> Array[Hash[String, untyped]]
71
- def mapped_elsewhere = @members.flat_map { |member| member["mapped_elsewhere"] || [] }
99
+ def mapped_elsewhere = shown.flat_map { |member| member["mapped_elsewhere"] || [] }
72
100
 
73
101
  private
74
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
+
75
111
  #: (Hash[String, untyped]) -> Hash[String, untyped]
76
112
  def template(member)
77
113
  assessed = member["carried_forward"] ? carried(member) : fresh(member)
78
- check = member["check"] or return assessed
79
- template = CheckResultTemplate.new(check, member["check_since_last_audit"],
80
- member.fetch("check_hidden_characters", []),
81
- reviewed_placeholders: @reviewed_check_placeholders,
82
- unchanged_placeholders: @unchanged_check_placeholders)
83
- assessed.merge("check_result" => template.to_h)
114
+ template = CheckResultTemplate.for(member, reviewed_placeholders: @reviewed_check_placeholders,
115
+ unchanged_placeholders: @unchanged_check_placeholders)
116
+ template ? assessed.merge("check_result" => template) : assessed
84
117
  end
85
118
 
86
119
  #: (Hash[String, untyped]) -> Hash[String, untyped]
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "answer_head"
5
5
  require_relative "assessed_members"
6
+ require_relative "instruction"
6
7
  require_relative "prompts"
7
8
  require_relative "request_parts"
8
9
 
@@ -14,12 +15,24 @@ module Principles
14
15
  class AssessmentRequest
15
16
  # The recent_decision the request's template prints, which names the other form in the guide beside it.
16
17
  IN_GUIDE = {
17
- "unavailable_reason" => "Or use the assessed shape in answer_guide.recent_decision."
18
+ "unavailable_reason" => "Or replace this object with answer_guide.recent_decision.examples.assessed " \
19
+ "as copy_from says."
18
20
  }.freeze #: Hash[String, String]
21
+ # How mapped_elsewhere_instruction's paragraph on open findings elsewhere begins, which prints only when an
22
+ # entry names one (#808).
23
+ OPEN_FINDINGS_ELSEWHERE = "Where an entry names `open_finding_ids`" #: String
19
24
 
20
- # The question every member's assessment answers, which a completed record digests with the description (D49).
25
+ # The question every member's assessment answers, which a completed record digests with the description (D49):
26
+ # the whole question, what observed means too, however much of it a request prints (#983).
21
27
  #: () -> String
22
- def self.question = Prompts.text("assess-every-member/assess-each-member-and-the-set")
28
+ def self.question = question_paragraphs.join(" ")
29
+
30
+ # The question's two parts: what to assess, and what observed means, which only a member judged afresh needs.
31
+ #: () -> [String, String]
32
+ def self.question_paragraphs
33
+ [Prompts.text("assess-every-member/assess-each-member-and-the-set"),
34
+ Prompts.text("assess-every-member/say-what-observed-means")]
35
+ end
23
36
 
24
37
  # principle is the principle_id and description it names. head is what the answer hands back unchanged: the
25
38
  # request's id and its basis, the base commit and the last completed record's revision. parts are what the
@@ -50,6 +63,23 @@ module Principles
50
63
  @parts.shown_after(listed).merge(asked)
51
64
  end
52
65
 
66
+ # The fields the request prints an instruction under, in the order it prints them: the question, the answer
67
+ # guide and each field named for an instruction (D81 step 2).
68
+ #: () -> Array[String]
69
+ def instruction_fields = printed_instructions.map(&:field)
70
+
71
+ # The principle the request audits.
72
+ #: () -> String
73
+ def principle_id = @principle.fetch("principle_id")
74
+
75
+ # The instruction fields the request prints only in part, leaving out paragraphs for cases it does not hold.
76
+ #: () -> Array[String]
77
+ def trimmed_instruction_fields = printed_instructions.select(&:trimmed?).map(&:field)
78
+
79
+ # The instruction field whole: every paragraph, the ones for cases the request does not hold too.
80
+ #: (String) -> untyped
81
+ def whole_instruction(field) = printed_instructions.find { it.field == field }&.whole
82
+
53
83
  # The answer to fill in: one assessment per member, and the set's.
54
84
  #: () -> Hash[String, untyped]
55
85
  def template
@@ -77,56 +107,86 @@ module Principles
77
107
  "recent_decision" => recent_decision, "findings" => [] }
78
108
  end
79
109
 
80
- # What the request asks of what the agent read: the question, why members are judged afresh, how to treat the
81
- # members it carries forward and the roles other principles give their lines, and the guide to the answer's
82
- # shapes.
110
+ # The instructions the request prints, in order: each part's, after its list, then its own.
111
+ #: () -> Array[Instruction | GuideInstruction]
112
+ def printed_instructions = [*@parts.instructions, *instructions].reject { it.printed.empty? }
113
+
114
+ # What the request asks of what the agent read, each of its own instructions as the request prints it.
83
115
  #: () -> Hash[String, untyped]
84
- def asked
85
- { "question" => AssessmentRequest.question }.merge(judge_because_instruction, carried_forward_instruction,
86
- mapped_elsewhere_instruction)
87
- .merge("answer_guide" => answer_guide)
116
+ def asked = instructions.reduce({}) { |all, instruction| all.merge(instruction.printed) }
117
+
118
+ # The request's own instructions: the question, why members are judged afresh, how to treat the members it
119
+ # carries forward and the roles other principles give their lines, and the guide to the answer's shapes.
120
+ #: () -> Array[Instruction | GuideInstruction]
121
+ def instructions
122
+ [question, judge_because_instruction,
123
+ carried_forward_instruction, mapped_elsewhere_instruction, answer_guide]
124
+ end
125
+
126
+ # The question, defining observed only when a member is judged afresh, whose delivery it guides (#983).
127
+ #: () -> Instruction
128
+ def question
129
+ assess, observed = AssessmentRequest.question_paragraphs
130
+ Instruction.new("question", [[assess, true], [observed, @members.judged_afresh?]])
88
131
  end
89
132
 
90
133
  # Why each member with judge_because is judged afresh, explaining only the values the members carry, so the
91
134
  # agent meets each value's meaning where it meets the value (D61); nothing when no member gives one.
92
- #: () -> Hash[String, untyped]
135
+ #: () -> Instruction
93
136
  def judge_because_instruction
94
137
  reasons = @members.judge_because
95
- return {} if reasons.empty?
96
-
97
- intro, *meanings = Prompts.text("assess-every-member/why-each-member-is-judged-again").split("\n\n")
98
- shown = meanings.select { |meaning| reasons.any? { |reason| meaning.start_with?("`#{reason}`:") } }
99
- { "judge_because_instruction" => [intro, *shown].join("\n\n") }
138
+ text = Prompts.text("assess-every-member/why-each-member-is-judged-again")
139
+ Instruction.of_paragraphs("judge_because_instruction", text) do |paragraph|
140
+ reasons.any? && (!paragraph.start_with?("`") || reasons.any? { paragraph.start_with?("`#{it}`:") })
141
+ end
100
142
  end
101
143
 
102
144
  # How to judge the roles other principles give a member's lines, printed only when a member shares lines with
103
145
  # another principle's (#719, D61), and, when an entry names findings open on its member, where to read how to
104
146
  # treat them, which prints apart, before the question (#808).
105
- #: () -> Hash[String, untyped]
147
+ #: () -> Instruction
106
148
  def mapped_elsewhere_instruction
107
149
  entries = @members.mapped_elsewhere
108
- return {} if entries.empty?
109
-
110
- roles, open_findings = Prompts.text("assess-every-member/check-roles-other-principles-give-these-lines")
111
- .split("\n\n")
112
- shown = entries.any? { |entry| entry["open_finding_ids"] } ? [roles, open_findings] : [roles]
113
- { "mapped_elsewhere_instruction" => shown.join("\n\n") }
150
+ open = entries.any? { |entry| entry["open_finding_ids"] }
151
+ text = Prompts.text("assess-every-member/check-roles-other-principles-give-these-lines")
152
+ Instruction.of_paragraphs("mapped_elsewhere_instruction", text) do |paragraph|
153
+ entries.any? && (open || !paragraph.start_with?(OPEN_FINDINGS_ELSEWHERE))
154
+ end
114
155
  end
115
156
 
116
- # The answer guide, showing the check result's shapes only when a member has a check, so an audit
117
- # with no checks costs no more context than before (D30).
118
- #: () -> Hash[String, untyped]
157
+ # The answer guide, showing check_result's fields only when a member has a check, so an audit
158
+ # with no checks costs no more context than before (D30), and delivery's shapes only when a member is judged
159
+ # afresh, since a carried member's marker gives none (#983). check_result's limits say how to review a check
160
+ # before running it only when a check is new or changed, as that check's own template says too (#983).
161
+ #: () -> GuideInstruction
119
162
  def answer_guide
120
163
  guide = Prompts.data("assess-every-member/answer-guide")
121
- @members.checked? ? guide : guide.except("check_result")
164
+ narrowed = @members.check_to_review? ? {} : guide.slice("check_result")
165
+ GuideInstruction.new("answer_guide", guide.merge("check_result" => reviewed(guide.fetch("check_result"))),
166
+ narrowed:) do |entry|
167
+ case entry
168
+ when "check_result" then @members.checked?
169
+ when "member_delivery" then @members.judged_afresh?
170
+ else true
171
+ end
172
+ end
173
+ end
174
+
175
+ # check_result's guide entry whole, its limits ending with how to review a new or changed check before running it.
176
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
177
+ def reviewed(check_result)
178
+ review = Prompts.text("assess-every-member/review-a-new-or-changed-check-before-running-it")
179
+ check_result.merge("limits" => "#{check_result.fetch("limits")} #{review}")
122
180
  end
123
181
 
124
182
  # How to answer when the request carries some members' last assessments forward; nothing when it carries none.
125
- #: () -> Hash[String, untyped]
183
+ # What a compact carried member shows, and what prints one whole, only when one prints compactly (#983).
184
+ #: () -> Instruction
126
185
  def carried_forward_instruction
127
- return {} unless @members.carried_forward?
128
-
129
- { "carried_forward_instruction" => Prompts.text("assess-every-member/judge-the-set-with-carried-assessments") }
186
+ carry = Prompts.text("assess-every-member/judge-the-set-with-carried-assessments")
187
+ compact = Prompts.text("assess-every-member/read-a-compact-carried-member")
188
+ Instruction.new("carried_forward_instruction",
189
+ [[carry, @members.carried_forward?], [compact, @members.carried_compactly?]])
130
190
  end
131
191
  end
132
192
  end
@@ -1,7 +1,9 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../prose_list"
4
5
  require_relative "assessment_request"
6
+ require_relative "answered_request"
5
7
  require_relative "audit_changes"
6
8
  require_relative "correction_request"
7
9
  require_relative "invocation"
@@ -24,25 +26,16 @@ module Principles
24
26
  end
25
27
 
26
28
  # An answer's result as submit-answer prints it: a correction request in full, with how to answer it.
27
- #: (Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
28
- def present(output)
29
- output = correction_request(output) if output.is_a?(CorrectionRequest)
30
- output["status"] == "agent_judgement_required" ? request(output) : output
29
+ #: (AnsweredRequest | CorrectionRequest, source_request_id: String, answer_file: String)
30
+ #| -> Hash[String, untyped]
31
+ def present(output, source_request_id:, answer_file:)
32
+ output.presented_with(self, source_request_id, answer_file)
31
33
  end
32
34
 
33
- # show-answer-check's acceptable result, with the correction's answer an accepted assessment leads to, alone, to
34
- # save and fill, and how to submit it after the assessment, which outside git writes the open record it is
35
- # checked against; next_action still ends with the checked answer's submit command (#859). The result is
36
- # unchanged for any other answer (D81 step 3).
37
- #: (Hash[String, untyped], Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
38
- def with_correction_to_fill(acceptable, output)
39
- return acceptable unless output.is_a?(CorrectionRequest)
40
-
41
- save = "Once this answer is submitted with the last line's command, save correction_template, the " \
42
- "correction's answer it leads to, to a file outside the project, such as under $TMPDIR, fill only " \
43
- "its dispositions, and submit it: #{@invocation.submit_answer(output.request_id)}"
44
- acceptable.merge("correction_template" => output.template,
45
- "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
35
+ # A correction request adds its answer to fill; a terminal result leaves the acceptable preview alone.
36
+ #: (Hash[String, untyped], AnsweredRequest | CorrectionRequest, answer_file: String) -> Hash[String, untyped]
37
+ def with_correction_to_fill(acceptable, output, answer_file:)
38
+ output.with_correction_to_fill(acceptable, @invocation, answer_file)
46
39
  end
47
40
 
48
41
  # show-answer-check: the answer passed every check, and what submitting it would write. open_findings_will_print
@@ -61,10 +54,17 @@ module Principles
61
54
  result.merge("next_action" => "#{waits}Submit the same answer unchanged, as you gave it: #{submit}")
62
55
  end
63
56
 
64
- # start-audit: the assessment request, as a judgement to answer under its request id.
57
+ # start-audit: the assessment request, as a judgement to answer under its request id, its context naming the
58
+ # instructions it prints only in part and the flag that prints one whole, so a trimmed field is not taken for
59
+ # the whole (#983), without the command the agent just ran (#1125).
65
60
  #: (AssessmentRequest) -> Hash[String, untyped]
66
61
  def assessment_request(request)
67
- judgement("assessment", request)
62
+ output = judgement("assessment", request)
63
+ trimmed = request.trimmed_instruction_fields
64
+ return output if trimmed.empty?
65
+
66
+ note = Prompts.text("assess-every-member/read-a-trimmed-instruction-whole", fields: ProseList.new(trimmed).to_s)
67
+ output.merge("context" => output.fetch("context").merge("trimmed_instructions" => note))
68
68
  end
69
69
 
70
70
  # start-audit --as template: the assessment's answer alone, to fill and submit (D81 step 1).
@@ -73,9 +73,11 @@ module Principles
73
73
 
74
74
  # submit-answer: the correction request that follows an assessment with findings, as a judgement to answer
75
75
  # under its request id, saying what submitting the assessment stored.
76
- #: (CorrectionRequest) -> Hash[String, untyped]
77
- def correction_request(request)
78
- judgement("correction", request).merge("stored" => request.stored)
76
+ #: (CorrectionRequest, source_request_id: String, answer_file: String) -> Hash[String, untyped]
77
+ def correction_request(request, source_request_id:, answer_file:)
78
+ judgement("correction", request).merge("stored" => request.stored,
79
+ "correction_recovery" => request.recovery(source_request_id, answer_file,
80
+ @invocation))
79
81
  end
80
82
 
81
83
  # A completed audit: its resolved and open findings, the files to commit and, in git, each changed
@@ -97,12 +99,28 @@ module Principles
97
99
  "full_record" => @invocation.in_project("show-audit", principle_id))
98
100
  end
99
101
 
102
+ # completed, a completed audit's result, offering to set principles up after its next_action, as it does
103
+ # while nothing keeps them held between audits (D95).
104
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
105
+ def offering_set_up(completed)
106
+ offer = Prompts.text("set-principles-up/keep-them-held-between-audits",
107
+ command: @invocation.in_project("show-meta-principle-passage"))
108
+ completed.merge("next_action" => "#{completed.fetch("next_action")}\n#{offer}")
109
+ end
110
+
100
111
  # The notice start-audit adds when the last audit's record is not committed.
101
112
  #: (String) -> String
102
113
  def uncommitted_record_notice(file)
103
114
  "The last audit's record, #{file}, is not committed. Commit it, so the project keeps it."
104
115
  end
105
116
 
117
+ # Wraps a known judgement request with this run's project and answer command.
118
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
119
+ def request(output)
120
+ submit = @invocation.submit_answer(output.fetch("request_id"))
121
+ output.merge("project" => @invocation.project, "answer_with" => submit)
122
+ end
123
+
106
124
  private
107
125
 
108
126
  # request as a judgement to answer in phase, under its id, which its template's head also gives.
@@ -113,12 +131,6 @@ module Principles
113
131
  "limits" => Prompts.text("answer-any-judgement-request/what-a-self-audit-cannot-show") }
114
132
  end
115
133
 
116
- #: (Hash[String, untyped]) -> Hash[String, untyped]
117
- def request(output)
118
- submit = @invocation.submit_answer(output.fetch("request_id"))
119
- output.merge("project" => @invocation.project, "answer_with" => submit)
120
- end
121
-
122
134
  # A completed audit's next step, from what it changed and how to commit it.
123
135
  #: (String, AuditChanges, AuditCommit | AuditCommit::ByHand) -> String
124
136
  def completed_next_action(id, changes, commit)