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
@@ -4,7 +4,9 @@
4
4
  require_relative "invocation"
5
5
  require_relative "printed_principle"
6
6
  require_relative "lines_shared_with_member"
7
+ require_relative "map_added_to"
7
8
  require_relative "activation_in_hand"
9
+ require_relative "first_audit"
8
10
  require_relative "prompts"
9
11
 
10
12
  module Principles
@@ -60,15 +62,13 @@ module Principles
60
62
  end
61
63
 
62
64
  # shared says which members share a line with the new one; added lists them only when there are some, as it
63
- # carries a check only when one is named.
64
- #: (PrintedPrinciple, added: Hash[String, untyped], ?shared: LinesSharedWithMember) -> Hash[String, untyped]
65
- def member_added(principle, added:, shared: LinesSharedWithMember.new)
65
+ # carries a check only when one is named. joined is what the result says of the map the member joined.
66
+ #: (PrintedPrinciple, added: Hash[String, untyped], ?shared: LinesSharedWithMember, ?joined: MapAddedTo)
67
+ #| -> Hash[String, untyped]
68
+ def member_added(principle, added:, shared: LinesSharedWithMember.new, joined: MapAddedTo.new)
66
69
  added = added.merge(shared.to_h)
67
- shown = @invocation.in_project("show-principle", principle.id)
68
- question(principle, "#{span(added)}#{shared.note}Add the next member the same way. Commit " \
69
- "#{principle.file} as it changes, so the project's history shows each change; in git, " \
70
- "start-audit refuses a map that is not committed.\n" \
71
- "To see the map so far: #{shown}\n#{start_when_mapped(principle.id)}",
70
+ question(principle, "#{span(added)}#{shared.note}Add the next member the same way. " \
71
+ "#{after_the_member(principle, added.fetch("id"), joined)}".rstrip,
72
72
  add_member_command(principle.id), shown: { "member_count" => principle.members.length })
73
73
  .merge("added" => added)
74
74
  end
@@ -114,19 +114,47 @@ module Principles
114
114
  question(principle, "#{done} Check the other members, then start the audit.\nIf you hold a correction " \
115
115
  "request from submit-answer (phase correction), list #{member} in the " \
116
116
  "changed_map_entries of the fixed disposition this change fixes, and submit it instead: " \
117
- "#{@invocation.submit_answer("REQUEST")}",
117
+ "#{@invocation.submit_answer("REQUEST_ID")}",
118
118
  start_audit(principle.id))
119
119
  end
120
120
 
121
121
  #: (PrintedPrinciple, removed: String) -> Hash[String, untyped]
122
122
  def member_removed(principle, removed:)
123
123
  question(principle, "Removed #{removed}. Add or remove members until the map is right.\n" \
124
- "#{start_when_mapped(principle.id)}",
124
+ "#{FirstAudit.new(@invocation, in_git: @in_git).after_mapping(principle.id)}",
125
125
  add_member_command(principle.id))
126
126
  end
127
127
 
128
128
  private
129
129
 
130
+ # What add-member's question says after the member it added, id, as joined says of the map: how a fix claims
131
+ # it while a correction may be open, then what to do after mapping, each only when joined says to remind, once
132
+ # per sitting (#1025, #1057).
133
+ #: (PrintedPrinciple, String, MapAddedTo) -> String
134
+ def after_the_member(principle, id, joined)
135
+ "#{claimed_by_a_fix(id) if joined.correction_may_be_open && joined.reminded}" \
136
+ "#{after_adding(principle, keeps_others_held: joined.keeps_others_held) if joined.reminded}"
137
+ end
138
+
139
+ # How a member added while a correction is open joins it: a fix claims it, and the next full audit assesses it
140
+ # (D72). It ends its own line, since it ends with a command.
141
+ #: (String) -> String
142
+ def claimed_by_a_fix(member)
143
+ "If you hold a correction request from submit-answer (phase correction) and this member fixes one of its " \
144
+ "findings, name #{member} in the changed_members of the fixed disposition; the next full audit assesses " \
145
+ "it.\nTo submit the correction instead: #{@invocation.submit_answer("REQUEST_ID")}\n"
146
+ end
147
+
148
+ # What add-member says after the member it added: to commit the map as it changes, how to see it, and the full
149
+ # audit's place once it lists every member.
150
+ #: (PrintedPrinciple, keeps_others_held: bool) -> String
151
+ def after_adding(principle, keeps_others_held:)
152
+ "Commit #{principle.file} as it changes, so the project's history shows each change; in git, start-audit " \
153
+ "refuses a map that is not committed.\n" \
154
+ "To see the map so far: #{@invocation.in_project("show-principle", principle.id)}\n" \
155
+ "#{FirstAudit.new(@invocation, in_git: @in_git).after_mapping(principle.id, keeps_others_held:)}"
156
+ end
157
+
130
158
  # The lines a member spans, said so that a passage cut short shows; it ends with a space.
131
159
  #: (Hash[String, untyped]) -> String
132
160
  def span(member)
@@ -147,19 +175,6 @@ module Principles
147
175
  @invocation.in_project("start-audit", id)
148
176
  end
149
177
 
150
- # The step after adding members, as the question's last line, since answer_with is the next add-member.
151
- #: (String) -> String
152
- def start_when_mapped(id)
153
- if @in_git
154
- return "When the map lists every member, commit it: list-member-problems then reports any change to a " \
155
- "member since that commit. Only a full audit judges whether they reinforce the principle.\n" \
156
- "To start it when you choose: #{start_audit(id)}"
157
- end
158
-
159
- "When the map lists every member, start the audit. It judges whether they reinforce the principle, and " \
160
- "gives each member the baseline list-member-problems compares it with.\nTo start it: #{start_audit(id)}"
161
- end
162
-
163
178
  #: (String) -> String
164
179
  def add_member_command(id)
165
180
  @invocation.in_project("add-member", id, usage: ADD_MEMBER_USAGE)
@@ -13,17 +13,22 @@ module Principles
13
13
  # member holds the member's id, role and evidence; commits holds "base", HEAD, and "baseline", the commit
14
14
  # the member's baseline text is at, and "audit_base" when the baseline is later than the audit's base;
15
15
  # member_lines holds its own lines at each, or their counts when too long; paths holds the paths the change
16
- # spans, its path at the baseline first.
16
+ # spans, its path at the baseline first; first_changed_lines the first line on each side the other lacks.
17
17
  #: (member: Hash[String, untyped], commits: Hash[String, String], member_lines: Hash[String, untyped],
18
- #| paths: Array[String]) -> void
19
- def initialize(member:, commits:, member_lines:, paths:)
18
+ #| first_changed_lines: Hash[String, String], paths: Array[String]) -> void
19
+ def initialize(member:, commits:, member_lines:, first_changed_lines:, paths:)
20
20
  @member = member
21
21
  @commits = commits
22
22
  @member_lines = member_lines
23
+ @first_changed_lines = first_changed_lines
23
24
  @paths = paths
24
25
  freeze
25
26
  end
26
27
 
28
+ # The first line on each side the other lacks, which the template's quotes print (#1111).
29
+ #: Hash[String, String]
30
+ attr_reader :first_changed_lines
31
+
27
32
  #: () -> String
28
33
  def member_id
29
34
  @member.fetch("id")
@@ -39,14 +44,26 @@ module Principles
39
44
  #: () -> Hash[String, untyped]
40
45
  def to_h
41
46
  read = read_the_change
42
- lines = @member_lines.key?("omitted") ? @member_lines.merge("read_instead" => read) : @member_lines
47
+ lines = @member_lines.key?("omitted") ? @member_lines.merge("read_instead" => read) : with_read_instead(read)
43
48
  { "member" => @member, "baseline_commit" => @commits.fetch("baseline"), "base_commit" => base_commit,
44
49
  **@commits.slice("audit_base").transform_keys { "audit_base_commit" },
45
- "member_lines" => lines, "read_the_change" => read }
50
+ "member_lines" => lines, "first_changed_lines" => @first_changed_lines, "read_the_change" => read }
46
51
  end
47
52
 
48
53
  private
49
54
 
55
+ # The member's lines, each side of their changed region left out pointing at read, as the whole lines do (#1103).
56
+ #: (String) -> Hash[String, untyped]
57
+ def with_read_instead(read)
58
+ region = @member_lines["changed_region"]
59
+ return @member_lines unless region
60
+
61
+ sides = region.transform_values do |side|
62
+ side.is_a?(Hash) && side.key?("omitted") ? side.merge("read_instead" => read) : side
63
+ end
64
+ @member_lines.merge("changed_region" => sides)
65
+ end
66
+
50
67
  # Each word quoted for the shell, and every path read by git as written, not as a pattern (#558).
51
68
  #: () -> String
52
69
  def read_the_change
@@ -6,15 +6,15 @@ require_relative "invocation"
6
6
  module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
- # The commands that repair a member this tool cannot find: move it, or remove it. A member whose file is
10
- # gone is moved to the path the agent finds, keeping its own section, passage or query, so a rename keeps
11
- # its audit (#268). A member whose place in its file is gone is moved within it, or to another file its text
12
- # moved into (#378); a passage keeps its anchors, so a move cannot silently widen it to its whole new
13
- # section (#251). Which fits is the agent's to judge.
9
+ # The commands that repair a member this tool cannot find: each move Models::MemberRepairMoves gives, then
10
+ # remove it. Which fits is the agent's to judge.
14
11
  class MemberRepairs
15
12
  # The flag that names each locator field in a printed command.
16
13
  FLAGS = { "section" => "--section", "starting_at" => "--starting-at", "ending_at" => "--ending-at",
17
- "query" => "--query" }.freeze #: Hash[String, String]
14
+ "query" => "--query", "path" => "--path" }.freeze #: Hash[String, String]
15
+ # The placeholder the agent fills in for each field a move leaves to it.
16
+ PLACEHOLDERS = { "section" => "HEADING", "starting_at" => "NEW_OPENING_TEXT", "query" => "QUERY",
17
+ "path" => "NEW_PATH" }.freeze #: Hash[String, String]
18
18
 
19
19
  #: (Invocation) -> void
20
20
  def initialize(invocation)
@@ -22,60 +22,29 @@ module Principles
22
22
  freeze
23
23
  end
24
24
 
25
- # The repairs for member, a printed member with its "id", its locator fields and the code of the refusal
26
- # that says why it cannot be found, as "code" or show-principle's "error", of principle id. Each is
27
- # copyable as it is: move-member, with NEW_PATH, HEADING or QUERY to fill in, then, for a section or
28
- # passage lost from a file that is still there, the same move into another file, then remove-member.
29
- #: (String, Hash[String, untyped]) -> Array[String]
30
- def commands(id, member)
31
- member_id = member.fetch("id")
32
- [move(id, member_id, member), *move_elsewhere(id, member_id, member),
33
- @invocation.in_project("remove-member", id, member_id)]
25
+ # The repairs for member_id of principle id: each of moves, as Models::MemberRepairMoves gives them, the locator
26
+ # fields it keeps and those to fill in, as a copyable move-member, then remove-member.
27
+ #: (String, String, Array[Hash[String, untyped]]) -> Array[String]
28
+ def commands(id, member_id, moves)
29
+ [*moves.map { move(id, member_id, it) }, @invocation.in_project("remove-member", id, member_id)]
34
30
  end
35
31
 
36
- # member, as show-principle prints it, with its repairs as repair_with when broken, which the controller says
37
- # of a member an audit would refuse (#272).
38
- #: (String, Hash[String, untyped], broken: bool) -> Hash[String, untyped]
39
- def beside(id, member, broken:)
40
- return member unless broken
32
+ # member, as show-principle prints it, with its repairs as repair_with when moves, its moves, are given, as the
33
+ # controller gives them for a member an audit would refuse (#272).
34
+ #: (String, Hash[String, untyped], Array[Hash[String, untyped]]?) -> Hash[String, untyped]
35
+ def beside(id, member, moves)
36
+ return member unless moves
41
37
 
42
- member.merge("repair_with" => commands(id, member))
38
+ member.merge("repair_with" => commands(id, member.fetch("id"), moves))
43
39
  end
44
40
 
45
41
  private
46
42
 
47
43
  #: (String, String, Hash[String, untyped]) -> String
48
- def move(id, member_id, member)
49
- if file_unreadable?(member)
50
- kept = flags(member, FLAGS.keys)
51
- return @invocation.in_project("move-member", id, member_id, options: kept, usage: "--path NEW_PATH")
52
- end
53
- return @invocation.in_project("move-member", id, member_id, usage: "--query QUERY") if member["query"]
54
-
55
- @invocation.in_project("move-member", id, member_id, options: flags(member, %w[starting_at ending_at]),
56
- usage: "--section HEADING")
57
- end
58
-
59
- # A section or passage lost from a file that is still there may have moved into another file (#378).
60
- #: (String, String, Hash[String, untyped]) -> Array[String]
61
- def move_elsewhere(id, member_id, member)
62
- return [] if member["query"] || file_unreadable?(member)
63
-
64
- anchors = flags(member, %w[starting_at ending_at])
65
- [@invocation.in_project("move-member", id, member_id, options: anchors,
66
- usage: "--path NEW_PATH --section HEADING")]
67
- end
68
-
69
- # Whether member's file cannot be read, by the refusal it carries.
70
- #: (Hash[String, untyped]) -> bool
71
- def file_unreadable?(member)
72
- (member["code"] || member.dig("error", "code")) == "unreadable_file"
73
- end
74
-
75
- # The flags, with their values, of the locator fields named in keys that member has.
76
- #: (Hash[String, untyped], Array[String]) -> Array[String]
77
- def flags(member, keys)
78
- keys.select { |key| member[key] }.flat_map { |key| [FLAGS.fetch(key), member.fetch(key)] }
44
+ def move(id, member_id, move)
45
+ kept = move.fetch("keep").flat_map { |field, value| [FLAGS.fetch(field), value] }
46
+ usage = move.fetch("fill").map { "#{FLAGS.fetch(it)} #{PLACEHOLDERS.fetch(it)}" }.join(" ")
47
+ @invocation.in_project("move-member", id, member_id, options: kept, usage: usage)
79
48
  end
80
49
  end
81
50
  end
@@ -5,6 +5,7 @@ require "json"
5
5
  require_relative "invocation"
6
6
  require_relative "problem_lines"
7
7
  require_relative "prompts"
8
+ require_relative "record_waiting_on_an_upgrade"
8
9
  require_relative "visible_text"
9
10
 
10
11
  module Principles
@@ -12,8 +13,9 @@ module Principles
12
13
  module Views
13
14
  # list-member-problems --commits-after COMMIT --hook-event EVENT: the whole JSON the plugin's after-commit hook
14
15
  # prints for Claude Code, which puts its additionalContext beside the Bash call's result (D73), or nothing at all.
15
- # Claude Code asks for that text to state facts, not to give orders, so it says what the commits changed and
16
- # which command shows more.
16
+ # Claude Code asks for that text to state facts, not to give orders, so it says what the commits changed,
17
+ # which command shows more and which skill to start from (#986). It names that skill as a user invokes it,
18
+ # /principles, in Claude Code, the only host whose hook prints this JSON.
17
19
  class MembersACommitChanged
18
20
  NOTHING = Lines.new(stdout: "", stderr: "", status: 0).freeze #: Lines
19
21
 
@@ -23,14 +25,16 @@ module Principles
23
25
  freeze
24
26
  end
25
27
 
26
- # changed is each member the commits changed, as list-member-problems lists it; others is how many other
27
- # changed members it still lists.
28
- #: (String, Array[Hash[String, untyped]], others: Integer) -> Lines
29
- def changed(event, changed, others:)
30
- rows = changed.map { |member| ProblemLines.new(@invocation).row(member) }
31
- reported(event, [Prompts.text("report-after-a-commit/the-commits-changed-these-members"), *rows,
32
- *still_listed(others), Prompts.text("report-after-a-commit/this-command-shows-each-one"),
33
- command])
28
+ # changed is each member the commits changed, as list-member-problems lists it; others is how many other changed
29
+ # members it still lists. Those it marks waiting_on_an_upgrade are named apart, with the waits that say why, and
30
+ # no audit to run (D85 V8, #1066); the others still listed are counted beside them too, since this copy may
31
+ # audit those (#1077).
32
+ #: (String, Array[Hash[String, untyped]], others: Integer, ?waits: Array[RecordWaitingOnAnUpgrade]) -> Lines
33
+ def changed(event, changed, others:, waits: [])
34
+ waiting, auditable = changed.partition { |member| member["waiting_on_an_upgrade"] }
35
+ reported(event, [*(to_audit(auditable, others) unless auditable.empty?),
36
+ *(waiting_lines(waiting, waits) unless waiting.empty?),
37
+ *(listed_beside_the_waiting(others) if auditable.empty?)])
34
38
  end
35
39
 
36
40
  # A refusal with code, which the commits could have caused.
@@ -42,6 +46,32 @@ module Principles
42
46
 
43
47
  private
44
48
 
49
+ # The members to audit, as rows, then what shows more and the skill to start from.
50
+ #: (Array[Hash[String, untyped]], Integer) -> Array[String]
51
+ def to_audit(changed, others)
52
+ [Prompts.text("report-after-a-commit/the-commits-changed-these-members"), *rows(changed),
53
+ *still_listed(others), Prompts.text("report-after-a-commit/this-command-shows-each-one"), command,
54
+ Prompts.text("report-after-a-commit/the-principles-skill-is-where-to-start")]
55
+ end
56
+
57
+ # The other changed members still listed, and the command that shows each, or nothing when none is.
58
+ #: (Integer) -> Array[String]
59
+ def listed_beside_the_waiting(others)
60
+ return [] if others.zero?
61
+
62
+ [*still_listed(others), Prompts.text("report-after-a-commit/this-command-shows-each-one"), command]
63
+ end
64
+
65
+ # The members whose audits wait on an upgrade, as rows, then each wait's line, which says how to update.
66
+ #: (Array[Hash[String, untyped]], Array[RecordWaitingOnAnUpgrade]) -> Array[String]
67
+ def waiting_lines(waiting, waits)
68
+ [Prompts.text("report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade"),
69
+ *rows(waiting), *waits.map(&:to_s)]
70
+ end
71
+
72
+ #: (Array[Hash[String, untyped]]) -> Array[String]
73
+ def rows(members) = members.map { |member| ProblemLines.new(@invocation).row(member) }
74
+
45
75
  # The line saying how many other changed members list-member-problems still lists, or none when it lists none.
46
76
  #: (Integer) -> Array[String]
47
77
  def still_listed(others)
@@ -4,6 +4,7 @@
4
4
  require_relative "invocation"
5
5
  require_relative "meta_principle_passage"
6
6
  require_relative "printed_principle"
7
+ require_relative "first_audit"
7
8
 
8
9
  module Principles
9
10
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -150,20 +151,8 @@ module Principles
150
151
  "This principle's first full audit gives the passage's member its baseline, since this project " \
151
152
  "is not in git."
152
153
  end
153
- [baseline, first_audit(id, existing_principles)].join(" ")
154
- end
155
-
156
- #: (String, Array[Hash[String, untyped]]) -> String
157
- def first_audit(id, existing_principles)
158
- if existing_principles.empty?
159
- return "This principle's first full audit judges whether the keeping works, so leave it until one of the " \
160
- "project's own principles is mapped.\n" \
161
- "To find the first of them: #{@invocation.in_project("list-candidate-files")}"
162
- end
163
-
164
- "This principle's first full audit judges whether the keeping works for the principles under " \
165
- "existing_principles.\n" \
166
- "To start it: #{@invocation.in_project("start-audit", id)}"
154
+ [baseline, FirstAudit.new(@invocation, in_git: @in_git)
155
+ .keeping(id, existing_principles: existing_principles)].join(" ")
167
156
  end
168
157
  end
169
158
  end
@@ -0,0 +1,43 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "check_notes"
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 check_result a one-member audit's template starts with for a checked member, whose check is the one the last
11
+ # audit ran, since any other is refused at its start (#1071). It asks for a passing run alone, since one that fails
12
+ # or cannot run is refused as a full audit's to judge, so it prints no not_run_reason and says nothing of how often
13
+ # full audits run it (#1112).
14
+ class OneMemberCheckResultTemplate
15
+ # The template for the checked member a request lists as entry, with its check, how that stands to the last
16
+ # audit's and any hidden characters in it; nil for a member without a check. review_basis is the text it prints
17
+ # there, which an answer leaves as printed to keep the line the last audit kept (#1010).
18
+ #: (Hash[String, untyped], review_basis: String) -> Hash[String, untyped]?
19
+ def self.for(entry, review_basis:)
20
+ check = entry["check"] or return
21
+ new(check, CheckNotes.new(entry["check_since_last_audit"], entry.fetch("check_hidden_characters", [])),
22
+ review_basis:).to_h
23
+ end
24
+
25
+ #: (String, CheckNotes, review_basis: String) -> void
26
+ def initialize(check, notes, review_basis:)
27
+ @check = check
28
+ @notes = notes
29
+ @review_basis = review_basis
30
+ freeze
31
+ end
32
+
33
+ #: () -> Hash[String, untyped]
34
+ def to_h
35
+ { "command" => @check,
36
+ "exit_status" => [@notes.hidden_characters,
37
+ Prompts.text("acknowledge-a-change/run-the-check-and-report-it-passing"),
38
+ *@notes.kept_review].compact.join(" "),
39
+ "review_basis" => @review_basis }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -23,9 +23,9 @@ module Principles
23
23
  def part
24
24
  return if @findings.empty?
25
25
 
26
- instruction = Prompts.text("assess-every-member/name-another-principles-open-finding-rather-than-raise-it")
27
- RequestPart.new(shown: { "open_findings_elsewhere" => @findings,
28
- "open_findings_elsewhere_instruction" => instruction }, slots: {})
26
+ text = Prompts.text("assess-every-member/name-another-principles-open-finding-rather-than-raise-it")
27
+ instruction = Instruction.of_paragraphs("open_findings_elsewhere_instruction", text) { true }
28
+ RequestPart.new(shown: { "open_findings_elsewhere" => @findings }, slots: {}, instructions: [instruction])
29
29
  end
30
30
  end
31
31
  end
@@ -16,6 +16,43 @@ module Principles
16
16
  # A waits_on longer than this is cut, so the line stays one short line.
17
17
  WAITS_ON_LIMIT = 80
18
18
 
19
+ # The session's start the line is worded for, as Claude Code's SessionStart hook names it: startup, resume,
20
+ # clear or compact. It says what the context holds already, and so when to raise the findings and when the
21
+ # line comes back.
22
+ class SessionStart
23
+ #: (String) -> void
24
+ def initialize(source)
25
+ @source = source
26
+ freeze
27
+ end
28
+
29
+ # A resumed conversation already holds the line printed when its context began (#1078).
30
+ #: () -> bool
31
+ def resumed? = @source == "resume"
32
+
33
+ # When to raise the findings: before the user's first task at startup, and at the next pause once the
34
+ # session is under way, after /clear or a compaction (#717).
35
+ #: () -> String
36
+ def raise_when
37
+ return Prompts.text("start-a-session/raise-them-before-the-first-task") if startup?
38
+
39
+ Prompts.text("start-a-session/raise-them-at-the-next-pause")
40
+ end
41
+
42
+ # When the line comes back: at each session start, and after each clear or compaction too (#741).
43
+ #: () -> String
44
+ def returns
45
+ return Prompts.text("start-a-session/it-returns-at-each-session-start") if startup?
46
+
47
+ Prompts.text("start-a-session/it-returns-after-each-clear-or-compaction-too")
48
+ end
49
+
50
+ private
51
+
52
+ #: () -> bool
53
+ def startup? = @source == "startup"
54
+ end
55
+
19
56
  #: (Invocation) -> void
20
57
  def initialize(invocation)
21
58
  @invocation = invocation
@@ -25,41 +62,42 @@ module Principles
25
62
  # waiting is nil when no finding is open, or the count of open findings with the oldest one's principle,
26
63
  # finding_id, days_open and, when it says, waits_on. not_found is each open finding, by principle and
27
64
  # finding_id, whose write-up can no longer be found where its recorded_at points (#694). source is the
28
- # session's start: startup, clear or compact.
65
+ # session's start: startup, resume, clear or compact.
29
66
  #: (Hash[String, untyped]?, ?Array[Hash[String, untyped]], ?source: String) -> Lines
30
67
  def short(waiting, not_found = [], source: "startup")
31
- Lines.new(stdout: waiting ? "#{line(waiting, not_found, source)}\n" : "", stderr: "", status: 0)
68
+ start = SessionStart.new(source)
69
+ Lines.new(stdout: waiting ? "#{line(waiting, not_found, start)}\n" : "", stderr: "", status: 0)
32
70
  end
33
71
 
34
72
  private
35
73
 
36
- #: (Hash[String, untyped], Array[Hash[String, untyped]], String) -> String
37
- def line(waiting, not_found, source)
74
+ #: (Hash[String, untyped], Array[Hash[String, untyped]], SessionStart) -> String
75
+ def line(waiting, not_found, start)
76
+ return resumed("#{how_long(waiting)} (#{oldest(waiting)})", not_found) if start.resumed?
77
+
78
+ whole(waiting, not_found, start)
79
+ end
80
+
81
+ # The line with what to do about the findings, for a context that does not hold it yet.
82
+ #: (Hash[String, untyped], Array[Hash[String, untyped]], SessionStart) -> String
83
+ def whole(waiting, not_found, start)
38
84
  count = waiting.fetch("count")
39
85
  them, each = pronouns(count)
40
86
  Prompts.text("start-a-session/act-on-the-open-findings",
41
- when: raise_when(source), returns: returns(source),
42
- findings: "#{counted(count)}#{waited(waiting)} (#{named(waiting)})",
87
+ when: start.raise_when, returns: start.returns,
88
+ findings: "#{how_long(waiting)} (#{named(waiting)})",
43
89
  without_waits_on: without_waits_on(count, waiting.fetch("without_waits_on", 0)),
44
90
  write_ups: write_ups(not_found),
45
91
  them: them, each: each, command: @invocation.in_project("list-open-findings"))
46
92
  end
47
93
 
48
- # When to raise the findings: before the user's first task at startup, and at the next pause once the session is
49
- # under way, after /clear or a compaction (#717).
50
- #: (String) -> String
51
- def raise_when(source)
52
- return Prompts.text("start-a-session/raise-them-before-the-first-task") if source == "startup"
53
-
54
- Prompts.text("start-a-session/raise-them-at-the-next-pause")
55
- end
56
-
57
- # When the line comes back: at each session start, and after each clear or compaction too (#741).
58
- #: (String) -> String
59
- def returns(source)
60
- return Prompts.text("start-a-session/it-returns-at-each-session-start") if source == "startup"
61
-
62
- Prompts.text("start-a-session/it-returns-after-each-clear-or-compaction-too")
94
+ # A resumed session's line: its conversation already holds the line printed when that context began, so this
95
+ # one gives the facts and where the instructions are, not the instructions again (#1078).
96
+ #: (String, Array[Hash[String, untyped]]) -> String
97
+ def resumed(findings, not_found)
98
+ Prompts.text("start-a-session/see-the-earlier-line",
99
+ findings: findings, write_ups: write_ups(not_found),
100
+ command: @invocation.in_project("list-open-findings", options: ["--short"]))
63
101
  end
64
102
 
65
103
  # How many of several open findings record no waits_on, since the line names only the oldest's (#736). One
@@ -91,6 +129,10 @@ module Principles
91
129
  "recorded_at points, and the list says why."
92
130
  end
93
131
 
132
+ # How many findings are open and how long the oldest has waited.
133
+ #: (Hash[String, untyped]) -> String
134
+ def how_long(waiting) = "#{counted(waiting.fetch("count"))}#{waited(waiting)}"
135
+
94
136
  #: (Integer) -> String
95
137
  def counted(count)
96
138
  count == 1 ? "1 audit finding is still open, " : "#{count} audit findings are still open, the oldest "
@@ -108,12 +150,24 @@ module Principles
108
150
  # text, so each is cut by characters first and then escaped, which may run past the limit to show them (#227).
109
151
  #: (Hash[String, untyped]) -> String
110
152
  def named(waiting)
111
- named = "#{waiting.fetch("principle")} #{VisibleText.new(waiting.fetch("finding_id"))}"
153
+ named = oldest(waiting)
112
154
  waits_on = waiting["waits_on"] or return named
113
- waits_on = closed("#{waits_on[0, WAITS_ON_LIMIT - 3]}...") if waits_on.length > WAITS_ON_LIMIT
155
+ waits_on = closed("#{whole_words(waits_on[0, WAITS_ON_LIMIT - 3].to_s)}...") if waits_on.length > WAITS_ON_LIMIT
114
156
  "#{named}, waits on: #{VisibleText.new(waits_on)}"
115
157
  end
116
158
 
159
+ # A cut waits_on up to its last whole word, so it never ends in part of one (#1078), or as cut when it is one
160
+ # word, which has no boundary to cut at.
161
+ #: (String) -> String
162
+ def whole_words(cut)
163
+ boundary = cut.rindex(" ") or return cut
164
+ cut[0, boundary].to_s
165
+ end
166
+
167
+ # The oldest finding's principle and id, which is free text and so escaped (#227).
168
+ #: (Hash[String, untyped]) -> String
169
+ def oldest(waiting) = "#{waiting.fetch("principle")} #{VisibleText.new(waiting.fetch("finding_id"))}"
170
+
117
171
  # A cut waits_on with a ")" for each "(" the cut left open, so the line's own parenthesis still reads as
118
172
  # closing the finding's name (#685).
119
173
  #: (String) -> String