principles 0.0.4 → 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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +3 -1
  3. data/lib/principles/command_line.rb +35 -7
  4. data/lib/principles/command_routes.rb +4 -3
  5. data/lib/principles/controllers/acknowledgement.rb +80 -14
  6. data/lib/principles/controllers/answer.rb +42 -75
  7. data/lib/principles/controllers/answer_phase.rb +54 -0
  8. data/lib/principles/controllers/assessment.rb +33 -9
  9. data/lib/principles/controllers/audit.rb +17 -6
  10. data/lib/principles/controllers/audit_completion.rb +6 -4
  11. data/lib/principles/controllers/command.rb +3 -2
  12. data/lib/principles/controllers/correction.rb +19 -9
  13. data/lib/principles/controllers/full_audit_request.rb +10 -0
  14. data/lib/principles/controllers/inventory.rb +25 -20
  15. data/lib/principles/controllers/member_problems_report.rb +11 -4
  16. data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
  17. data/lib/principles/controllers/members_to_assess.rb +20 -12
  18. data/lib/principles/controllers/repoint.rb +18 -22
  19. data/lib/principles/data/bounded_file.rb +9 -4
  20. data/lib/principles/data/command-steps.json +9 -9
  21. data/lib/principles/data/project_files.rb +11 -8
  22. data/lib/principles/data/schema_check.rb +16 -6
  23. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
  24. data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
  25. data/lib/principles/data/schemas/audit-record.schema.json +10 -1
  26. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  27. data/lib/principles/invocation_options.rb +1 -1
  28. data/lib/principles/models/acknowledgement.rb +73 -84
  29. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  30. data/lib/principles/models/answer_place.rb +4 -0
  31. data/lib/principles/models/assessment_answer.rb +0 -45
  32. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  33. data/lib/principles/models/audit_record.rb +9 -17
  34. data/lib/principles/models/audit_records.rb +19 -16
  35. data/lib/principles/models/candidate_files.rb +30 -7
  36. data/lib/principles/models/candidate_inventory.rb +23 -6
  37. data/lib/principles/models/candidate_listing.rb +12 -3
  38. data/lib/principles/models/candidate_outline.rb +195 -0
  39. data/lib/principles/models/carried_member.rb +42 -0
  40. data/lib/principles/models/check_since_last_audit.rb +16 -3
  41. data/lib/principles/models/command_steps.rb +17 -1
  42. data/lib/principles/models/declared_map_changes.rb +5 -4
  43. data/lib/principles/models/frontmatter_fields.rb +9 -8
  44. data/lib/principles/models/instruction_named.rb +35 -0
  45. data/lib/principles/models/left_as_printed.rb +39 -0
  46. data/lib/principles/models/member_assessments.rb +9 -31
  47. data/lib/principles/models/member_file.rb +35 -11
  48. data/lib/principles/models/member_hashes_as_written.rb +10 -6
  49. data/lib/principles/models/member_lines.rb +63 -15
  50. data/lib/principles/models/member_problems.rb +24 -18
  51. data/lib/principles/models/member_repair_moves.rb +54 -0
  52. data/lib/principles/models/missing_files.rb +2 -2
  53. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  54. data/lib/principles/models/other_templates_placeholders.rb +81 -42
  55. data/lib/principles/models/outline_budget.rb +127 -0
  56. data/lib/principles/models/outline_group.rb +31 -0
  57. data/lib/principles/models/outline_section.rb +56 -0
  58. data/lib/principles/models/principle_members.rb +11 -0
  59. data/lib/principles/models/prior_decision_fields.rb +3 -2
  60. data/lib/principles/models/prior_finding_decision.rb +14 -4
  61. data/lib/principles/models/project.rb +10 -19
  62. data/lib/principles/models/quoted_change.rb +137 -0
  63. data/lib/principles/models/record_format.rb +6 -2
  64. data/lib/principles/models/recorded_entry.rb +6 -0
  65. data/lib/principles/models/recorded_hashes.rb +7 -3
  66. data/lib/principles/models/recorded_members.rb +27 -15
  67. data/lib/principles/models/refusal_before_shape.rb +21 -0
  68. data/lib/principles/models/repoint.rb +13 -0
  69. data/lib/principles/models/reported_check.rb +3 -13
  70. data/lib/principles/models/sent_answer.rb +51 -0
  71. data/lib/principles/models/shape_problems_beside.rb +40 -0
  72. data/lib/principles/models/submitted_answer.rb +34 -0
  73. data/lib/principles/models/template_placeholders.rb +34 -4
  74. data/lib/principles/models/text_within.rb +55 -0
  75. data/lib/principles/models/unchecked_members.rb +76 -0
  76. data/lib/principles/models/write_up_opening.rb +21 -4
  77. data/lib/principles/session_start_options.rb +2 -2
  78. data/lib/principles/start_audit_options.rb +19 -4
  79. data/lib/principles/version.rb +2 -2
  80. data/lib/principles/views/acknowledgement_result.rb +15 -7
  81. data/lib/principles/views/assessed_members.rb +43 -10
  82. data/lib/principles/views/assessment_request.rb +89 -30
  83. data/lib/principles/views/audit_result.rb +19 -2
  84. data/lib/principles/views/candidate_files_result.rb +41 -19
  85. data/lib/principles/views/check_notes.rb +44 -0
  86. data/lib/principles/views/check_result_template.rb +14 -23
  87. data/lib/principles/views/instruction.rb +74 -0
  88. data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
  89. data/lib/principles/views/loads_to_check_result.rb +2 -2
  90. data/lib/principles/views/map_result.rb +2 -2
  91. data/lib/principles/views/member_change_since_baseline.rb +22 -5
  92. data/lib/principles/views/member_repairs.rb +21 -52
  93. data/lib/principles/views/members_a_commit_changed.rb +16 -6
  94. data/lib/principles/views/one_member_check_result_template.rb +43 -0
  95. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  96. data/lib/principles/views/open_findings_line.rb +77 -23
  97. data/lib/principles/views/principle_read_result.rb +20 -28
  98. data/lib/principles/views/prior_findings_result.rb +23 -15
  99. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  100. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  101. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
  102. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  103. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  104. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
  105. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  106. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  107. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  108. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  109. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  110. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  111. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +4 -3
  112. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  113. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  114. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
  115. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  116. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  117. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  118. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +21 -6
  119. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +4 -4
  120. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  121. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
  122. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +1 -1
  123. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
  124. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
  125. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +3 -3
  126. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  127. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  128. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  129. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
  130. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  131. data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
  132. data/lib/principles/views/request_part.rb +16 -8
  133. data/lib/principles/views/request_parts.rb +4 -0
  134. metadata +39 -5
  135. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  136. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
  137. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96ca8d7922a17170882557d15e04abea9f3bea70aab25a22f50bdd9c9125011e
4
- data.tar.gz: cf55a17d354871a0db2753cce1073594e934438b6f8d1927580490923f29219e
3
+ metadata.gz: 40e41136c5be852cc2019089d41ab1548144e52138ab51c80211befe32bfa411
4
+ data.tar.gz: 3d7d56d9ba40d0678e39fcd4b7f6ecca2b231ac5b449f07af84617b8e0ad1a91
5
5
  SHA512:
6
- metadata.gz: cc665678840f9e2623292feec10931656a3408e493cce68832e7d68cdbffebdae9fe227191bac8a439b0dd1f9df68da62cc0b7106e498d3f3a54faf6471a2f3e
7
- data.tar.gz: 3bf529373932b7ef4230d417d9b6bb10fe78f7fff3152c1648b5f291f94312dfcc9776d08567424e7cbe49602d390c105cc9a19056b74f776adf4d25742582ab
6
+ metadata.gz: ff6dd21e3e9a0e929ae135aaaa587b8781e6bea67ac6547fa8b23ce43d15a75d05a3c9490eaecf1049d76384df1e39eb7e5d6c0605a883dc67ff5051b308f12b
7
+ data.tar.gz: cd61142617ebf7f28eba7b2ae5bc89e1dd18d745fb8d9c763bacf68c6e2dacc7a5cc5f66869c0bf4da24d584134612b4f9ae52a63d682931c342a96217476bb0
@@ -117,9 +117,11 @@ module Principles
117
117
  end
118
118
  end
119
119
 
120
- # A result prints as JSON, or as lines with their own exit status, as list-member-problems --short does.
120
+ # A result prints as JSON, as JSON laid out with one entry a line, as list-candidate-files does, or as lines with
121
+ # their own exit status, as list-member-problems --short does.
121
122
  #: (untyped) -> Integer
122
123
  def printed_result(result)
124
+ return printed(visible(result.text)) if result.is_a?(Views::JsonWithEntriesOnLines)
123
125
  return printed(visible(JSON.pretty_generate(result))) unless result.is_a?(Views::Lines)
124
126
 
125
127
  @stdout.print(result.stdout)
@@ -7,11 +7,15 @@ require_relative "after_commit_hook_options"
7
7
  require_relative "session_start_options"
8
8
  require_relative "start_audit_options"
9
9
  require_relative "models/command_steps"
10
+ require_relative "prose_list"
10
11
 
11
12
  module Principles
12
13
  # One invocation's words: the command, its positional arguments and its options, refused with an
13
14
  # OptionParser error when they do not fit what the command takes. CLI decides what to run from it.
14
15
  class CommandLine
16
+ # How a refusal names each option a command requires.
17
+ REQUIRED_OPTION_WORDS = { "file" => "--file FILE, or --file - for stdin" }.freeze #: Hash[String, String]
18
+
15
19
  # argv is parsed at once; positional names each command's positional arguments, in order; executable is the
16
20
  # invocation a refusal tells the agent to run --help with (#562).
17
21
  #: (Array[String], positional: Hash[String, Array[String]], executable: String) -> void
@@ -62,18 +66,16 @@ module Principles
62
66
  raise OptionParser::InvalidArgument, "unknown command #{name}"
63
67
  end
64
68
 
65
- # Refuses the wrong number of arguments, an option the command does not take or given an option as its value,
66
- # and an answer command without --file.
69
+ # Refuses every missing argument at once, too many arguments, an option the command does not take or given an
70
+ # option as its value.
67
71
  #: () -> void
68
72
  def check
69
73
  name = command.to_s
74
+ check_missing(name)
70
75
  check_arguments(name)
71
76
  check_options(name)
72
77
  check_values_are_not_options(name)
73
78
  check_combined_options(name)
74
- return unless %w[submit-answer show-answer-check].include?(name) && !@options.value("file")
75
-
76
- raise OptionParser::MissingArgument, "#{name} needs --file FILE, or --file - for stdin"
77
79
  end
78
80
 
79
81
  # The principle id, for a command whose first argument is one.
@@ -102,9 +104,31 @@ module Principles
102
104
  @arguments.drop(1)
103
105
  end
104
106
 
107
+ # Each argument the command needs and was not given, named in one refusal: an agent that met one refusal per
108
+ # missing argument repaired them one at a time (#1083). Each option command-steps.json says it requires is one.
109
+ #: (String) -> void
110
+ def check_missing(name)
111
+ missing = missing_arguments + missing_options(name)
112
+ return if missing.empty?
113
+
114
+ raise OptionParser::MissingArgument, "#{name} needs #{ProseList.new(missing)}"
115
+ end
116
+
117
+ # The positional arguments the command needs past those given, as usage names them.
118
+ #: () -> Array[String]
119
+ def missing_arguments = names.drop(values.length).reject { |each| each.end_with?("?") }.map(&:upcase)
120
+
121
+ # The options command name requires and was not given, as a refusal names them.
122
+ #: (String) -> Array[String]
123
+ def missing_options(name)
124
+ required = steps(name)&.requires || []
125
+ required.reject { |option| @options.value(option) }.map { |option| REQUIRED_OPTION_WORDS.fetch(option) }
126
+ end
127
+
128
+ # Too many arguments; check_missing has refused too few.
105
129
  #: (String) -> void
106
130
  def check_arguments(name)
107
- return if values.length.between?(names.count { |each| !each.end_with?("?") }, names.length)
131
+ return if values.length <= names.length
108
132
 
109
133
  takes = "#{name} takes #{shown_arguments}".strip.sub(/ takes\z/, " takes no arguments")
110
134
  raise OptionParser::InvalidArgument, takes
@@ -119,7 +143,7 @@ module Principles
119
143
  # An option a command does not take is refused, so a mistyped command never runs as something else.
120
144
  #: (String) -> void
121
145
  def check_options(name)
122
- taken = Models::CommandSteps.load.command(name)&.options || []
146
+ taken = steps(name)&.options || []
123
147
  unknown = (@options.given - taken - ["project"]).map { |option| "--#{option}" }
124
148
  return if unknown.empty?
125
149
 
@@ -165,6 +189,10 @@ module Principles
165
189
  #: (Array[String]) -> String?
166
190
  def named_command(argv) = argv.find { |word| @positional.key?(word) }
167
191
 
192
+ # What command-steps.json says of the command name, or nil for a name it does not list.
193
+ #: (String) -> Models::CommandSteps::Command?
194
+ def steps(name) = Models::CommandSteps.load.command(name)
195
+
168
196
  #: (String) -> String
169
197
  def help_repair(name) = "To see what it takes: #{@executable} #{name} --help"
170
198
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "controllers/inventory"
5
+ require_relative "controllers/member_problems_report"
5
6
  require_relative "controllers/mapping"
6
7
  require_relative "controllers/meta_principle_setup"
7
8
  require_relative "controllers/member_entries"
@@ -32,7 +33,7 @@ module Principles
32
33
  ROUTES = {
33
34
  "list-candidate-files" => Route.new(Controllers::Inventory, []),
34
35
  "list-principles" => Route.new(Controllers::Inventory, []),
35
- "list-member-problems" => Route.new(Controllers::Inventory, %w[id?]),
36
+ "list-member-problems" => Route.new(Controllers::MemberProblemsReport, %w[id?]),
36
37
  "show-principle" => Route.new(Controllers::Inventory, %w[id]),
37
38
  "show-audit" => Route.new(Controllers::Audit, %w[id]),
38
39
  "list-open-findings" => Route.new(Controllers::Audit, %w[id?]),
@@ -47,8 +48,8 @@ module Principles
47
48
  "remove-member-check" => Route.new(Controllers::MemberEntries, %w[id member]),
48
49
  "remove-member" => Route.new(Controllers::MemberEntries, %w[id member]),
49
50
  "start-audit" => Route.new(Controllers::Audit, %w[id]),
50
- "submit-answer" => Route.new(Controllers::Answer, %w[id]),
51
- "show-answer-check" => Route.new(Controllers::Answer, %w[id])
51
+ "submit-answer" => Route.new(Controllers::Answer, %w[request_id]),
52
+ "show-answer-check" => Route.new(Controllers::Answer, %w[request_id])
52
53
  }.freeze #: Hash[String, Route]
53
54
 
54
55
  # Each command's positional arguments, in order, as CommandLine takes them.
@@ -1,9 +1,13 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "json"
4
5
  require "time"
5
- require_relative "command"
6
+ require_relative "answer_phase"
6
7
  require_relative "../models/acknowledgement"
8
+ require_relative "../models/check_since_last_audit"
9
+ require_relative "../models/reported_check"
10
+ require_relative "../views/one_member_check_result_template"
7
11
  require_relative "../views/acknowledgement_result"
8
12
 
9
13
  module Principles
@@ -12,25 +16,35 @@ module Principles
12
16
  module Controllers
13
17
  # A one-member audit (D33): start-audit ID --member MEMBER asks whether a committed change keeps that member's
14
18
  # meaning, and submit-answer moves its baseline in the audit record when the answer holds.
15
- class Acknowledgement < Command
19
+ class Acknowledgement < AnswerPhase
16
20
  # The request for principle id's member.
17
21
  #: (String, String) -> Hash[String, untyped]
18
22
  def start(id, member_id)
19
23
  naming_the_executable(rerun: one_member_audit(id)) do
20
- acknowledgement, member, base = prepared(id, member_id)
21
- baseline, lines = since_baseline(id, acknowledgement, member)
22
- change = Views::MemberChangeSinceBaseline.new(
23
- member: shown(acknowledgement, member, baseline), member_lines: lines.shown,
24
- commits: commits(acknowledgement, baseline, base), paths: acknowledgement.paths_since(baseline)
25
- )
24
+ acknowledgement, change, check_result = asked(id, member_id)
26
25
  view.request(request_id: acknowledgement.request_id.to_s, principle_id: id, change: change,
27
- open_findings: acknowledgement.open_findings).merge("wrote" => [])
26
+ open_findings: acknowledgement.open_findings, placeholders: placeholders(check_result, change))
27
+ .merge("wrote" => [])
28
28
  end
29
29
  end
30
30
 
31
- # The result of answering request_id with response, and the record it changes, not yet written.
32
- #: (Models::RequestId, untyped) -> [Hash[String, untyped], Array[Models::AuditRecord]]
33
- def answered(request_id, response)
31
+ # The answer alone, as start-audit --member --as template prints it, to fill and submit under the request's id
32
+ # (#773).
33
+ #: (String, String) -> Hash[String, untyped]
34
+ def to_fill(id, member_id)
35
+ naming_the_executable(rerun: one_member_audit(id)) do
36
+ acknowledgement, change, check_result = asked(id, member_id)
37
+ view.answer_to_fill(request_id: acknowledgement.request_id.to_s, change: change,
38
+ placeholders: placeholders(check_result, change))
39
+ end
40
+ end
41
+
42
+ # The result of answering, and the record it changes, not yet written.
43
+ # @override
44
+ #: (Models::SubmittedAnswer) -> [Hash[String, untyped], Array[Models::AuditRecord]]
45
+ def answered(submitted)
46
+ request_id = submitted.request_id
47
+ response = submitted.response
34
48
  id = request_id.principle_id
35
49
  acknowledgement, member, = prepared(id, response.fetch("basis").fetch("member_id"))
36
50
  stale(id, member.id) unless acknowledgement.request_id.to_s == request_id.to_s
@@ -38,8 +52,59 @@ module Principles
38
52
  [accepted(id, acknowledgement, member, response)]]
39
53
  end
40
54
 
55
+ # The refusals an answer meets before its shape: any phase's, then a placeholder its template printed left in,
56
+ # which the shape would refuse in meaning_kept without naming it (#773).
57
+ #: (Models::RequestId) -> Array[Models::RefusalBeforeShape]
58
+ def before_shape(request_id) = [*super, Models::Acknowledgement::PLACEHOLDERS]
59
+
41
60
  private
42
61
 
62
+ # The placeholders a one-member audit's template prints, which its answer may leave as printed: its own, and
63
+ # check_result's for a check the last audit ran, the only check it acknowledges (#1112). The member is in the
64
+ # answer, not the request id, so this names the check's whether the member has one.
65
+ # @override
66
+ #: (Models::RequestId) -> Hash[String, untyped]?
67
+ def printed_placeholders(_request_id) = placeholders(Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h)
68
+
69
+ # The acknowledgement of principle id's member, its change since its baseline, as the request shows it, and the
70
+ # check_result its answer fills, if the member has a check.
71
+ #: (String, String) -> [Models::Acknowledgement, Views::MemberChangeSinceBaseline, Hash[String, untyped]?]
72
+ def asked(id, member_id)
73
+ acknowledgement, member, base = prepared(id, member_id)
74
+ baseline, lines = since_baseline(id, acknowledgement, member)
75
+ check_result = check_template(id, member)
76
+ [acknowledgement,
77
+ Views::MemberChangeSinceBaseline.new(
78
+ member: shown(acknowledgement, member, baseline), member_lines: lines.shown(taken: bytes_of(check_result)),
79
+ first_changed_lines: acknowledgement.first_changed_lines(lines),
80
+ commits: commits(acknowledgement, baseline, base), paths: acknowledgement.paths_since(baseline)
81
+ ), check_result]
82
+ end
83
+
84
+ # The bytes check_result takes as the request prints it, which the member's lines give up (#1119).
85
+ #: (Hash[String, untyped]?) -> Integer
86
+ def bytes_of(check_result) = check_result ? JSON.pretty_generate(check_result).bytesize : 0
87
+
88
+ # The text the template prints in each field the agent writes: its judgement's placeholders, the quotes as the
89
+ # change's first_changed_lines hints them (#1111), and check_result's for a checked member.
90
+ #: (Hash[String, untyped]?, ?Views::MemberChangeSinceBaseline?) -> Hash[String, untyped]
91
+ def placeholders(check_result, change = nil)
92
+ quotes = change&.first_changed_lines.to_h
93
+ { **Models::Acknowledgement.placeholders_beside(quotes), **quotes,
94
+ **(check_result ? { "check_result" => check_result } : {}) }
95
+ end
96
+
97
+ # The check_result a checked member's answer fills, for the check the last audit ran, which a one-member audit
98
+ # requires (D30, D63, #1071), asking for a passing run alone (#1112); nil for a member without a check.
99
+ #: (String, Models::Member) -> Hash[String, untyped]?
100
+ def check_template(id, member)
101
+ checks = Models::CheckSinceLastAudit.new(id:, history: @history, principles: @principles,
102
+ record: @audit_records.find(id))
103
+ Views::OneMemberCheckResultTemplate.for(checks.entry(member),
104
+ review_basis:
105
+ Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.fetch("review_basis"))
106
+ end
107
+
43
108
  # The one-member audit of principle id's member, as a refusal naming a near miss leads its repair with (D56).
44
109
  #: (String) -> ^(String) -> String
45
110
  def one_member_audit(id)
@@ -50,14 +115,15 @@ module Principles
50
115
  #: (String, Models::Acknowledgement, Models::Member, untyped) -> Models::AuditRecord
51
116
  def accepted(id, acknowledgement, member, response)
52
117
  _baseline, lines = since_baseline(id, acknowledgement, member)
53
- acknowledgement.accepted(response, before: lines.at_baseline, now: lines.now, at: Time.now.utc.iso8601)
118
+ acknowledgement.accepted(response, lines, at: Time.now.utc.iso8601)
54
119
  end
55
120
 
56
121
  # The member as the request shows it, with where it was at its baseline when it has moved since (#547).
57
122
  #: (Models::Acknowledgement, Models::Member, Models::Placement) -> Hash[String, untyped]
58
123
  def shown(acknowledgement, member, baseline)
59
124
  moved_from = acknowledgement.moved_from(baseline)
60
- { "id" => member.id, "role" => member.role, "evidence" => [member.reference],
125
+ { "id" => member.id, "role" => member.role, **(member.check ? { "check" => member.check } : {}),
126
+ "evidence" => [member.reference],
61
127
  **(moved_from ? { "evidence_at_baseline" => [moved_from] } : {}) }
62
128
  end
63
129
 
@@ -3,14 +3,12 @@
3
3
 
4
4
  require_relative "command"
5
5
  require_relative "../models/finding_write_ups"
6
- require_relative "../models/audit"
7
6
  require_relative "../models/request_id"
7
+ require_relative "../models/submitted_answer"
8
8
  require_relative "acknowledgement"
9
9
  require_relative "correction"
10
10
  require_relative "repoint"
11
11
  require_relative "assessment"
12
- require_relative "full_audit_request"
13
- require_relative "../models/other_templates_placeholders"
14
12
 
15
13
  module Principles
16
14
  # Each runs one command: reads models, applies their rules and prints through a view.
@@ -20,13 +18,18 @@ module Principles
20
18
  # audit completes, writes the committed audit record. Nothing else is stored: each request id is a
21
19
  # digest of what the request depends on, so an answer is checked against the project as it is now (D25).
22
20
  class Answer < Command
21
+ # The controller that answers for each phase a request id may name.
22
+ PHASE_CONTROLLERS = {
23
+ "assessment" => Assessment, "correction" => Correction, "acknowledgement" => Acknowledgement,
24
+ "repointing" => Repoint
25
+ }.freeze #: Hash[String, Class[AnswerPhase]]
26
+
23
27
  #: (String, String?, Hash[String, untyped]) -> untyped
24
- def call(command, id, options)
28
+ def call(command, _id, options)
25
29
  naming_the_executable do
26
30
  case command
27
- when "submit-answer" then submit_answer(required_id(id), *submitted(required_id(id), options))
28
- when "show-answer-check"
29
- check_answer(required_id(id), *submitted(required_id(id), options), options.fetch("file"))
31
+ when "submit-answer" then submit_answer(submitted(options))
32
+ when "show-answer-check" then check_answer(submitted(options), options.fetch("file"))
30
33
  else unknown(command)
31
34
  end
32
35
  end
@@ -34,50 +37,31 @@ module Principles
34
37
 
35
38
  private
36
39
 
37
- # The answer from --file, where - means it was read from stdin, checked against the schema for the phase
38
- # the request id names once its head says it answers a request that still matches the project, with the prior
39
- # findings a full audit's request listed, which checking its head found (#1052).
40
- #: (String, Hash[String, untyped]) -> [untyped, Models::PriorFindings?]
41
- def submitted(request_text, options)
42
- request_id = Models::RequestId.parse(request_text)
43
- prior = nil #: Models::PriorFindings?
44
- response = @project.answer(options.fetch("file"), stdin: options["stdin"], phase: request_id.phase) do |head|
45
- prior = checked_head(request_id, head)
46
- printed_placeholders(request_id)
47
- end
48
- [response, prior]
40
+ # The answer from --file, where - means it was read from stdin, to the request REQUEST_ID names, checked against
41
+ # the schema for the phase that id names once its head says it answers a request that still matches the project,
42
+ # with the prior findings a full audit's request listed, which checking its head found (#1052).
43
+ #: (Hash[String, untyped]) -> Models::SubmittedAnswer
44
+ def submitted(options)
45
+ request_id = Models::RequestId.parse(options.fetch("request_id"))
46
+ sent = @project.answer(options.fetch("file"), stdin: options["stdin"], phase: request_id.phase)
47
+ prior = checked_head(request_id, sent.head)
48
+ Models::SubmittedAnswer.new(request_id, sent.checked(phase(request_id).before_shape(request_id)), prior)
49
49
  end
50
50
 
51
51
  # Refuses an answer from its head alone: a record a later copy wrote is refused first, read afresh as
52
52
  # start-audit reads it, so nothing is written over one that landed mid-audit (D85), then an answer to another
53
- # request. Only an assessment's request is checked against the project here, since its template prints
54
- # placeholders this release's schema could otherwise refuse first; it gives the prior findings it listed (#1052).
53
+ # request, then whatever the phase checks of its request from the head alone (#1052).
55
54
  #: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings?
56
55
  def checked_head(request_id, head)
57
56
  @audit_records.refuse_newer(request_id.principle_id, version: @tool.version)
58
57
  request_id.check_answer(head)
59
- return unless request_id.phase == "assessment"
60
-
61
- handed(Assessment).checked_request(request_id, head, audit(request_id.principle_id))
62
- end
63
-
64
- # The placeholders the template of the request request_id names printed, which its answer may leave as
65
- # printed: a full audit's as start-audit --as template prints it now, a correction's from its dispositions'
66
- # placeholders; any other phase's template prints none (#1084).
67
- #: (Models::RequestId) -> Models::OtherTemplatesPlaceholders
68
- def printed_placeholders(request_id)
69
- Models::OtherTemplatesPlaceholders.besides(
70
- case request_id.phase
71
- when "assessment" then handed(FullAuditRequest, principle_id: request_id.principle_id).to_fill
72
- when "correction" then Models::Disposition::TEMPLATE_PLACEHOLDERS
73
- end
74
- )
58
+ phase(request_id).checked_request(request_id, head)
75
59
  end
76
60
 
77
61
  # Accepts the answer and writes the record changes it makes.
78
- #: (String, untyped, Models::PriorFindings?) -> untyped
79
- def submit_answer(request_text, response, prior)
80
- output, changes = judged(request_text, response, prior)
62
+ #: (Models::SubmittedAnswer) -> untyped
63
+ def submit_answer(submitted)
64
+ output, changes = judged(submitted)
81
65
  wrote = changes.map { |record| @audit_records.save(record) }
82
66
  audit_result.present(output).merge("wrote" => wrote)
83
67
  end
@@ -85,52 +69,35 @@ module Principles
85
69
  # Runs every check submit-answer would, and says what it would write, writing nothing; its submit command
86
70
  # gives answer_file, the --file value it was checked from, again. An assessment with findings also gives the
87
71
  # correction's answer it leads to, to fill (D81 step 3).
88
- #: (String, untyped, Models::PriorFindings?, String) -> untyped
89
- def check_answer(request_text, response, prior, answer_file)
90
- output, changes = judged(request_text, response, prior)
91
- audit_result.with_correction_to_fill(acceptable(request_text, response, answer_file, changes), output)
92
- .merge("wrote" => [])
72
+ #: (Models::SubmittedAnswer, String) -> untyped
73
+ def check_answer(submitted, answer_file)
74
+ output, changes = judged(submitted)
75
+ audit_result.with_correction_to_fill(acceptable(submitted, answer_file, changes), output).merge("wrote" => [])
93
76
  end
94
77
 
95
78
  # The answer passed every check: what submitting it would write, and its submit command.
96
- #: (String, untyped, String, Array[Models::AuditRecord]) -> Hash[String, untyped]
97
- def acceptable(request_text, response, answer_file, changes)
79
+ #: (Models::SubmittedAnswer, String, Array[Models::AuditRecord]) -> Hash[String, untyped]
80
+ def acceptable(submitted, answer_file, changes)
98
81
  written_up = Models::FindingWriteUps.of(@project, changes).written_up
99
82
  # Only a correction's fixed dispositions claim map entries; for any other answer this is empty, read from
100
83
  # no map, and left out.
101
- audit_result.acceptable(request_text, changes.map { |record| @audit_records.file(record.principle_id) },
84
+ audit_result.acceptable(submitted.request_id.to_s,
85
+ changes.map { |record| @audit_records.file(record.principle_id) },
102
86
  answer_file:, open_findings_will_print: (written_up unless written_up.empty?),
103
- map_entry_changes: claimed_map_entry_changes(request_text, response))
87
+ map_entry_changes: claimed_map_entry_changes(submitted))
104
88
  end
105
89
 
106
- # What each map entry a correction's fix claims changed, from the map its audit started from; its audit is
107
- # built only when a fix claims one.
108
- #: (String, untyped) -> Array[Hash[String, untyped]]
109
- def claimed_map_entry_changes(request_text, response)
110
- handed(Correction).map_entry_changes(response) { audit(Models::RequestId.parse(request_text).principle_id) }
111
- end
90
+ # What each map entry a fix in the answer claims changed, which only a correction's fixes claim.
91
+ #: (Models::SubmittedAnswer) -> Array[Hash[String, untyped]]
92
+ def claimed_map_entry_changes(submitted) = phase(submitted.request_id).map_entry_changes(submitted)
112
93
 
113
- # The result of answering, and each record change the answer makes, not yet written; every phase changes only
114
- # the request's own principle's record (D85). prior is what checking a full audit's assessment request found.
115
- #: (String, untyped, Models::PriorFindings?) -> [untyped, Array[Models::AuditRecord]]
116
- def judged(request_text, response, prior)
117
- request_id = Models::RequestId.parse(request_text)
118
- case request_id.phase
119
- when "acknowledgement" then handed(Acknowledgement).answered(request_id, response)
120
- when "repointing" then handed(Repoint).answered(request_id, response)
121
- when "assessment"
122
- checked = prior or raise ArgumentError, "an assessment's prior findings come from checking its head"
123
- handed(Assessment).answered(response, audit(request_id.principle_id), checked)
124
- else handed(Correction).answered(request_id, response, audit(request_id.principle_id))
125
- end
126
- end
94
+ # The result of answering, and each record change the answer makes, not yet written (D85).
95
+ #: (Models::SubmittedAnswer) -> [untyped, Array[Models::AuditRecord]]
96
+ def judged(submitted) = phase(submitted.request_id).answered(submitted)
127
97
 
128
- # The audit of principle id, against its members' hashes now.
129
- #: (String) -> Models::Audit
130
- def audit(id)
131
- map = @principles.find(id)
132
- Models::Audit.new(map: map, now: @project.snapshots(map).hashes)
133
- end
98
+ # The controller of the phase request_id names, which answers for it.
99
+ #: (Models::RequestId) -> AnswerPhase
100
+ def phase(request_id) = handed(PHASE_CONTROLLERS.fetch(request_id.phase))
134
101
  end
135
102
  end
136
103
  end
@@ -0,0 +1,54 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/audit"
6
+ require_relative "../models/other_templates_placeholders"
7
+ require_relative "../models/refusal_before_shape"
8
+ require_relative "../models/submitted_answer"
9
+
10
+ module Principles
11
+ # Each runs one command: reads models, applies their rules and prints through a view.
12
+ # controllers/CLAUDE.md owns the boundary.
13
+ module Controllers
14
+ # What every phase of an audit shares in answering its request, which submit-answer and show-answer-check hand
15
+ # over: each phase's controller answers for itself, so Answer never asks which phase it holds.
16
+ # @abstract
17
+ class AnswerPhase < Command
18
+ # The result of answering, and each record change the answer makes, not yet written; every phase changes only
19
+ # the request's own principle's record (D85). Sorbet refuses a phase that does not define it, and takes an
20
+ # abstract method only with a forwarding super for its body, which RuboCop would otherwise call useless.
21
+ # @abstract
22
+ #: (Models::SubmittedAnswer) -> [untyped, Array[Models::AuditRecord]]
23
+ def answered(submitted) = super # rubocop:disable Lint/UselessMethodDefinition
24
+
25
+ # The prior findings the request an answer's head names listed, once the phase has checked that request from
26
+ # the head alone: none, unless the phase lists some.
27
+ #: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings?
28
+ def checked_request(_request_id, _head) = nil
29
+
30
+ # What each map entry a fix in the answer claims changed, which only a correction's fixes claim.
31
+ #: (Models::SubmittedAnswer) -> Array[Hash[String, untyped]]
32
+ def map_entry_changes(_submitted) = []
33
+
34
+ # The refusals an answer to the request request_id names meets before its shape, in order; any phase's is a
35
+ # placeholder its template did not print (#1084).
36
+ #: (Models::RequestId) -> Array[Models::RefusalBeforeShape]
37
+ def before_shape(request_id) = [Models::OtherTemplatesPlaceholders.besides(printed_placeholders(request_id))]
38
+
39
+ private
40
+
41
+ # The placeholders the template of the request request_id names printed, which its answer may leave as
42
+ # printed: none, unless the phase's template prints some.
43
+ #: (Models::RequestId) -> Hash[String, untyped]?
44
+ def printed_placeholders(_request_id) = nil
45
+
46
+ # The audit of principle id, against its members' hashes now.
47
+ #: (String) -> Models::Audit
48
+ def audit_now(id)
49
+ map = @principles.find(id)
50
+ Models::Audit.new(map: map, now: @project.snapshots(map).hashes)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -2,10 +2,13 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "time"
5
- require_relative "command"
5
+ require_relative "answer_phase"
6
+ require_relative "../models/assessment_left_as_printed"
6
7
  require_relative "../models/audit"
7
8
  require_relative "../models/request_id"
9
+ require_relative "../models/unchecked_members"
8
10
  require_relative "audit_completion"
11
+ require_relative "full_audit_request"
9
12
 
10
13
  module Principles
11
14
  # Each runs one command: reads models, applies their rules and prints through a view.
@@ -14,11 +17,15 @@ module Principles
14
17
  # A full audit's assessment, which submit-answer and show-answer-check hand over: this tool checks the request
15
18
  # it answers and each member's assessment, then completes an audit with no findings or asks for the correction
16
19
  # of its findings (D35, D50).
17
- class Assessment < Command
18
- # The result of answering an assessment request whose request checked_request found unchanged, with the prior
19
- # findings it listed, and the record change it makes, not yet written.
20
- #: (untyped, Models::Audit, Models::PriorFindings) -> [untyped, Array[Models::AuditRecord]]
21
- def answered(response, audit, prior)
20
+ class Assessment < AnswerPhase
21
+ # The result of answering an assessment request, which checked_request found unchanged, with the prior findings
22
+ # it listed, and the record change it makes, not yet written.
23
+ # @override
24
+ #: (Models::SubmittedAnswer) -> [untyped, Array[Models::AuditRecord]]
25
+ def answered(submitted)
26
+ response = submitted.response
27
+ prior = submitted.prior_findings
28
+ audit = audit_now(submitted.request_id.principle_id)
22
29
  basis = Models::AssessmentBasis.new(response.fetch("basis"))
23
30
  judged_against = record_judged_against(audit)
24
31
  basis.printed_after.refusing_stale_first(audit.id, @audit_records.find(audit.id)) do
@@ -27,16 +34,33 @@ module Principles
27
34
  end
28
35
 
29
36
  # The prior findings the request an answer's head names listed, refused when that request, given the head's
30
- # basis, no longer matches the project, before the rest of the answer's shape is read (#1052).
31
- #: (Models::RequestId, Hash[String, untyped], Models::Audit) -> Models::PriorFindings
32
- def checked_request(request_id, head, audit)
37
+ # basis, no longer matches the project, before the rest of the answer's shape is read: checked here alone, since
38
+ # its template prints placeholders this release's schema could otherwise refuse first (#1052).
39
+ #: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings
40
+ def checked_request(request_id, head)
41
+ audit = audit_now(request_id.principle_id)
33
42
  basis = Models::AssessmentBasis.new(head.fetch("basis"))
34
43
  audit.check_assessment_request(request_id, basis: basis, committed: committed(basis.base, audit.map),
35
44
  record: @audit_records.find(audit.id), loads: loads_to_check(audit))
36
45
  end
37
46
 
47
+ # The refusals an answer meets before its shape: first a check_result on a member with no check, which the
48
+ # shape would refuse as lacking its command (#1088), then any phase's, whose template is read first, as before,
49
+ # then a judgement left as its template printed it, named with the shape's problems, so one refusal names both
50
+ # (#1109).
51
+ #: (Models::RequestId) -> Array[Models::RefusalBeforeShape]
52
+ def before_shape(request_id)
53
+ any_phase = super
54
+ [Models::UncheckedMembers.new(@principles.find(request_id.principle_id).members), *any_phase,
55
+ Models::AssessmentLeftAsPrinted.new]
56
+ end
57
+
38
58
  private
39
59
 
60
+ # The placeholders a full audit's template printed, as start-audit --as template prints it now (#1084).
61
+ #: (Models::RequestId) -> Hash[String, untyped]?
62
+ def printed_placeholders(request_id) = handed(FullAuditRequest, principle_id: request_id.principle_id).to_fill
63
+
40
64
  # The assessment's fields and its decisions on the prior findings checked, then the audit completed or its
41
65
  # correction asked for.
42
66
  #: (untyped, Models::Audit, Models::PriorFindings, Models::RecordJudgedAgainst, Models::AssessmentBasis)
@@ -33,15 +33,25 @@ module Principles
33
33
  private
34
34
 
35
35
  # The audit start-audit's options ask for: a one-member audit with --member, a repoint of the open
36
- # findings' write-ups with --write-ups (D59), else a full audit, its answer alone with --as template (D81).
36
+ # findings' write-ups with --write-ups (D59), else a full audit; a full or one-member audit's answer alone with
37
+ # --as template (D81, #773).
37
38
  #: (String, Hash[String, untyped]) -> Hash[String, untyped]
38
39
  def started_audit(id, options)
39
40
  naming_the_executable { @audit_records.refuse_newer(id, version: @tool.version) }
40
- return acknowledge(id, options["member"]) if options["member"]
41
+ return acknowledge(id, options["member"], to_fill: options["as"] == "template") if options["member"]
41
42
  return handed(Repoint).start(id) if options["write_ups"]
42
43
 
44
+ full_audit(id, options)
45
+ end
46
+
47
+ # A full audit's request, or with --as template its answer alone, or with --instruction one instruction field
48
+ # of it (D81).
49
+ #: (String, Hash[String, untyped]) -> Hash[String, untyped]
50
+ def full_audit(id, options)
43
51
  naming_the_executable do
44
52
  full = handed(FullAuditRequest, principle_id: id)
53
+ next full.instruction(options["instruction"]) if options["instruction"]
54
+
45
55
  options["as"] ? full.to_fill : full.printed
46
56
  end
47
57
  end
@@ -55,10 +65,11 @@ module Principles
55
65
  @audit_records.fetch(id).shown.merge(waiting_beside(id), "wrote" => [])
56
66
  end
57
67
 
58
- # A one-member audit of member_id (D33).
59
- #: (String, String) -> Hash[String, untyped]
60
- def acknowledge(id, member_id)
61
- handed(Acknowledgement).start(id, member_id)
68
+ # A one-member audit of member_id (D33), or its answer alone to fill (#773).
69
+ #: (String, String, to_fill: bool) -> Hash[String, untyped]
70
+ def acknowledge(id, member_id, to_fill:)
71
+ acknowledgement = handed(Acknowledgement)
72
+ to_fill ? acknowledgement.to_fill(id, member_id) : acknowledgement.start(id, member_id)
62
73
  end
63
74
 
64
75
  # The findings the last completed audit of map id, or of every map, deferred or accepted (#292, D35). Across