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
@@ -14,9 +14,20 @@ module Principles
14
14
  # outside git, where nothing checked them (#386), and the lists to ask the owner about, each with the paths to
15
15
  # name in it (#405, #412).
16
16
  class Found
17
+ # What each listed file prints: where it is, how big, where a link leads, and what the survey reads of it.
18
+ PRINTED_FILE_FIELDS = %w[path characters symlink_to description opening_line outline].freeze
19
+
17
20
  #: Hash[String, Array[String]]
18
21
  attr_reader :owner_asks
19
22
 
23
+ # Whether the inventory names files whose list items were cut to keep the result short (#1155).
24
+ #: () -> bool
25
+ def cut? = @inventory.key?("outlines_cut")
26
+
27
+ # Whether the inventory names files that print their path and size alone, their outlines left out (#1155).
28
+ #: () -> bool
29
+ def left_out? = @inventory.key?("outlines_left_out")
30
+
20
31
  #: (inventory: Hash[String, untyped], untracked: Array[String]?,
21
32
  #| owner_asks: Hash[String, Array[String]]) -> void
22
33
  def initialize(inventory:, untracked:, owner_asks:)
@@ -30,7 +41,7 @@ module Principles
30
41
  # in git.
31
42
  #: () -> Hash[String, untyped]
32
43
  def listed
33
- files = @inventory.fetch("files").map { |file| file.slice("path", "characters", "symlink_to") }
44
+ files = @inventory.fetch("files").map { |file| file.slice(*PRINTED_FILE_FIELDS) }
34
45
  listed = @inventory.merge("files" => files,
35
46
  "scope" => Prompts.text("find-a-principle-to-map/where-the-inventory-looks"))
36
47
  @untracked ? listed.merge("untracked" => @untracked) : listed
@@ -47,34 +58,45 @@ module Principles
47
58
  end
48
59
 
49
60
  # The inventory, and the question of which principle to map, with one item for each list under found's owner_asks
50
- # to ask the owner about. Until principles is set_up, next_action puts setting it up first.
51
- #: (Found, existing_maps: Array[String], map_file: String, set_up: bool) -> Hash[String, untyped]
52
- def question(found, existing_maps:, map_file:, set_up:)
61
+ # to ask the owner about.
62
+ #: (Found, existing_maps: Array[String], map_file: String) -> Hash[String, untyped]
63
+ def question(found, existing_maps:, map_file:)
53
64
  { "status" => "question", "inventory" => found.listed, "existing_maps" => existing_maps,
54
65
  "writes" => Prompts.text("find-a-principle-to-map/what-each-command-writes", map_file: map_file),
55
- "question" => principle_question(found.owner_asks),
56
- "answer_with" => @invocation.in_project("create-principle", usage: CREATE_PRINCIPLE_USAGE),
57
- **(set_up ? {} : { "next_action" => set_up_first }) }
66
+ "question" => principle_question(found),
67
+ "answer_with" => @invocation.in_project("create-principle", usage: CREATE_PRINCIPLE_USAGE) }
58
68
  end
59
69
 
60
70
  private
61
71
 
62
- # The line that puts setting principles up first, ending in its command.
63
- #: () -> String
64
- def set_up_first
65
- Prompts.text("set-principles-up/set-up-first",
66
- command: @invocation.in_project("show-meta-principle-passage"))
67
- end
68
-
69
- # Which principle to map, then one item per list to ask the owner about.
70
- #: (Hash[String, Array[String]]) -> String
71
- def principle_question(owner_asks)
72
+ # The survey, leaving out files possibly test data, and when outlines were cut or left out how to read them, then
73
+ # one item per list to ask the owner about after the table.
74
+ #: (Found) -> String
75
+ def principle_question(found)
76
+ owner_asks = found.owner_asks
72
77
  asks = owner_asks.map { |key, paths| "- #{owner_ask(key, named: inline(paths))}" }
73
- [Prompts.text("find-a-principle-to-map/choose-one-principle"),
74
- *([Prompts.text("find-a-principle-to-map/ask-the-owner-before-mapping"), *asks].join("\n") if asks.any?)]
78
+ [Prompts.text("find-a-principle-to-map/choose-one-principle"), *left_out_of_the_survey(owner_asks),
79
+ *budget_notes(found),
80
+ Prompts.text("find-a-principle-to-map/ask-which-principle-to-map"),
81
+ *([Prompts.text("find-a-principle-to-map/ask-the-owner-after-the-table"), *asks].join("\n") if asks.any?)]
75
82
  .join("\n\n")
76
83
  end
77
84
 
85
+ # How to read what the budget cut: a cut section back by its lines, and a file whose outline was left out.
86
+ #: (Found) -> Array[String]
87
+ def budget_notes(found)
88
+ [*(Prompts.text("find-a-principle-to-map/read-a-cut-section-back") if found.cut?),
89
+ *(Prompts.text("find-a-principle-to-map/read-left-out-files") if found.left_out?)]
90
+ end
91
+
92
+ # The line leaving files possibly test data out of the survey, when any is listed.
93
+ #: (Hash[String, Array[String]]) -> Array[String]
94
+ def left_out_of_the_survey(owner_asks)
95
+ return [] unless owner_asks.key?("possibly_test_data")
96
+
97
+ [Prompts.text("find-a-principle-to-map/leave-test-data-out-of-the-survey")]
98
+ end
99
+
78
100
  # The paths an ask names after its list's name, each quoted, since a path may hold a comma; none, nothing.
79
101
  #: (Array[String]) -> String
80
102
  def inline(paths) = paths.empty? ? "" : " (#{paths.map { |path| "`#{path}`" }.join(", ")})"
@@ -0,0 +1,44 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "prompts"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # What a checked member's exit_status placeholder says of its check beside what to do, in a full audit's template
10
+ # and a one-member audit's alike: any hidden character the command holds (#260), and the line the last audit's
11
+ # review rested on, which a run keeps unless a new one is given (#849).
12
+ class CheckNotes
13
+ # since_last_audit is how the check stands to the last audit's, with the review line that audit kept, if any;
14
+ # hidden_characters names each hidden character in the command.
15
+ #: (Hash[String, untyped]?, Array[String]) -> void
16
+ def initialize(since_last_audit, hidden_characters)
17
+ @since_last_audit = since_last_audit
18
+ @hidden_characters = hidden_characters
19
+ freeze
20
+ end
21
+
22
+ # The note naming the command's hidden characters, where the decision to run it is made; nil when it has none.
23
+ #: () -> String?
24
+ def hidden_characters
25
+ return if @hidden_characters.empty?
26
+
27
+ Prompts.text("assess-every-member/have-hidden-characters-in-a-check-explained",
28
+ characters: @hidden_characters.join("; "))
29
+ end
30
+
31
+ # That a run keeps the line the last audit's review rested on, quoted with since when, unless a new one is
32
+ # given, so whether it still holds can be judged from the template (#849); a record from before D63 kept none,
33
+ # so there is nothing to say (#826).
34
+ #: () -> Array[String]
35
+ def kept_review
36
+ return [] unless @since_last_audit&.key?("review_basis")
37
+
38
+ [Prompts.text("assess-every-member/keep-the-last-review-basis-unless-you-give-a-new-one",
39
+ since: @since_last_audit.fetch("review_basis_since"),
40
+ basis: @since_last_audit.fetch("review_basis"))]
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,42 +1,55 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "check_notes"
4
5
  require_relative "prompts"
5
6
 
6
7
  module Principles
7
8
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
9
  module Views
9
- # The check_result a checked member's assessment template starts with: its command, and a not_run_reason
10
- # that says what to do before replacing it. A check no audit has run, or one changed since, is reviewed
11
- # before it runs (#227), and any hidden character it holds is named where that decision is made (#260).
10
+ # The check_result a checked member's assessment template starts with: its command, an exit_status placeholder
11
+ # that says what to do before replacing it with the run's status, and not_run_reason, the alternative, as a
12
+ # placeholder an answer leaves as printed when it reports a run (#993). A check no audit has run, or one changed
13
+ # since, is reviewed before it runs (#227), so it also gives review_basis to fill (D63), and any hidden character
14
+ # it holds is named where that decision is made (#260).
12
15
  class CheckResultTemplate
13
- #: (String, Hash[String, untyped]?, ?Array[String]) -> void
14
- def initialize(check, since_last_audit, hidden_characters = [])
16
+ # The template for the checked member a request lists as entry, with its check, how that stands to the last
17
+ # audit's and any hidden characters in it; nil for a member without a check.
18
+ #: (Hash[String, untyped], reviewed_placeholders: Hash[String, String],
19
+ #| unchanged_placeholders: Hash[String, String]) -> Hash[String, untyped]?
20
+ def self.for(entry, reviewed_placeholders:, unchanged_placeholders:)
21
+ check = entry["check"] or return
22
+ new(check, entry["check_since_last_audit"], entry.fetch("check_hidden_characters", []),
23
+ reviewed_placeholders:, unchanged_placeholders:).to_h
24
+ end
25
+
26
+ # reviewed_placeholders gives the text of not_run_reason and review_basis, which an answer leaves as printed to
27
+ # give neither, for a check reviewed before it runs; unchanged_placeholders gives it for one the last audit ran,
28
+ # whose review_basis left as printed keeps the line that audit kept (#1010).
29
+ #: (String, Hash[String, untyped]?, ?Array[String], reviewed_placeholders: Hash[String, String],
30
+ #| unchanged_placeholders: Hash[String, String]) -> void
31
+ def initialize(check, since_last_audit, hidden_characters = [], reviewed_placeholders:, unchanged_placeholders:)
15
32
  @check = check
16
33
  @since_last_audit = since_last_audit
17
- @hidden_characters = hidden_characters
34
+ @notes = CheckNotes.new(since_last_audit, hidden_characters) #: CheckNotes
35
+ unchanged = since_last_audit&.fetch("status") == "unchanged"
36
+ @placeholders = unchanged ? unchanged_placeholders : reviewed_placeholders #: Hash[String, String]
18
37
  freeze
19
38
  end
20
39
 
21
40
  #: () -> Hash[String, untyped]
22
41
  def to_h
23
- { "command" => @check, "not_run_reason" => [hidden_characters, not_run_reason].compact.join(" ") }
42
+ { "command" => @check, "exit_status" => [@notes.hidden_characters, run_and_report].compact.join(" "),
43
+ "not_run_reason" => @placeholders.fetch("not_run_reason"),
44
+ "review_basis" => @placeholders.fetch("review_basis") }
24
45
  end
25
46
 
26
47
  private
27
48
 
28
- #: () -> String?
29
- def hidden_characters
30
- return if @hidden_characters.empty?
31
-
32
- Prompts.text("assess-every-member/have-hidden-characters-in-a-check-explained",
33
- characters: @hidden_characters.join("; "))
34
- end
35
-
36
- # What to do before replacing the field, then that a named check runs at every full audit, which holds for
49
+ # What to do before replacing exit_status, then that a named check runs at every full audit, which holds for
37
50
  # each status.
38
51
  #: () -> String
39
- def not_run_reason
52
+ def run_and_report
40
53
  [*steps, Prompts.text("assess-every-member/run-a-named-check-at-every-full-audit")].join(" ")
41
54
  end
42
55
 
@@ -46,23 +59,22 @@ module Principles
46
59
  #: () -> Array[String]
47
60
  def steps
48
61
  case @since_last_audit&.fetch("status")
49
- when "unchanged" then [Prompts.text("assess-every-member/run-the-check-then-report-it"), *kept_review]
62
+ when "unchanged" then [Prompts.text("assess-every-member/run-the-check-then-report-it"), *@notes.kept_review]
50
63
  when "changed"
51
- [Prompts.text("assess-every-member/have-a-changed-check-reviewed-before-running-it"), run_reviewed]
52
- else [Prompts.text("assess-every-member/have-a-new-check-reviewed-before-running-it"), run_reviewed]
64
+ [Prompts.text("assess-every-member/have-a-changed-check-reviewed-before-running-it",
65
+ changed_in: commit_clause(": commit %s changed it")), run_reviewed]
66
+ else
67
+ [Prompts.text("assess-every-member/have-a-new-check-reviewed-before-running-it",
68
+ set_in: commit_clause("; commit %s set it")), run_reviewed]
53
69
  end
54
70
  end
55
71
 
56
- # That a run keeps the line the last audit's review rested on, quoted with since when, unless a new one is
57
- # given, so whether it still holds can be judged from the template (#849); a record from before D63 kept none,
58
- # so there is nothing to say (#826).
59
- #: () -> Array[String]
60
- def kept_review
61
- return [] unless @since_last_audit&.key?("review_basis")
62
-
63
- [Prompts.text("assess-every-member/keep-the-last-review-basis-unless-you-give-a-new-one",
64
- since: @since_last_audit.fetch("review_basis_since"),
65
- basis: @since_last_audit.fetch("review_basis"))]
72
+ # The commit that made the check what it is now, stated in the placeholder itself, since the template printed
73
+ # alone has no context beside it (#1024); nothing outside git, or when no commit holds it.
74
+ #: (String) -> String
75
+ def commit_clause(format)
76
+ commit = @since_last_audit&.fetch("changed_in", nil)
77
+ commit ? format(format, commit) : ""
66
78
  end
67
79
 
68
80
  # Run a reviewed check, then report it with what its review rested on.
@@ -0,0 +1,64 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_head"
5
+ require_relative "prompts"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # The correction request that follows an assessment with findings: one disposition for each, with a guide to
11
+ # every disposition's shape (#414), and what submitting the assessment stored.
12
+ class CorrectionRequest
13
+ # head is what the answer hands back unchanged, the request's id and the basis the correction depends on;
14
+ # placeholders is the text the template leaves in each field the agent writes (#725).
15
+ #: (head: AnswerHead, principle_id: String, findings: Array[untyped], placeholders: Hash[String, String]) -> void
16
+ def initialize(head:, principle_id:, findings:, placeholders:)
17
+ @head = head
18
+ @principle_id = principle_id
19
+ @findings = findings
20
+ @placeholders = placeholders
21
+ freeze
22
+ end
23
+
24
+ # The id the request is answered under.
25
+ #: () -> String
26
+ def request_id = @head.request_id
27
+
28
+ # The findings to dispose of, the question and a guide to every disposition's shape.
29
+ #: () -> Hash[String, untyped]
30
+ def context
31
+ { "principle_id" => @principle_id, "findings" => @findings,
32
+ "question" => Prompts.text("dispose-of-each-finding/fix-or-record-each-finding"),
33
+ "answer_guide" => Prompts.data("dispose-of-each-finding/answer-guide") }
34
+ end
35
+
36
+ # The answer to fill in, as submit-answer prints it and show-answer-check prints it alone: one disposition for
37
+ # each finding, each action the placeholder that says what it may be and what each adds, so both print one
38
+ # template (D81 step 3, #1011).
39
+ #: () -> Hash[String, untyped]
40
+ def template
41
+ @head.leading("dispositions" => @findings.map do |finding|
42
+ { "finding_id" => finding["id"], "action" => @placeholders.fetch("action"),
43
+ "reason" => @placeholders.fetch("reason"), "changed_members" => [], "evidence" => [],
44
+ "reassessment" => @placeholders.fetch("reassessment"), "recorded_at" => nil, "waits_on" => nil }
45
+ end)
46
+ end
47
+
48
+ # What submitting the assessment stored, and what submitting it again would do, so an assessment submitted
49
+ # twice plainly replaced nothing: in git, where the audit has a base commit, nothing; outside git, the open
50
+ # record, which keeps what the audit began from.
51
+ #: () -> String
52
+ def stored
53
+ again = "Submitting the same assessment again prints this same request"
54
+ unless @head.based_on_a_commit?
55
+ return "This audit's open record, listed under wrote when it was first written, keeps what the audit " \
56
+ "began from. #{again} and leaves that record as it is."
57
+ end
58
+
59
+ "Nothing is stored yet: this request was computed from your assessment and the project. #{again} and " \
60
+ "replaces nothing; the audit record is written when the audit completes."
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,71 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation"
5
+ require_relative "prompts"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # The first full audit's place after mapping: a commit can supply the members' baseline in git, while the
11
+ # keeping principle also needs an own principle whose keeping it can judge.
12
+ class FirstAudit
13
+ #: (Invocation, in_git: bool) -> void
14
+ def initialize(invocation, in_git:)
15
+ @invocation = invocation
16
+ @in_git = in_git
17
+ freeze
18
+ end
19
+
20
+ # The step after adding members, since the next add-member remains the command to answer with.
21
+ #: (String, ?keeps_others_held: bool) -> String
22
+ def after_mapping(id, keeps_others_held: false)
23
+ return after_keeping_mapping(id) if keeps_others_held
24
+
25
+ if @in_git
26
+ return "When the map lists every member, commit it: list-member-problems then reports any change to a " \
27
+ "member since that commit. Only a full audit judges whether they reinforce the principle.\n" \
28
+ "To start it when you choose: #{start_audit(id)}"
29
+ end
30
+
31
+ "When the map lists every member, start the audit. It judges whether they reinforce the principle, and " \
32
+ "gives each member the baseline list-member-problems compares it with.\nTo start it: #{start_audit(id)}"
33
+ end
34
+
35
+ # The keeping audit waits until there is a project's own principle for it to keep held.
36
+ #: (String, existing_principles: Array[Hash[String, untyped]]) -> String
37
+ def keeping(id, existing_principles:)
38
+ if existing_principles.empty?
39
+ return "This principle's first full audit judges whether the keeping works, so leave it until one of the " \
40
+ "project's own principles is mapped.\n" \
41
+ "To find the first of them: #{@invocation.in_project("list-candidate-files")}"
42
+ end
43
+
44
+ "This principle's first full audit judges whether the keeping works for the principles under " \
45
+ "existing_principles.\n" \
46
+ "To start it: #{@invocation.in_project("start-audit", id)}"
47
+ end
48
+
49
+ private
50
+
51
+ # Adding the keeping passage retains setup's first-own-principle prerequisite.
52
+ #: (String) -> String
53
+ def after_keeping_mapping(id)
54
+ baseline = if @in_git
55
+ "When the map lists every member, commit it: that commit is the members' baseline until an audit."
56
+ else
57
+ "Outside git, the first full audit gives each member its baseline."
58
+ end
59
+ Prompts.text("set-principles-up/first-keeping-audit-after-own-principle",
60
+ baseline: baseline,
61
+ find: @invocation.in_project("list-candidate-files"),
62
+ audit: start_audit(id))
63
+ end
64
+
65
+ #: (String) -> String
66
+ def start_audit(id)
67
+ @invocation.in_project("start-audit", id)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -79,7 +79,8 @@ module Principles
79
79
  "## #{heading}\n\n#{entries.map { |usage, summary| "- `#{usage}`: #{summary}" }.join("\n")}"
80
80
  end
81
81
  Prompts.markdown("learn-what-a-command-does/every-command-and-how-they-chain",
82
- version: @version, commands: commands.join("\n\n"), executable: @executable)
82
+ version: @version, commands: commands.join("\n\n"), executable: @executable,
83
+ project_selection: Prompts.text("learn-what-a-command-does/select-the-project-root"))
83
84
  end
84
85
  end
85
86
 
@@ -101,7 +102,7 @@ module Principles
101
102
  numbered = @steps.each_with_index.map { |step, index| "#{index + 1}. #{step_text(step)}" }
102
103
  ["# #{@executable} #{@usage}", Prompts.markdown(@prompt, executable: @executable), @writes, "## Steps",
103
104
  numbered.join("\n"), "A step that fails prints a refusal with its code and a repair.",
104
- "`--project PATH` is optional: it defaults to the current directory."].join("\n\n")
105
+ Prompts.text("learn-what-a-command-does/select-the-project-root")].join("\n\n")
105
106
  end
106
107
 
107
108
  private
@@ -0,0 +1,74 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # One instruction a judgement request prints under its own field: its paragraphs, each printed only when the
8
+ # request holds the case it explains, and every one when the agent reads the field whole (D81 step 2, #983).
9
+ class Instruction
10
+ #: String
11
+ attr_reader :field
12
+
13
+ # An instruction of a prompt's paragraphs, each held when the block, given the paragraph, says the request
14
+ # holds its case; key a case by what the paragraph says, never by its position, which an edit moves.
15
+ #: (String, String) { (String) -> bool } -> Instruction
16
+ def self.of_paragraphs(field, text, &held)
17
+ new(field, text.split("\n\n").map { |paragraph| [paragraph, held.call(paragraph)] })
18
+ end
19
+
20
+ # paragraphs are each paragraph, in order, with whether the request holds its case.
21
+ #: (String, Array[[String, bool]]) -> void
22
+ def initialize(field, paragraphs)
23
+ @field = field
24
+ @paragraphs = paragraphs
25
+ freeze
26
+ end
27
+
28
+ # The field as the request prints it, with the paragraphs whose case it holds; nothing when it holds none.
29
+ #: () -> Hash[String, String]
30
+ def printed
31
+ held = @paragraphs.select { |_, case_held| case_held }.map(&:first)
32
+ held.empty? ? {} : { @field => held.join("\n\n") }
33
+ end
34
+
35
+ # Every paragraph, whether or not the request holds its case.
36
+ #: () -> String
37
+ def whole = @paragraphs.map(&:first).join("\n\n")
38
+
39
+ # Whether the request prints some paragraphs and leaves others out, so the field read as printed is not whole.
40
+ #: () -> bool
41
+ def trimmed? = @paragraphs.any? { |_, held| held } && @paragraphs.any? { |_, held| !held }
42
+ end
43
+
44
+ # The guide to an answer's shapes a judgement request prints under its own field: its entries, each printed only
45
+ # when the request holds the case it shows, and every one when the agent reads the field whole (D81 step 2).
46
+ class GuideInstruction
47
+ #: String
48
+ attr_reader :field
49
+
50
+ # guide is every entry; held says, by entry name, whether the request holds its case. narrowed is, by name, an
51
+ # entry as the request prints it when it holds the entry's case but not every case within it (#983).
52
+ #: (String, Hash[String, untyped], ?narrowed: Hash[String, untyped]) { (String) -> bool } -> void
53
+ def initialize(field, guide, narrowed: {}, &held)
54
+ @field = field
55
+ @guide = guide
56
+ @held = guide.filter_map { |name, entry| [name, narrowed.fetch(name, entry)] if held.call(name) }
57
+ .to_h #: Hash[String, untyped]
58
+ freeze
59
+ end
60
+
61
+ # The field as the request prints it, with the entries whose case it holds; nothing when it holds none.
62
+ #: () -> Hash[String, untyped]
63
+ def printed = @held.empty? ? {} : { @field => @held }
64
+
65
+ # Every entry, whether or not the request holds its case.
66
+ #: () -> Hash[String, untyped]
67
+ def whole = @guide
68
+
69
+ # Whether the request prints some entries and leaves others out, so the field read as printed is not whole.
70
+ #: () -> bool
71
+ def trimmed? = !@held.empty? && @held != @guide
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,51 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # A JSON result printed pretty, but for one array whose entries each print compact on a line of their own.
10
+ # list-candidate-files' file entries are that array: pretty-printing cost 17% of a 66 KB result, and one compact
11
+ # line of 36 KB is the worst shape to read by lines (#1155). It is the first case of ticket 007's decision on the
12
+ # output format; every other result prints pretty.
13
+ class JsonWithEntriesOnLines
14
+ # Stands in for the array while the rest prints pretty. Only its first place is replaced, so text from a project
15
+ # file that holds it, which prints after the array, is left as it is.
16
+ MARKER = "\u0000entries on lines of their own\u0000"
17
+
18
+ # The array is result[under][key].
19
+ #: (Hash[String, untyped], under: String, key: String) -> void
20
+ def initialize(result, under:, key:)
21
+ @result = result
22
+ @under = under
23
+ @key = key
24
+ freeze
25
+ end
26
+
27
+ # The result as JSON generates it, so a reader of the values need not know the layout.
28
+ #: (?untyped, *untyped) -> String
29
+ def to_json(state = nil, *) = @result.to_json(state)
30
+
31
+ # The result as printed.
32
+ #: () -> String
33
+ def text
34
+ marked = JSON.pretty_generate(@result.merge(@under => @result.fetch(@under).merge(@key => MARKER)))
35
+ place = /^( *)(.*)#{Regexp.escape(JSON.generate(MARKER))}/
36
+ marked.sub(place) { "#{Regexp.last_match(1)}#{Regexp.last_match(2)}#{lines(Regexp.last_match(1).to_s)}" }
37
+ end
38
+
39
+ private
40
+
41
+ # The array's entries, each compact on its own line, one step in from indent.
42
+ #: (String) -> String
43
+ def lines(indent)
44
+ entries = @result.fetch(@under).fetch(@key)
45
+ return "[]" if entries.empty?
46
+
47
+ "[\n#{entries.map { |entry| "#{indent} #{JSON.generate(entry)}" }.join(",\n")}\n#{indent}]"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -10,9 +10,15 @@ module Principles
10
10
  module Views
11
11
  # How a full audit's request shows the members to check against the principle's activation (#355 slice 3).
12
12
  class LoadsToCheckResult
13
- # listed is the members to check, nil when there are none, and id the principle they belong to.
14
- #: (Invocation, Hash[String, untyped]?, String) -> void
15
- def initialize(invocation, listed, id)
13
+ # What a decision may be, as the answer printed alone says where it is written (#746).
14
+ DECISION = "accepted, with reason saying why the member loads as it does; if the activation is wrong " \
15
+ "instead, change it and start the audit again" #: String
16
+
17
+ # listed is the members to check, nil when there are none, and id the principle they belong to; placeholders
18
+ # is the text the template alone prints in each field of a decision beside it, which left is not given (#994).
19
+ #: (Invocation, Hash[String, untyped]?, String, placeholders: Hash[String, String]) -> void
20
+ def initialize(invocation, listed, id, placeholders:)
21
+ @placeholders = placeholders
16
22
  @invocation = invocation
17
23
  @listed = listed
18
24
  @id = id
@@ -26,9 +32,10 @@ module Principles
26
32
  listed = @listed or return
27
33
 
28
34
  decisions = listed.fetch("rows").map { |row| { "member_id" => row.fetch("member_id"), "decision" => nil } }
29
- RequestPart.new(shown: { "loads_to_check_against_activation" => listed,
30
- "loads_to_check_instruction" => instruction },
31
- slots: { "loading_decisions" => decisions })
35
+ RequestPart.new(shown: { "loads_to_check_against_activation" => listed },
36
+ instructions: [Instruction.of_paragraphs("loads_to_check_instruction", instruction) { true }],
37
+ slots: { "loading_decisions" => decisions },
38
+ help: { "loading_decisions" => { "decision" => DECISION, **@placeholders } })
32
39
  end
33
40
 
34
41
  private
@@ -0,0 +1,31 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # What add-member's result needs to know of the map a member joined, beyond the map itself: whether its
8
+ # principle keeps the others held, which changes the step after mapping (D71), and whether a full audit's
9
+ # correction may be open on it, so that the member may fix one of its findings (D72, #1023), and whether to repeat
10
+ # what to do after mapping: with a principle's first member, or in git the first since the map's last commit, so
11
+ # members mapped in one sitting do not each repeat it (#1025).
12
+ class MapAddedTo
13
+ #: bool
14
+ attr_reader :keeps_others_held
15
+
16
+ #: bool
17
+ attr_reader :correction_may_be_open
18
+
19
+ #: bool
20
+ attr_reader :reminded
21
+
22
+ #: (?keeps_others_held: bool, ?correction_may_be_open: bool, ?reminded: bool) -> void
23
+ def initialize(keeps_others_held: false, correction_may_be_open: false, reminded: true)
24
+ @keeps_others_held = keeps_others_held
25
+ @correction_may_be_open = correction_may_be_open
26
+ @reminded = reminded
27
+ freeze
28
+ end
29
+ end
30
+ end
31
+ end