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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51ce6acd3b9d638e2948da0d6e41e0eb4b7656dff90a976bf976f4232020c431
4
- data.tar.gz: 803b232afd27b6050db0197f2d77accc7afe852545d17000f2c768a4138aa402
3
+ metadata.gz: 40e41136c5be852cc2019089d41ab1548144e52138ab51c80211befe32bfa411
4
+ data.tar.gz: 3d7d56d9ba40d0678e39fcd4b7f6ecca2b231ac5b449f07af84617b8e0ad1a91
5
5
  SHA512:
6
- metadata.gz: bb6296b076b2b9ce37d5ad707d1b8312a95edd7e0341da94ee9f7da1587471536db19d1fb3afe072de8f297100fe02da308a7f553b13e99608509413eadcdd0a
7
- data.tar.gz: 89b4e1074966cc96af2769263ac1ed9210dd0175c3d0c4490ff681dbfc41da09157a20189e1380e06ae61c5fea7cc261b479c1d1bd1783265163ebd167baafa9
6
+ metadata.gz: ff6dd21e3e9a0e929ae135aaaa587b8781e6bea67ac6547fa8b23ce43d15a75d05a3c9490eaecf1049d76384df1e39eb7e5d6c0605a883dc67ff5051b308f12b
7
+ data.tar.gz: cd61142617ebf7f28eba7b2ae5bc89e1dd18d745fb8d9c763bacf68c6e2dacc7a5cc5f66869c0bf4da24d584134612b4f9ae52a63d682931c342a96217476bb0
@@ -64,11 +64,17 @@ module Principles
64
64
  options = line.command_options
65
65
  # One byte past the limit is enough for the answer's own check to refuse it as too large.
66
66
  options["stdin"] = @stdin.read(Data::BoundedFile::LIMIT + 1).to_s if options["file"] == "-"
67
- project = Models::Project.at(options.fetch("project"))
67
+ project = selected_project(line)
68
68
  CommandRoutes::CONTROLLERS.fetch(command).new(project, tool: running_tool)
69
69
  .call(command, line.id, options)
70
70
  end
71
71
 
72
+ #: (CommandLine) -> Models::Project
73
+ def selected_project(line)
74
+ root = line.option("project")
75
+ line.project_given? ? Models::Project.at(root) : Models::Project.containing(root)
76
+ end
77
+
72
78
  # The JSON object an agent reads for a failure that is not one of this tool's refusals.
73
79
  #: (StandardError) -> Hash[untyped, untyped]
74
80
  def refusal(error)
@@ -111,9 +117,11 @@ module Principles
111
117
  end
112
118
  end
113
119
 
114
- # 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.
115
122
  #: (untyped) -> Integer
116
123
  def printed_result(result)
124
+ return printed(visible(result.text)) if result.is_a?(Views::JsonWithEntriesOnLines)
117
125
  return printed(visible(JSON.pretty_generate(result))) unless result.is_a?(Views::Lines)
118
126
 
119
127
  @stdout.print(result.stdout)
@@ -4,14 +4,17 @@
4
4
  require "optparse"
5
5
  require_relative "invocation_options"
6
6
  require_relative "after_commit_hook_options"
7
+ require_relative "session_start_options"
8
+ require_relative "start_audit_options"
7
9
  require_relative "models/command_steps"
10
+ require_relative "prose_list"
8
11
 
9
12
  module Principles
10
13
  # One invocation's words: the command, its positional arguments and its options, refused with an
11
14
  # OptionParser error when they do not fit what the command takes. CLI decides what to run from it.
12
15
  class CommandLine
13
- # The sources Claude Code's SessionStart hook names, which list-open-findings --short --session-start takes (#717).
14
- SESSION_STARTS = %w[startup clear compact].freeze #: Array[String]
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]
15
18
 
16
19
  # argv is parsed at once; positional names each command's positional arguments, in order; executable is the
17
20
  # invocation a refusal tells the agent to run --help with (#562).
@@ -50,6 +53,10 @@ module Principles
50
53
  @options.value(name)
51
54
  end
52
55
 
56
+ # Explicit selection defines a project even when it names the current directory.
57
+ #: () -> bool
58
+ def project_given? = @options.given.include?("project")
59
+
53
60
  # The command named first; nil when none is, and refused when this tool has no such command.
54
61
  #: () -> String?
55
62
  def command
@@ -59,20 +66,16 @@ module Principles
59
66
  raise OptionParser::InvalidArgument, "unknown command #{name}"
60
67
  end
61
68
 
62
- # Refuses the wrong number of arguments, an option the command does not take or given an option as its value,
63
- # 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.
64
71
  #: () -> void
65
72
  def check
66
73
  name = command.to_s
74
+ check_missing(name)
67
75
  check_arguments(name)
68
76
  check_options(name)
69
77
  check_values_are_not_options(name)
70
- check_session_start(name)
71
- check_hook_report(name)
72
- check_audit_kind(name)
73
- return unless %w[submit-answer show-answer-check].include?(name) && !@options.value("file")
74
-
75
- raise OptionParser::MissingArgument, "#{name} needs --file FILE, or --file - for stdin"
78
+ check_combined_options(name)
76
79
  end
77
80
 
78
81
  # The principle id, for a command whose first argument is one.
@@ -101,9 +104,31 @@ module Principles
101
104
  @arguments.drop(1)
102
105
  end
103
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.
104
129
  #: (String) -> void
105
130
  def check_arguments(name)
106
- return if values.length.between?(names.count { |each| !each.end_with?("?") }, names.length)
131
+ return if values.length <= names.length
107
132
 
108
133
  takes = "#{name} takes #{shown_arguments}".strip.sub(/ takes\z/, " takes no arguments")
109
134
  raise OptionParser::InvalidArgument, takes
@@ -118,7 +143,7 @@ module Principles
118
143
  # An option a command does not take is refused, so a mistyped command never runs as something else.
119
144
  #: (String) -> void
120
145
  def check_options(name)
121
- taken = Models::CommandSteps.load.command(name)&.options || []
146
+ taken = steps(name)&.options || []
122
147
  unknown = (@options.given - taken - ["project"]).map { |option| "--#{option}" }
123
148
  return if unknown.empty?
124
149
 
@@ -140,33 +165,15 @@ module Principles
140
165
  end
141
166
  end
142
167
 
143
- # --session-start names one of the hook's sources, and words only the --short line.
168
+ # Options checked together, each set owning what is wrong with it as given: --session-start (#717), the
169
+ # after-commit hook's pair (D73) and the audit start-audit begins (#760); the first fault is refused.
144
170
  #: (String) -> void
145
- def check_session_start(name)
146
- start = @options.value("session_start") or return
147
- unless SESSION_STARTS.include?(start)
148
- raise UsageRefusal.new("--session-start takes startup, clear or compact, not #{start}", help_repair(name))
149
- end
150
- return if @options.value("short")
151
-
152
- raise UsageRefusal.new("--session-start words only the --short line", help_repair(name))
153
- end
154
-
155
- # --commits-after and --hook-event ask together for the after-commit hook's JSON, which --short's lines are not.
156
- #: (String) -> void
157
- def check_hook_report(name)
158
- fault = AfterCommitHookOptions.new(@options).fault or return
171
+ def check_combined_options(name)
172
+ sets = [SessionStartOptions.new(@options), AfterCommitHookOptions.new(@options), StartAuditOptions.new(@options)]
173
+ fault = sets.filter_map(&:fault).first or return
159
174
  raise UsageRefusal.new(fault, help_repair(name))
160
175
  end
161
176
 
162
- # --member and --write-ups each ask start-audit for a different audit, so only one may be given (#760).
163
- #: (String) -> void
164
- def check_audit_kind(name)
165
- return unless @options.value("member") && @options.value("write_ups")
166
-
167
- raise UsageRefusal.new("--member and --write-ups each start a different audit; give one", help_repair(name))
168
- end
169
-
170
177
  # Parses argv's options; an option no command defines fails here, before the command is checked, and is
171
178
  # repaired with the help of the command argv names, or left to CLI's general advice when it names none.
172
179
  #: (Array[String]) -> void
@@ -182,6 +189,10 @@ module Principles
182
189
  #: (Array[String]) -> String?
183
190
  def named_command(argv) = argv.find { |word| @positional.key?(word) }
184
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
+
185
196
  #: (String) -> String
186
197
  def help_repair(name) = "To see what it takes: #{@executable} #{name} --help"
187
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
 
@@ -73,8 +139,8 @@ module Principles
73
139
  # lines there and now, which the answer's quotes are checked against (#379).
74
140
  #: (String, Models::Acknowledgement, Models::Member) -> [Models::Placement, Models::MemberLines]
75
141
  def since_baseline(id, acknowledgement, member)
76
- placements = map_history(id).placements_since(acknowledgement.last_judged_commit, member.key,
77
- @member_maps.find(id).member(member.id))
142
+ placements = principle_history(id).placements_since(acknowledgement.last_judged_commit, member.key,
143
+ @principles.find(id).member(member.id))
78
144
  baseline = acknowledgement.baseline(placements)
79
145
  lines = @project.member_lines(member.locator, since: baseline.commit, then_locator: baseline.locator)
80
146
  [baseline, acknowledgement.compared(lines)]
@@ -82,8 +148,8 @@ module Principles
82
148
 
83
149
  #: (String, String) -> [Models::Acknowledgement, Models::Member, String?]
84
150
  def prepared(id, member_id)
85
- member = Models::Member.new(@member_maps.find(id).member(member_id))
86
- base = @history.base_commit(id, [@member_maps.file(id), member.path])
151
+ member = Models::Member.new(@principles.find(id).member(member_id))
152
+ base = @history.base_commit(id, [@principles.file(id), member.path])
87
153
  now = @project.locate(member.locator).fetch("sha256")
88
154
  [Models::Acknowledgement.new(principle_id: id, member: member, record: @audit_records.find(id), base: base,
89
155
  now_sha256: now), member, base]
@@ -1,15 +1,14 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "time"
5
4
  require_relative "command"
6
5
  require_relative "../models/finding_write_ups"
7
- require_relative "../models/audit"
8
6
  require_relative "../models/request_id"
7
+ require_relative "../models/submitted_answer"
9
8
  require_relative "acknowledgement"
10
9
  require_relative "correction"
11
10
  require_relative "repoint"
12
- require_relative "audit_completion"
11
+ require_relative "assessment"
13
12
 
14
13
  module Principles
15
14
  # Each runs one command: reads models, applies their rules and prints through a view.
@@ -19,13 +18,18 @@ module Principles
19
18
  # audit completes, writes the committed audit record. Nothing else is stored: each request id is a
20
19
  # digest of what the request depends on, so an answer is checked against the project as it is now (D25).
21
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
+
22
27
  #: (String, String?, Hash[String, untyped]) -> untyped
23
- def call(command, id, options)
28
+ def call(command, _id, options)
24
29
  naming_the_executable do
25
30
  case command
26
- when "submit-answer" then submit_answer(required_id(id), submitted(required_id(id), options))
27
- when "show-answer-check"
28
- 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"))
29
33
  else unknown(command)
30
34
  end
31
35
  end
@@ -33,140 +37,67 @@ module Principles
33
37
 
34
38
  private
35
39
 
36
- # The answer from --file, where - means it was read from stdin, checked against the schema for the phase
37
- # the request id names.
38
- #: (String, Hash[String, untyped]) -> untyped
39
- def submitted(request_text, options)
40
- @project.answer(options.fetch("file"), stdin: options["stdin"], phase: Models::RequestId.parse(request_text).phase)
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
+ end
50
+
51
+ # Refuses an answer from its head alone: a record a later copy wrote is refused first, read afresh as
52
+ # start-audit reads it, so nothing is written over one that landed mid-audit (D85), then an answer to another
53
+ # request, then whatever the phase checks of its request from the head alone (#1052).
54
+ #: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings?
55
+ def checked_head(request_id, head)
56
+ @audit_records.refuse_newer(request_id.principle_id, version: @tool.version)
57
+ request_id.check_answer(head)
58
+ phase(request_id).checked_request(request_id, head)
41
59
  end
42
60
 
43
61
  # Accepts the answer and writes the record changes it makes.
44
- #: (String, untyped) -> untyped
45
- def submit_answer(request_text, response)
46
- output, changes = judged(request_text, response)
62
+ #: (Models::SubmittedAnswer) -> untyped
63
+ def submit_answer(submitted)
64
+ output, changes = judged(submitted)
47
65
  wrote = changes.map { |record| @audit_records.save(record) }
48
66
  audit_result.present(output).merge("wrote" => wrote)
49
67
  end
50
68
 
51
69
  # Runs every check submit-answer would, and says what it would write, writing nothing; its submit command
52
- # gives answer_file, the --file value it was checked from, again.
53
- #: (String, untyped, String) -> untyped
54
- def check_answer(request_text, response, answer_file)
55
- _, changes = judged(request_text, response)
70
+ # gives answer_file, the --file value it was checked from, again. An assessment with findings also gives the
71
+ # correction's answer it leads to, to fill (D81 step 3).
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" => [])
76
+ end
77
+
78
+ # The answer passed every check: what submitting it would write, and its submit command.
79
+ #: (Models::SubmittedAnswer, String, Array[Models::AuditRecord]) -> Hash[String, untyped]
80
+ def acceptable(submitted, answer_file, changes)
56
81
  written_up = Models::FindingWriteUps.of(@project, changes).written_up
57
82
  # Only a correction's fixed dispositions claim map entries; for any other answer this is empty, read from
58
83
  # no map, and left out.
59
- 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) },
60
86
  answer_file:, open_findings_will_print: (written_up unless written_up.empty?),
61
- map_entry_changes: claimed_map_entry_changes(request_text, response))
62
- .merge("wrote" => [])
87
+ map_entry_changes: claimed_map_entry_changes(submitted))
63
88
  end
64
89
 
65
- # What each map entry a correction's fix claims changed, from the map its audit started from; its audit is
66
- # built only when a fix claims one.
67
- #: (String, untyped) -> Array[Hash[String, untyped]]
68
- def claimed_map_entry_changes(request_text, response)
69
- handed(Correction).map_entry_changes(response) { audit(Models::RequestId.parse(request_text).principle_id) }
70
- 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)
71
93
 
72
- # The result of answering, and each record change the answer makes, not yet written.
73
- #: (String, untyped) -> [untyped, Array[Models::AuditRecord]]
74
- def judged(request_text, response)
75
- request_id = Models::RequestId.parse(request_text)
76
- request_id.check_answer(response)
77
- case request_id.phase
78
- when "acknowledgement" then handed(Acknowledgement).answered(request_id, response)
79
- when "repointing" then handed(Repoint).answered(request_id, response)
80
- when "assessment" then answer_assessment(request_id, response, audit(request_id.principle_id))
81
- else handed(Correction).answered(request_id, response, audit(request_id.principle_id))
82
- end
83
- 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)
84
97
 
85
- # The audit of principle id, against its members' hashes now.
86
- #: (String) -> Models::Audit
87
- def audit(id)
88
- map = @member_maps.find(id)
89
- Models::Audit.new(map: map, now: @project.snapshots(map).hashes)
90
- end
91
-
92
- #: (Models::RequestId, untyped, Models::Audit) -> [untyped, Array[Models::AuditRecord]]
93
- def answer_assessment(request_id, response, audit)
94
- basis = Models::AssessmentBasis.new(response.fetch("basis"))
95
- judged_against = record_judged_against(audit)
96
- prior = checked_request(request_id, basis, audit, judged_against.loads)
97
- basis.printed_after.refusing_stale_first(audit.id, @audit_records.find(audit.id)) do
98
- judged_assessment(response, audit, prior, judged_against, basis)
99
- end
100
- end
101
-
102
- # The assessment's fields and its decisions on the prior findings checked, then the audit completed or its
103
- # correction asked for.
104
- #: (untyped, Models::Audit, Models::PriorFindings, Models::RecordJudgedAgainst, Models::AssessmentBasis)
105
- #| -> [untyped, Array[Models::AuditRecord]]
106
- def judged_assessment(response, audit, prior, judged_against, basis)
107
- assessed = audit.assessment(response, judged_against, Time.now.utc.iso8601) do |locator|
108
- snapshot(locator)
109
- end
110
- findings = assessed.findings
111
- decided = prior.decided(response["prior_finding_decisions"], findings, records: @audit_records) do |locator|
112
- snapshot(locator)
113
- end
114
- correction(audit.assessed_start(basis.base, assessed, grounds(audit)), audit, findings, decided, basis)
115
- end
116
-
117
- # The request an assessment answers, checked against the project now, with the prior findings it listed.
118
- #: (Models::RequestId, Models::AssessmentBasis, Models::Audit, Models::LoadsToCheck) -> Models::PriorFindings
119
- def checked_request(request_id, basis, audit, loads)
120
- audit.check_assessment_request(request_id, basis: basis, committed: committed(basis.base, audit.map),
121
- record: @audit_records.find(audit.id), loads: loads)
122
- end
123
-
124
- # Completes an audit with no findings. Otherwise asks the agent to correct them. Each is refused once the last
125
- # completed record changed after the assessment's request was printed, the completion unless it writes
126
- # nothing (D50).
127
- #: (Models::AuditStart, Models::Audit, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
128
- #| -> [untyped, Array[Models::AuditRecord]]
129
- def correction(start, audit, findings, decided, assessed)
130
- if findings.empty?
131
- return handed(AuditCompletion, replacing: assessed.printed_after).completed(start, audit, [], [], decided)
132
- end
133
-
134
- correction_request(start, audit, findings, decided, assessed)
135
- end
136
-
137
- # The correction request for findings, and outside git the open record that keeps what the audit began from.
138
- # It is refused before it is printed once the last completed record changed, so no fix is made for an audit
139
- # that cannot complete (D50). The check results travel in the basis, so the completed record keeps them (D30).
140
- #: (Models::AuditStart, Models::Audit, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
141
- #| -> [untyped, Array[Models::AuditRecord]]
142
- def correction_request(start, audit, findings, decided, assessed)
143
- assessed.printed_after.confirm_unchanged(audit.id, @audit_records.find(audit.id))
144
- basis = printed_basis(start, findings, decided, assessed)
145
- [audit_result.correction_request(request_id: basis.request_id(audit.id, audit.now).to_s,
146
- principle_id: audit.id, findings: findings, basis: basis.to_h,
147
- placeholders: Models::Disposition::PLACEHOLDERS),
148
- open_record_changes(start, audit, basis.to_h)]
149
- end
150
-
151
- # The basis a correction request prints, for the agent to hand back with its answer.
152
- # Its revision is the one the assessment was printed after, carried forward, so the correction is refused once
153
- # that record changes (#646, D50).
154
- #: (Models::AuditStart, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
155
- #| -> Models::CorrectionBasis
156
- def printed_basis(start, findings, decided, assessed)
157
- Models::CorrectionBasis.printed(start, findings: findings, prior: decided, revision: assessed.revision)
158
- end
159
-
160
- # Outside git, the open record that keeps what the audit began from, and the last completed record, so a
161
- # restarted audit still lists its prior findings (D35); in git, nothing.
162
- #: (Models::AuditStart, Models::Audit, Hash[String, untyped]) -> Array[Models::AuditRecord]
163
- def open_record_changes(start, audit, basis)
164
- return [] if start.base
165
-
166
- last = @audit_records.find(audit.id)&.last_completed
167
- record = handed(AuditCompletion).record(start, basis.fetch("findings"), "open", audit.now, last)
168
- @audit_records.changes(record)
169
- 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))
170
101
  end
171
102
  end
172
103
  end