principles 0.1.2 → 0.1.4

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 (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +132 -0
  3. data/README.md +10 -6
  4. data/lib/principles/command_line.rb +15 -6
  5. data/lib/principles/command_routes.rb +11 -1
  6. data/lib/principles/controllers/acknowledgement.rb +19 -4
  7. data/lib/principles/controllers/acknowledgements.rb +43 -12
  8. data/lib/principles/controllers/after_commit_report.rb +15 -2
  9. data/lib/principles/controllers/assessment.rb +7 -3
  10. data/lib/principles/controllers/audit.rb +17 -8
  11. data/lib/principles/controllers/audit_completion.rb +34 -9
  12. data/lib/principles/controllers/carrier_practices.rb +26 -0
  13. data/lib/principles/controllers/command.rb +31 -3
  14. data/lib/principles/controllers/correction.rb +15 -5
  15. data/lib/principles/controllers/full_audit_request.rb +38 -42
  16. data/lib/principles/controllers/inventory.rb +77 -71
  17. data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
  18. data/lib/principles/controllers/member_acknowledgement.rb +21 -11
  19. data/lib/principles/controllers/member_addition.rb +19 -4
  20. data/lib/principles/controllers/member_entries.rb +25 -6
  21. data/lib/principles/controllers/member_problems_report.rb +26 -6
  22. data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
  23. data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
  24. data/lib/principles/controllers/members_to_assess.rb +24 -7
  25. data/lib/principles/controllers/meta_principle_setup.rb +2 -2
  26. data/lib/principles/controllers/open_correction.rb +3 -2
  27. data/lib/principles/controllers/parts_to_read.rb +46 -5
  28. data/lib/principles/controllers/plugin_member_addition.rb +48 -0
  29. data/lib/principles/controllers/principle_listing.rb +84 -0
  30. data/lib/principles/controllers/request_logging.rb +52 -0
  31. data/lib/principles/controllers/running_tool.rb +45 -17
  32. data/lib/principles/data/branches_bringing_in.rb +52 -0
  33. data/lib/principles/data/changes_since.rb +56 -0
  34. data/lib/principles/data/claude_code_home.rb +58 -0
  35. data/lib/principles/data/command-steps.json +91 -15
  36. data/lib/principles/data/decoded_leaf.rb +63 -0
  37. data/lib/principles/data/head_reflog.rb +13 -2
  38. data/lib/principles/data/kept_line.rb +32 -0
  39. data/lib/principles/data/known_marketplaces.rb +50 -0
  40. data/lib/principles/data/logged_request_matches.rb +138 -0
  41. data/lib/principles/data/logged_request_scan.rb +120 -0
  42. data/lib/principles/data/map_files.rb +18 -4
  43. data/lib/principles/data/plugin_folder.rb +85 -0
  44. data/lib/principles/data/plugin_registry.rb +73 -0
  45. data/lib/principles/data/principles_store.rb +49 -0
  46. data/lib/principles/data/ran.rb +25 -0
  47. data/lib/principles/data/raw_request_filter.rb +61 -0
  48. data/lib/principles/data/repository.rb +34 -27
  49. data/lib/principles/data/request_logging_folder.rb +167 -0
  50. data/lib/principles/data/running_version.rb +1 -1
  51. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
  52. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
  53. data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
  54. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  55. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  56. data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
  57. data/lib/principles/data/schemas/member-map.schema.json +10 -1
  58. data/lib/principles/data/string_counts.rb +39 -0
  59. data/lib/principles/data/tools_on_path.rb +25 -0
  60. data/lib/principles/invocation_options.rb +4 -2
  61. data/lib/principles/launch.rb +14 -4
  62. data/lib/principles/models/acknowledged_check.rb +11 -1
  63. data/lib/principles/models/acknowledgement.rb +15 -0
  64. data/lib/principles/models/acknowledgement_placeholders.rb +43 -18
  65. data/lib/principles/models/acknowledgement_refusal.rb +20 -11
  66. data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
  67. data/lib/principles/models/after_commit_input.rb +5 -0
  68. data/lib/principles/models/answer_fields.rb +3 -0
  69. data/lib/principles/models/assessment_basis.rb +10 -3
  70. data/lib/principles/models/audit.rb +10 -10
  71. data/lib/principles/models/audit_record.rb +10 -0
  72. data/lib/principles/models/audit_records.rb +4 -3
  73. data/lib/principles/models/audit_start.rb +9 -0
  74. data/lib/principles/models/authored_locator.rb +33 -0
  75. data/lib/principles/models/candidate_files.rb +23 -3
  76. data/lib/principles/models/candidate_outline.rb +18 -125
  77. data/lib/principles/models/captured_sessions.rb +128 -0
  78. data/lib/principles/models/carrier_kind.rb +79 -0
  79. data/lib/principles/models/cited_files.rb +12 -3
  80. data/lib/principles/models/decided_prior_findings.rb +5 -0
  81. data/lib/principles/models/disposition.rb +38 -7
  82. data/lib/principles/models/disposition_placeholders.rb +27 -7
  83. data/lib/principles/models/disposition_text_field.rb +4 -0
  84. data/lib/principles/models/feature.rb +53 -0
  85. data/lib/principles/models/finding_outcomes.rb +55 -0
  86. data/lib/principles/models/findings_left_open.rb +9 -11
  87. data/lib/principles/models/head_moves.rb +27 -10
  88. data/lib/principles/models/installed_component.rb +55 -0
  89. data/lib/principles/models/installed_plugins.rb +174 -0
  90. data/lib/principles/models/kept_sessions.rb +34 -0
  91. data/lib/principles/models/locator.rb +8 -0
  92. data/lib/principles/models/logged_request_reach.rb +44 -0
  93. data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
  94. data/lib/principles/models/mapped_baseline.rb +46 -0
  95. data/lib/principles/models/maps_holding_file_whole.rb +42 -0
  96. data/lib/principles/models/markdown_text.rb +143 -0
  97. data/lib/principles/models/member.rb +14 -1
  98. data/lib/principles/models/member_entry.rb +56 -0
  99. data/lib/principles/models/member_lines.rb +11 -0
  100. data/lib/principles/models/member_loads.rb +17 -2
  101. data/lib/principles/models/member_problems.rb +45 -42
  102. data/lib/principles/models/member_reach.rb +36 -0
  103. data/lib/principles/models/member_snapshots.rb +23 -4
  104. data/lib/principles/models/member_text_as_sent.rb +31 -0
  105. data/lib/principles/models/member_texts.rb +45 -0
  106. data/lib/principles/models/members_in_logged_requests.rb +240 -0
  107. data/lib/principles/models/missing_files.rb +41 -16
  108. data/lib/principles/models/named_placeholder.rb +17 -7
  109. data/lib/principles/models/nearly_matching_maps.rb +56 -0
  110. data/lib/principles/models/open_correction.rb +5 -0
  111. data/lib/principles/models/open_finding.rb +4 -3
  112. data/lib/principles/models/outline_budget.rb +10 -1
  113. data/lib/principles/models/outline_item.rb +25 -0
  114. data/lib/principles/models/outline_section.rb +15 -4
  115. data/lib/principles/models/part_named.rb +16 -2
  116. data/lib/principles/models/plugin_component.rb +37 -0
  117. data/lib/principles/models/plugin_install.rb +33 -0
  118. data/lib/principles/models/plugin_name.rb +23 -0
  119. data/lib/principles/models/plugin_reference.rb +53 -0
  120. data/lib/principles/models/principle_members.rb +15 -0
  121. data/lib/principles/models/prior_finding_decision.rb +1 -1
  122. data/lib/principles/models/prior_finding_outcomes.rb +12 -1
  123. data/lib/principles/models/problem_report.rb +14 -25
  124. data/lib/principles/models/project.rb +35 -29
  125. data/lib/principles/models/project_history.rb +23 -0
  126. data/lib/principles/models/recorded_members.rb +7 -0
  127. data/lib/principles/models/request_logging.rb +196 -0
  128. data/lib/principles/models/runs_from.rb +0 -5
  129. data/lib/principles/models/script_comments.rb +58 -0
  130. data/lib/principles/models/stale_request.rb +9 -0
  131. data/lib/principles/models/template_placeholders.rb +10 -9
  132. data/lib/principles/models/unfixed_part.rb +82 -0
  133. data/lib/principles/models/unresolved_plugin_members.rb +35 -0
  134. data/lib/principles/models/whole_file_member_read.rb +48 -0
  135. data/lib/principles/models/without_prose.rb +20 -0
  136. data/lib/principles/models/workflow_jobs.rb +92 -0
  137. data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
  138. data/lib/principles/show_principle_options.rb +32 -0
  139. data/lib/principles/version.rb +2 -2
  140. data/lib/principles/views/acknowledged_result.rb +31 -12
  141. data/lib/principles/views/acknowledgement_result.rb +41 -29
  142. data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
  143. data/lib/principles/views/acknowledgements_offered.rb +54 -0
  144. data/lib/principles/views/added_member.rb +22 -6
  145. data/lib/principles/views/answer_in_a_file.rb +16 -16
  146. data/lib/principles/views/assessed_members.rb +18 -7
  147. data/lib/principles/views/assessment_request.rb +8 -3
  148. data/lib/principles/views/audit_changes.rb +14 -8
  149. data/lib/principles/views/audit_findings.rb +34 -0
  150. data/lib/principles/views/audit_result.rb +14 -19
  151. data/lib/principles/views/carrier_checks.rb +40 -0
  152. data/lib/principles/views/carrier_practices_page.rb +49 -0
  153. data/lib/principles/views/completed_audit_findings.rb +33 -0
  154. data/lib/principles/views/completed_audit_next_step.rb +12 -4
  155. data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
  156. data/lib/principles/views/context_parts.rb +129 -25
  157. data/lib/principles/views/correction_request.rb +22 -17
  158. data/lib/principles/views/disposition_template.rb +35 -0
  159. data/lib/principles/views/first_audit.rb +29 -15
  160. data/lib/principles/views/first_audit_brief.rb +0 -1
  161. data/lib/principles/views/first_audit_line.rb +4 -5
  162. data/lib/principles/views/invocation.rb +16 -6
  163. data/lib/principles/views/last_record_notice.rb +41 -0
  164. data/lib/principles/views/lines_shared_with_member.rb +16 -22
  165. data/lib/principles/views/logged_request_status_meanings.rb +29 -0
  166. data/lib/principles/views/logged_requests_evidence.rb +69 -0
  167. data/lib/principles/views/map_added_to.rb +14 -12
  168. data/lib/principles/views/map_result.rb +39 -17
  169. data/lib/principles/views/member_change_since_baseline.rb +4 -0
  170. data/lib/principles/views/member_row.rb +13 -4
  171. data/lib/principles/views/member_sets_overlap.rb +31 -0
  172. data/lib/principles/views/members_a_commit_changed.rb +42 -25
  173. data/lib/principles/views/members_changed_during_audit.rb +27 -0
  174. data/lib/principles/views/members_in_logged_requests_result.rb +68 -0
  175. data/lib/principles/views/members_too_short_to_scan.rb +45 -0
  176. data/lib/principles/views/members_with_no_baseline.rb +6 -6
  177. data/lib/principles/views/meta_principle_result.rb +14 -2
  178. data/lib/principles/views/open_findings_line.rb +31 -92
  179. data/lib/principles/views/parts_index_result.rb +9 -5
  180. data/lib/principles/views/principle_read_result.rb +52 -11
  181. data/lib/principles/views/prior_findings_result.rb +9 -1
  182. data/lib/principles/views/problem_facts.rb +5 -3
  183. data/lib/principles/views/problem_lines.rb +32 -6
  184. data/lib/principles/views/problem_result.rb +7 -15
  185. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  186. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
  187. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
  188. data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
  189. data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
  190. data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
  191. data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
  192. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  193. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -0
  194. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +1 -1
  195. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
  196. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
  197. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
  198. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
  199. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
  200. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
  201. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
  202. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
  203. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +50 -51
  204. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
  205. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
  206. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
  207. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  208. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
  209. data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +16 -0
  210. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
  211. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +2 -2
  212. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +3 -3
  213. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
  214. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
  215. data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
  216. data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +20 -0
  217. data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +48 -0
  218. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +1 -1
  219. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +14 -14
  220. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
  221. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +11 -11
  222. data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +10 -0
  223. data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +32 -0
  224. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
  225. data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
  226. data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
  227. data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
  228. data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
  229. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
  230. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
  231. data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
  232. data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
  233. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
  234. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
  235. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
  236. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  237. data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
  238. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
  239. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
  240. data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
  241. data/lib/principles/views/request_logging_result.rb +62 -0
  242. data/lib/principles/views/request_part.rb +10 -4
  243. data/lib/principles/views/request_parts.rb +9 -0
  244. data/lib/principles/views/whole_file_elsewhere.rb +30 -0
  245. metadata +101 -4
  246. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
  247. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
@@ -1,34 +1,17 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../error"
5
- require_relative "frontmatter_fields"
4
+ require_relative "markdown_text"
6
5
  require_relative "outline_group"
7
- require_relative "outline_section"
8
- require_relative "text_within"
6
+ require_relative "script_comments"
7
+ require_relative "workflow_jobs"
9
8
 
10
9
  module Principles
11
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
11
  module Models
13
- # One candidate file's outline, as the survey reads it in place of the file: its Markdown headings in order, and
14
- # under each its top-level list items. One user scripted a heading grep over 45 files to survey them,
15
- # and missed a principles section written as one numbered list, so this tool prints both.
12
+ # One candidate file's outline, as the survey reads it in place of the file: the sections of the text it outlines,
13
+ # and that text's description and opening line when it has them, cut to fit a budget.
16
14
  class CandidateOutline
17
- HEADING = /\A#+\s/
18
- FENCE = /\A\s*(?:```|~~~)/
19
- # A top-level list item, its marker and its text; an indented one is nested, and left out.
20
- ITEM = /\A(\d+\.|[-*])\s+(.*)/
21
- # A horizontal rule, such as `* * *` or `- - -`, which is no item.
22
- RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
23
- LINK = /\[([^\]]*)\]\([^)]*\)/
24
- BOLD_LEAD = /\A\*\*[^*]+\*\*/
25
- # The most characters of an item printed, cut back to a whole word.
26
- ITEM_CHARACTERS = 60
27
- # The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
28
- # mid-clause left 30 of one user's 45 opening lines a fragment. The line is short only when
29
- # its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
30
- # accepted, since the file's path and outline still say what it holds.
31
- OPENING_CHARACTERS = 160
32
15
  # The cuts that shorten an outline to fit a budget, in the order they are made, each keeping those before it.
33
16
  # The last leaves the whole outline out, which a big enough project needs once every other cut is made.
34
17
  CUTS = %w[description items headings opening_line outline].freeze
@@ -36,19 +19,11 @@ module Principles
36
19
  ENTRY_FILE_CUTS = CUTS.length - 1 #: Integer
37
20
  # The deepest heading level a cut outline keeps once its headings are folded.
38
21
  FOLDED_BELOW = 2
39
- # The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
40
- # one user's descriptions printed 12,537 B uncut, and suggested about 300.
41
- DESCRIPTION_CHARACTERS = 300
42
22
 
43
- # A description's key and any block scalar indicator, which its text starts after.
44
- DESCRIPTION_KEY = /\Adescription:\s*(?:[>|][-+]?\s)?/
45
- # A value inside a matching pair of quotes, printed without them; its escapes are left as written.
46
- QUOTED = /\A(["'])(.*)\1\z/
47
-
48
- #: (String) -> void
49
- def initialize(text)
50
- @lines = text.lines #: Array[String]
51
- @frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
23
+ # The file's text, read as the kind of text `as` names.
24
+ #: (String, ?as: singleton(MarkdownText) | singleton(ScriptComments) | singleton(WorkflowJobs)) -> void
25
+ def initialize(text, as: MarkdownText)
26
+ @text = as.new(text) #: MarkdownText | ScriptComments | WorkflowJobs
52
27
  freeze
53
28
  end
54
29
 
@@ -58,14 +33,16 @@ module Principles
58
33
  def to_h(cuts: 0)
59
34
  return {} if left_out?(cuts)
60
35
 
61
- { "description" => made?("description", cuts) ? cut_description : description,
62
- "opening_line" => (opening_line unless made?("opening_line", cuts) && description),
36
+ description = @text.description
37
+ { "description" => made?("description", cuts) ? @text.cut_description : description,
38
+ "opening_line" => (@text.opening_line unless made?("opening_line", cuts) && description),
63
39
  "outline" => outline_lines(cuts) }.compact
64
40
  end
65
41
 
66
- # Whether the first `cuts` of CUTS cut the outline's lines, rather than only its description.
42
+ # Whether the outline's lines are cut once the first `cuts` of CUTS are made: by those cuts, rather than only its
43
+ # description, or by a section leaving items out past OutlineSection::MOST_ITEMS before any cut.
67
44
  #: (Integer) -> bool
68
- def outline_cut?(cuts) = made?("items", cuts)
45
+ def outline_cut?(cuts) = made?("items", cuts) || sections.any?(&:leaves_items_out?)
69
46
 
70
47
  # Whether the first `cuts` of CUTS leave the whole outline out, the file printing its path and size alone.
71
48
  #: (Integer) -> bool
@@ -79,16 +56,9 @@ module Principles
79
56
  #: () -> Array[String]
80
57
  def cut_lines = sections.flat_map(&:cut_lines)
81
58
 
82
- # Each heading with the items under it, and the items before the first heading when there are any, each with
83
- # the lines of the file it spans.
59
+ # The text's sections, each a heading with the items under it and the lines of the file it spans.
84
60
  #: () -> Array[OutlineSection]
85
- def sections
86
- body = unfenced
87
- starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
88
- starts.zip(starts.drop(1)).filter_map do |first, after|
89
- section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
90
- end
91
- end
61
+ def sections = @text.sections
92
62
 
93
63
  private
94
64
 
@@ -96,7 +66,7 @@ module Principles
96
66
  # headings folded into the heading above, whose 11,112 B kept one user's result over budget.
97
67
  #: (Integer) -> Array[String]
98
68
  def outline_lines(cuts)
99
- return lines unless outline_cut?(cuts)
69
+ return lines unless made?("items", cuts)
100
70
  return cut_lines unless made?("headings", cuts)
101
71
 
102
72
  groups.flat_map(&:folded_lines)
@@ -113,83 +83,6 @@ module Principles
113
83
  # Whether the first `cuts` of CUTS include the one named.
114
84
  #: (String, Integer) -> bool
115
85
  def made?(cut, cuts) = CUTS.take(cuts).include?(cut)
116
-
117
- # The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
118
- # heading nor an item.
119
- #: (Array[String], first_line: Integer) -> OutlineSection?
120
- def section(lines, first_line:)
121
- heading = lines.first if lines.first&.match?(HEADING)
122
- items = lines.select { |line| item?(line) }.map { |line| item(line) }
123
- return nil unless heading || items.any?
124
-
125
- OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
126
- end
127
-
128
- # A top-level list item, not a horizontal rule written with the same marks.
129
- #: (String) -> bool
130
- def item?(line) = line.match?(ITEM) && !line.match?(RULE)
131
-
132
- # The index in the file of the body's first line, after any frontmatter.
133
- #: () -> Integer
134
- def body_start = (@frontmatter.closing_line || -1) + 1
135
-
136
- # The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
137
- #: () -> String?
138
- def description
139
- written = @frontmatter.field_lines("$.description") or return nil
140
- text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
141
- text[QUOTED, 2] || text
142
- rescue Error
143
- nil
144
- end
145
-
146
- # The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
147
- # characters it holds and the lines of the file that hold it, so the agent reads just those back.
148
- #: () -> String?
149
- def cut_description
150
- text = description or return nil
151
- within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
152
- return text unless within.cut?
153
-
154
- kept = within.kept
155
- first, last = @frontmatter.field("$.description")
156
- "#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
157
- end
158
-
159
- # The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
160
- # joined, with links as their text. The first physical line was a fragment in a hard-wrapped file.
161
- #: () -> String?
162
- def opening_line
163
- body = unfenced
164
- first = body.index { |line| prose?(line) } or return nil
165
- paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
166
- TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
167
- end
168
-
169
- #: (String) -> bool
170
- def prose?(line)
171
- text = line.strip
172
- !text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
173
- end
174
-
175
- # The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
176
- #: () -> Array[String]
177
- def unfenced
178
- fenced = false #: bool
179
- body = @lines.drop(body_start).map(&:chomp)
180
- body.map do |line|
181
- fenced = !fenced if line.match?(FENCE)
182
- fenced || line.match?(FENCE) ? "" : line
183
- end
184
- end
185
-
186
- # An item by its marker and its bold lead, or its opening words, with links as their text.
187
- #: (String) -> String
188
- def item(line)
189
- marker, text = line.match(ITEM)&.captures
190
- text = text.to_s.gsub(LINK, '\1')
191
- "#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: ITEM_CHARACTERS).by_words}"
192
- end
193
86
  end
194
87
  end
195
88
  end
@@ -0,0 +1,128 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../data/request_logging_folder"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # What the host captured under requests/, read from its files and its index: each session's requests, files and
10
+ # bytes, and the request files no index line names, whose cause is the agent's to judge.
11
+ class CapturedSessions
12
+ # Files counted, and their bytes.
13
+ class Tally
14
+ #: Integer
15
+ attr_reader :files, :bytes
16
+
17
+ #: (files: Integer, bytes: Integer) -> void
18
+ def initialize(files:, bytes:)
19
+ @files = files
20
+ @bytes = bytes
21
+ freeze
22
+ end
23
+
24
+ #: () -> Hash[String, Integer]
25
+ def to_h = { "files" => @files, "bytes" => @bytes }
26
+ end
27
+
28
+ # One session's tally: its requests, the files they and their responses fill, and those files' bytes.
29
+ class Session
30
+ #: String
31
+ attr_reader :session_id
32
+ #: Integer
33
+ attr_reader :requests
34
+ #: Tally
35
+ attr_reader :tally
36
+
37
+ #: (String, Integer, Tally) -> void
38
+ def initialize(session_id, requests, tally)
39
+ @session_id = session_id
40
+ @requests = requests
41
+ @tally = tally
42
+ freeze
43
+ end
44
+
45
+ #: () -> Hash[String, untyped]
46
+ def to_h = { "session_id" => @session_id, "requests" => @requests, **@tally.to_h }
47
+ end
48
+
49
+ #: (Array[Data::RequestLoggingFolder::CapturedFile], Array[Data::RequestLoggingFolder::IndexLine]) -> void
50
+ def initialize(files, index_lines)
51
+ @files = files.to_h { |file| [file.name, file] } #: Hash[String, Data::RequestLoggingFolder::CapturedFile]
52
+ @index_lines = index_lines
53
+ freeze
54
+ end
55
+
56
+ # Each session the index names, in the order it first names them.
57
+ #: () -> Array[Session]
58
+ def sessions
59
+ @index_lines.group_by(&:session_id).map do |session_id, lines|
60
+ named = lines.flat_map { |line| named_files(line) }.uniq
61
+ Session.new(session_id, lines.size, Tally.new(files: named.size, bytes: named.sum(&:bytes)))
62
+ end
63
+ end
64
+
65
+ # The request files no index line names, counted, and their bytes.
66
+ #: () -> Tally
67
+ def orphans
68
+ unnamed = unnamed_requests
69
+ Tally.new(files: unnamed.size, bytes: unnamed.sum(&:bytes))
70
+ end
71
+
72
+ # When the newest request file was written, which says whether requests still arrive, or nil before any.
73
+ #: () -> Time?
74
+ def newest_request_written_at
75
+ @files.values.select { |file| file.name.end_with?(".request.json") }.map(&:modified_at).max
76
+ end
77
+
78
+ # Whether the host captured no request yet, as before a session is launched with capture on.
79
+ #: () -> bool
80
+ def none? = newest_request_written_at.nil?
81
+
82
+ # The session of the index's newest line, by its timestamp, or nil before the index has one. It compares the
83
+ # timestamps as text, which orders them only while the host writes them in one ISO 8601 form, not yet seen on a
84
+ # real launch.
85
+ #: () -> String?
86
+ def newest_session_id = @index_lines.max_by(&:timestamp)&.session_id
87
+
88
+ # The names of the files the index names for every session but the newest keep, ranked by each session's
89
+ # newest line, as newest_session_id compares them, leaving every file a kept session also names; then the
90
+ # request files no line names that were written before every kept session's file. With no session kept, every
91
+ # such file stays, since it may belong to a session still running.
92
+ #: (Integer) -> Array[String]
93
+ def older_than_newest(keep)
94
+ ranked = @index_lines.group_by(&:session_id).values.sort_by { |lines| lines.map(&:timestamp).max.to_s }
95
+ kept = ranked.last(keep).flatten
96
+ names(ranked.flatten - kept) - names(kept) + orphans_written_before(kept)
97
+ end
98
+
99
+ private
100
+
101
+ #: (Array[Data::RequestLoggingFolder::IndexLine]) -> Array[String]
102
+ def orphans_written_before(kept)
103
+ oldest = kept.flat_map { |line| named_files(line) }.map(&:modified_at).min
104
+ return [] unless oldest
105
+
106
+ unnamed_requests.select { |file| file.modified_at < oldest }.map(&:name)
107
+ end
108
+
109
+ #: () -> Array[Data::RequestLoggingFolder::CapturedFile]
110
+ def unnamed_requests
111
+ indexed = @index_lines.map { |line| base_name(line.request_file) }
112
+ @files.values.select { |file| file.name.end_with?(".request.json") && !indexed.include?(file.name) }
113
+ end
114
+
115
+ #: (Array[Data::RequestLoggingFolder::IndexLine]) -> Array[String]
116
+ def names(lines) = lines.flat_map { |line| named_files(line) }.map(&:name).uniq
117
+
118
+ #: (String) -> String
119
+ def base_name(path) = path.split("/").last.to_s
120
+
121
+ # The files a line names that the folder holds, by name, since the index names them by their full paths.
122
+ #: (Data::RequestLoggingFolder::IndexLine) -> Array[Data::RequestLoggingFolder::CapturedFile]
123
+ def named_files(line)
124
+ [line.request_file, line.response_file].filter_map { |path| @files[base_name(path)] }
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,79 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "agent_loads"
7
+ require_relative "hook_commands"
8
+ require_relative "plugin_reference"
9
+
10
+ module Principles
11
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
+ module Models
13
+ # The kind of harness carrier a member's file is, by its path, whose own practices a request names for judging and
14
+ # editing it: an instruction file, a rule, a skill or a subagent, a plugin's too, a hook configuration, a script a
15
+ # hook command names, or none when no host loads the path by itself.
16
+ # Text a program prints into context has no kind here: the path cannot show it, so the agent judges it.
17
+ class CarrierKind
18
+ # The instruction files a host reads in a folder, Claude Code's and Codex's, at the root or below it.
19
+ INSTRUCTION_FILE = %r{(?:\A|/)(?:CLAUDE\.md|\.claude/CLAUDE\.md|CLAUDE\.local\.md|AGENTS\.md)\z} #: Regexp
20
+
21
+ # A rule file in a .claude/rules folder, at the root or below it.
22
+ RULE_FILE = %r{(?:\A|/)\.claude/rules/.+\.md\z} #: Regexp
23
+
24
+ # A skill's file in any skills folder: under .claude, as SkillLoads::SKILL_FILE, whose loading it derives, or at a
25
+ # plugin's root, such as a project's own plugin folder, whose loading it does not.
26
+ SKILL_IN_ANY_SKILLS_FOLDER = %r{(?:\A|/)skills/[^/]+/SKILL\.md\z} #: Regexp
27
+
28
+ # A plugin member's agent file, in the agents folder at the plugin's root.
29
+ PLUGIN_AGENT_FILE = %r{\A#{Regexp.escape(PluginReference::PREFIX)}[^/]+/agents/(?:[^/]+/)*[^/]+\.md\z} #: Regexp
30
+
31
+ # The hooks file at a plugin's root, or a project's own plugin folder, beside the settings files hooks are read
32
+ # from.
33
+ HOOKS_FILE = %r{(?:\A|/)hooks/hooks\.json\z} #: Regexp
34
+
35
+ # Each kind a path alone shows, in the order they are tried, with the paths that make a file one.
36
+ BY_PATH = {
37
+ "instructions" => [INSTRUCTION_FILE],
38
+ "rule" => [RULE_FILE],
39
+ "skill" => [SKILL_IN_ANY_SKILLS_FOLDER],
40
+ "subagent" => [AgentLoads::AGENT_FILE, PLUGIN_AGENT_FILE],
41
+ "hook_configuration" => [HOOKS_FILE, *HookCommands::ON_EVERY_HOST.map { /\A#{Regexp.escape(it)}\z/ }]
42
+ }.freeze #: Hash[String, Array[Regexp]]
43
+
44
+ # The kind of a file no host loads by itself.
45
+ NONE = "none" #: String
46
+
47
+ # Every kind's name: those a path shows, then a hook script and none.
48
+ NAMES = [*BY_PATH.keys, "hook_script", NONE].freeze #: Array[String]
49
+
50
+ # name, as an agent gives it, refused unless it is one of NAMES.
51
+ #: (String) -> String
52
+ def self.named(name)
53
+ return name if NAMES.include?(name)
54
+
55
+ raise Error.new("unknown_carrier_kind", "There is no carrier kind named #{name.inspect}.",
56
+ "Name one of #{ProseList.new(NAMES)}.")
57
+ end
58
+
59
+ # named_in_hooks is whether a hook command names the file, which makes a file no other kind holds a hook script.
60
+ #: (String, ?named_in_hooks: bool) -> void
61
+ def initialize(path, named_in_hooks: false)
62
+ @path = path
63
+ @named_in_hooks = named_in_hooks
64
+ freeze
65
+ end
66
+
67
+ # The kind's name, as show-carrier-practices takes it: the first BY_PATH names, or else a hook script or none.
68
+ #: () -> String
69
+ def name
70
+ by_path = BY_PATH.find { |_, paths| paths.any? { it.match?(@path) } }&.first
71
+ by_path || (@named_in_hooks ? "hook_script" : NONE)
72
+ end
73
+
74
+ # Whether a host loads a file of this kind by itself, so its absence from a request is not expected.
75
+ #: () -> bool
76
+ def carrier? = name != NONE
77
+ end
78
+ end
79
+ end
@@ -3,6 +3,8 @@
3
3
 
4
4
  require_relative "assessment_report"
5
5
  require_relative "project_history"
6
+ require_relative "installed_plugins"
7
+ require_relative "plugin_reference"
6
8
 
7
9
  module Principles
8
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -31,9 +33,16 @@ module Principles
31
33
  changed.uniq.sort
32
34
  end
33
35
 
34
- # Each cited file that no longer exists, in git or outside it.
35
- #: () -> Array[String]
36
- def missing = @paths - @history.existing(@paths)
36
+ # Each cited file that no longer exists, in git or outside it; a plugin's file, which is not in the project,
37
+ # when the plugin installed now does not hold it.
38
+ #: (InstalledPlugins) -> Array[String]
39
+ def missing(plugins)
40
+ existing = @history.existing(@paths)
41
+ @paths.reject do |path|
42
+ reference = PluginReference.in(path)
43
+ reference ? plugins.holds?(reference) : existing.include?(path)
44
+ end
45
+ end
37
46
  end
38
47
  end
39
48
  end
@@ -72,6 +72,11 @@ module Principles
72
72
  inherited.key?(id) ? { "first_raised_at" => inherited.fetch(id) } : {}
73
73
  end
74
74
 
75
+ # Where each deferral raised again was written up and whom it waited on, by the id of the new finding it became;
76
+ # none in a basis printed before they were carried.
77
+ #: () -> Hash[String, Hash[String, untyped]]
78
+ def deferrals_raised_again = @fields.fetch("deferrals_raised_again", {})
79
+
75
80
  # These decisions with each kept finding filed under its members' ids after moves.
76
81
  #: (MemberMoves) -> DecidedPriorFindings
77
82
  def moved(moves)
@@ -8,6 +8,8 @@ require_relative "answer_text"
8
8
  require_relative "disposition_placeholders"
9
9
  require_relative "disposition_text_field"
10
10
  require_relative "fix_only_fields"
11
+ require_relative "plugin_reference"
12
+ require_relative "unfixed_part"
11
13
  require_relative "unfinished_field"
12
14
  require_relative "waits_on"
13
15
  require_relative "write_up_pointer"
@@ -24,13 +26,14 @@ module Principles
24
26
  ACTIONS = %w[fixed deferred accepted disagreed].freeze #: Array[String]
25
27
 
26
28
  # at is the disposition's place in the answer, such as /dispositions/0, which a refusal about its pointers names.
27
- # samples is the answer guide's disposition for each action, whose text illustrates each field.
28
- #: (untyped, AnswerFields, at: String, samples: Hash[String, untyped]) -> void
29
- def initialize(disposition, fields, at:, samples:)
29
+ # samples is the answer guide's disposition for each action, whose text illustrates each field. subject is whose
30
+ # disposition a refusal names it as: its finding's, or the unfixed part's of the fix that gives it.
31
+ #: (untyped, AnswerFields, at: String, samples: Hash[String, untyped], ?subject: String) -> void
32
+ def initialize(disposition, fields, at:, samples:, subject: "Finding #{disposition["finding_id"]}")
30
33
  @disposition = disposition
31
34
  @fields = fields
32
35
  @samples = samples
33
- @place = AnswerPlace.new(at, "Finding #{disposition["finding_id"]}") #: AnswerPlace
36
+ @place = AnswerPlace.new(at, subject) #: AnswerPlace
34
37
  freeze
35
38
  end
36
39
 
@@ -75,7 +78,19 @@ module Principles
75
78
  # left empty, as the template's placeholder or as the answer guide's sample, and so a fix's reassessment,
76
79
  # which applies to no other action, and a waits_on left as the guide's sample.
77
80
  #: () -> Array[UnfinishedField]
78
- def unfinished = [*unchosen_action, *unwritten_text, *waits_on_left_as_sample]
81
+ def unfinished = [*unchosen_action, *unwritten_text, *waits_on_left_as_sample, *unfixed_part&.unfinished]
82
+
83
+ # The part of its finding a fix leaves unfixed, as the agent gave it, or nil when it gives none.
84
+ #: () -> UnfixedPart?
85
+ def unfixed_part
86
+ part = @disposition["unfixed_part"]
87
+ return unless part
88
+
89
+ place = AnswerPlace.new(@place.child("unfixed_part").pointer, "Finding #{finding_id} unfixed_part")
90
+ own = Disposition.new(part.except("id", "problem").merge("finding_id" => part["id"]), @fields,
91
+ at: place.pointer, samples: @samples, subject: place.subject)
92
+ UnfixedPart.new(part, of: self, outcome: own, place:)
93
+ end
79
94
 
80
95
  # The members this disposition claims it changed, refusing it unless its other fields are sound: only a fix
81
96
  # claims any, and each must be among the members that changed. CorrectionAnswer has checked its action and
@@ -84,6 +99,7 @@ module Principles
84
99
  def claimed_members(changed)
85
100
  action = @disposition["action"]
86
101
  checked_fields
102
+ unfixed_part&.check
87
103
  members = @fields.array(fix_fields.list("changed_members"), "changed_members")
88
104
  entries = @disposition.fetch("changed_map_entries", []) + @disposition.fetch("removed_members", [])
89
105
  action == "fixed" ? fixed_members(members, entries, changed) : fix_fields.unclaimed(members, entries)
@@ -98,7 +114,7 @@ module Principles
98
114
  action = @disposition["action"]
99
115
  return if ACTIONS.include?(action)
100
116
 
101
- unchosen = action.nil? || DispositionPlaceholders::ACTION.left?(action)
117
+ unchosen = action.nil? || DispositionPlaceholders.action_left?(action)
102
118
  problem = unchosen ? "is not chosen" : "is #{action.inspect}, not one of the four"
103
119
  UnfinishedField.new(@place.child("action"), "action",
104
120
  problem:, repair: "Set its action to one of fixed, deferred, accepted or disagreed.")
@@ -131,6 +147,7 @@ module Principles
131
147
  # claims a map entry instead, which DeclaredMapChanges has checked changed.
132
148
  #: (Array[untyped], Array[untyped], Array[String]) -> Array[untyped]
133
149
  def fixed_members(members, entries, changed)
150
+ refuse_plugin_members(members)
134
151
  return members unless (members.empty? && entries.empty?) || (members - changed).any?
135
152
 
136
153
  raise Error.new("claimed_change_missing",
@@ -138,6 +155,20 @@ module Principles
138
155
  "Make the authorised change and reassess it, or record a deferral.")
139
156
  end
140
157
 
158
+ # A fix never claims a plugin's member changed, whatever its text did: principles never edits an installed
159
+ # plugin's files, which the plugin's next update replaces.
160
+ #: (Array[untyped]) -> void
161
+ def refuse_plugin_members(members)
162
+ plugin = members.select { |id| id.is_a?(String) && PluginReference.in(id) }
163
+ return if plugin.empty?
164
+
165
+ raise Error.new("plugin_member_read_only",
166
+ "Finding #{finding_id} claims a fix to #{plugin.join(", ")}, read from an installed plugin, " \
167
+ "which principles never edits",
168
+ "Settle it another way: fix it in the project's own files and claim those; or set its action " \
169
+ "to deferred, with recorded_at {\"url\": ...} where it is raised upstream; or to accepted.")
170
+ end
171
+
141
172
  # The disposition's evidence and recorded_at, which a deferral must give, if only as null, and the
142
173
  # one line a deferral may give saying what it waits on.
143
174
  #: () -> void
@@ -168,7 +199,7 @@ module Principles
168
199
  #: () -> bot
169
200
  def unrecorded_deferral
170
201
  raise Error.new("invalid_disposition", "Deferred finding #{finding_id} has no recorded_at",
171
- "Set recorded_at to where the finding is written up, as {\"path\": ..., \"heading\": ...}, " \
202
+ "Set recorded_at to where the finding is written up, as #{AnswerFields::WRITE_UP_FORMS}; " \
172
203
  "or to null when it is written up nowhere.")
173
204
  end
174
205
  end
@@ -28,21 +28,41 @@ module Principles
28
28
  }.freeze #: Hash[String, DispositionTextField]
29
29
  # The placeholder in each field, which the template prints with the disposition's finding in its slot.
30
30
  PLACEHOLDERS = TEXT_FIELDS.transform_values { it.placeholder.slotted }.freeze #: Hash[String, String]
31
- # What action takes, said where it is written when the correction's answer is printed with no answer guide
32
- # beside it, as show-answer-check prints it, before it named the finding. It is help, never an action, so it
33
- # is left unchosen.
31
+ # What action takes, as the correction's template printed it in action before it named the finding: one long
32
+ # sentence of every action's fields, which the agent replaced whole. It is help, never an action, so an answer
33
+ # still sending it is left unchosen.
34
34
  ACTION_PLACEHOLDER = "One of fixed, deferred, accepted or disagreed, each with a reason: fixed lists " \
35
35
  "changed_members for current text changes, optional removed_members for map removals, " \
36
36
  "and evidence and gives a reassessment; deferred gives recorded_at, " \
37
37
  "where the write-up is, and may give waits_on; any other action leaves changed_members, " \
38
38
  "evidence and reassessment as printed" #: String
39
- # The action's placeholder, naming the finding.
40
- ACTION = NamedPlaceholder.new("For #{NamedPlaceholder::SLOT}, #{ACTION_PLACEHOLDER.sub(/\AO/, "o")}",
39
+ # The action's placeholder as it was printed naming the finding, before it named the four choices alone.
40
+ EARLIER_ACTION = NamedPlaceholder.new("For #{NamedPlaceholder::SLOT}, #{ACTION_PLACEHOLDER.sub(/\AO/, "o")}",
41
+ before: ACTION_PLACEHOLDER) #: NamedPlaceholder
42
+ # The action's placeholder, naming the finding and the four choices alone, short enough to replace with one;
43
+ # the answer guide shows each action's fields.
44
+ ACTION = NamedPlaceholder.new("For #{NamedPlaceholder::SLOT}: fixed, deferred, accepted or disagreed",
41
45
  before: ACTION_PLACEHOLDER) #: NamedPlaceholder
42
- # Every placeholder a slot of a correction's template prints, for any finding.
43
- NAMED = [*TEXT_FIELDS.values.map(&:placeholder), ACTION].freeze #: Array[NamedPlaceholder]
46
+ # Every placeholder a slot of a correction's template prints, for any finding, or printed before.
47
+ NAMED = [*TEXT_FIELDS.values.map(&:placeholder), ACTION, EARLIER_ACTION].freeze #: Array[NamedPlaceholder]
48
+ # What the correction's question prints in an unfixed part's problem and reason, as its example
49
+ # `"problem": ..., ... "reason": ...` in dispose-of-each-finding/fix-or-record-each-finding.md, since no
50
+ # template prints an unfixed part.
51
+ QUESTION_EXAMPLE = NamedPlaceholder.new("...", before: "...") #: NamedPlaceholder
52
+ # The text fields an unfixed part gives, which the agent writes: the problem it raises as a finding of its own,
53
+ # and why it is left, which its outcome checks too against the template's reason.
54
+ UNFIXED_TEXT_FIELDS = {
55
+ "problem" => DispositionTextField.new(placeholder: QUESTION_EXAMPLE,
56
+ repair: "Write the problem the fix leaves unfixed."),
57
+ "reason" => DispositionTextField.new(placeholder: QUESTION_EXAMPLE,
58
+ repair: TEXT_FIELDS.fetch("reason").repair)
59
+ }.freeze #: Hash[String, DispositionTextField]
44
60
  # Every placeholder a correction's template prints, each text field's and the action's, each with its slot.
45
61
  TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION.slotted).freeze #: Hash[String, String]
62
+
63
+ # Whether action is the action's placeholder, as this release prints it or an earlier one did, for any finding.
64
+ #: (untyped) -> bool
65
+ def self.action_left?(action) = [ACTION, EARLIER_ACTION].any? { it.left?(action) }
46
66
  end
47
67
  end
48
68
  end
@@ -19,6 +19,10 @@ module Principles
19
19
  #: NamedPlaceholder
20
20
  attr_reader :placeholder
21
21
 
22
+ # What to write instead.
23
+ #: String
24
+ attr_reader :repair
25
+
22
26
  #: (placeholder: NamedPlaceholder, repair: String) -> void
23
27
  def initialize(placeholder:, repair:)
24
28
  @placeholder = placeholder