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
@@ -0,0 +1,58 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "outline_section"
5
+ require_relative "without_prose"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # A script's or configuration file's text as its outline reads it: its whole-line `#` comments, where a hook or a
11
+ # CI check writes the rule it enforces, which a survey reading Markdown headings alone never found.
12
+ class ScriptComments
13
+ include WithoutProse
14
+
15
+ # A whole-line comment and its text, past any indent and the space after the mark.
16
+ COMMENT = /\A\s*#\s?(.*)/
17
+ # A first line naming the script's interpreter, which is no comment.
18
+ SHEBANG = /\A#!/
19
+ # A Ruby magic comment, such as frozen_string_literal or Sorbet's typed sigil, which sets how the file runs and
20
+ # states no rule.
21
+ MAGIC = /\A#\s*(?:frozen_string_literal|typed|encoding|coding|warn_indent|shareable_constant_value):/
22
+
23
+ #: (String) -> void
24
+ def initialize(text)
25
+ @lines = text.lines.map(&:chomp) #: Array[String]
26
+ freeze
27
+ end
28
+
29
+ # One section with no heading, its items the comments, spanning the lines from the first to the last; none when
30
+ # the text has no comment.
31
+ #: () -> Array[OutlineSection]
32
+ def sections
33
+ comments = comment_numbers
34
+ first = comments.first or return []
35
+
36
+ items = comments.map { |number| OutlineItem.new(item(@lines.fetch(number - 1)), line: number) }
37
+ [OutlineSection.new(heading: nil, items:, first_line: first, last_line: comments.fetch(-1))]
38
+ end
39
+
40
+ private
41
+
42
+ # The number in the file, counted from 1, of each line that is a comment with text.
43
+ #: () -> Array[Integer]
44
+ def comment_numbers
45
+ @lines.each_index.filter_map do |index|
46
+ line = @lines.fetch(index)
47
+ next if (index.zero? && line.match?(SHEBANG)) || line.match?(MAGIC)
48
+
49
+ index + 1 unless line[COMMENT, 1].to_s.strip.empty?
50
+ end
51
+ end
52
+
53
+ # A comment as its mark and its whole text, so any line can be quoted as an exact --starting-at.
54
+ #: (String) -> String
55
+ def item(line) = "# #{line[COMMENT, 1].to_s.strip}"
56
+ end
57
+ end
58
+ end
@@ -26,6 +26,15 @@ module Principles
26
26
  freeze
27
27
  end
28
28
 
29
+ # The refusal of an answer whose audit began before the installed plugin changed the text of members, its
30
+ # plugin members: no fix can claim a plugin's change, so the audit starts again on the new text.
31
+ #: (String, Array[String]) -> Error
32
+ def self.plugin_updated(principle_id, members)
33
+ Error.new("stale_request", "This request no longer matches #{principle_id}: the installed plugin changed " \
34
+ "#{ProseList.new(members)} since the audit began",
35
+ "Start the audit again and answer the new request: #{Error::EXECUTABLE} start-audit #{principle_id}")
36
+ end
37
+
29
38
  #: () -> Error
30
39
  def refusal
31
40
  Error.new("stale_request", "This request no longer matches #{@principle_id}: #{cause}", repair)
@@ -16,20 +16,21 @@ module Principles
16
16
 
17
17
  # placeholders is the text printed in each field, by field name, or for a field that takes pointers, one pointer
18
18
  # whose fields hold that text, so the template shows their shape; empty_lists names the fields a template
19
- # may instead start as an empty list, which is not given either; also_printed, the other text a template
20
- # may print in a field, refused alike. A NamedPlaceholder in either prints with its slot, which the view fills
21
- # with the id of the entry it prints in, and is left as printed for any id.
22
- #: (Hash[String, untyped], ?empty_lists: Array[String], ?also_printed: Hash[String, untyped]) -> void
19
+ # may instead start as an empty list, which is not given either; also_printed, the other texts a template
20
+ # may print in a field, each by a name saying when, refused alike. A NamedPlaceholder in either prints with its
21
+ # slot, which the view fills with the id of the entry it prints in, and is left as printed for any id.
22
+ #: (Hash[String, untyped], ?empty_lists: Array[String], ?also_printed: Hash[String, Hash[Symbol, untyped]])
23
+ #| -> void
23
24
  def initialize(placeholders, empty_lists: [], also_printed: {})
24
25
  @placeholders = placeholders.freeze #: Hash[String, untyped]
25
26
  @empty_lists = empty_lists.freeze #: Array[String]
26
- @also_printed = also_printed.freeze #: Hash[String, untyped]
27
+ @also_printed = also_printed.freeze #: Hash[String, Hash[Symbol, untyped]]
27
28
  freeze
28
29
  end
29
30
 
30
- # The text printed in each field, with field's other text in place of its own.
31
- #: (String) -> Hash[String, untyped]
32
- def with_other_text_in(field) = to_h.merge(field => shown(@also_printed.fetch(field)))
31
+ # The text printed in each field, with field's other text named name in place of its own.
32
+ #: (String, Symbol) -> Hash[String, untyped]
33
+ def with_other_text_in(field, name) = to_h.merge(field => shown(@also_printed.fetch(field).fetch(name)))
33
34
 
34
35
  # Each placeholder printed in its own field naming its entry's id; a field's other text is printed only by
35
36
  # some of its requests, so another template leaving it is not read as this one's.
@@ -73,7 +74,7 @@ module Principles
73
74
  # Whether value is a text the template prints in field.
74
75
  #: (String, untyped) -> bool
75
76
  def printed?(field, value)
76
- [@placeholders[field], @also_printed[field]].compact.any? do |printed|
77
+ [@placeholders[field], *@also_printed.fetch(field, {}).values].compact.any? do |printed|
77
78
  printed.is_a?(NamedPlaceholder) ? printed.left?(value) : printed == value
78
79
  end
79
80
  end
@@ -0,0 +1,82 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "answer_place"
6
+ require_relative "disposition_placeholders"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # The part of a finding that a fix settles only in part, which the fix leaves unfixed: raised as a finding of its
12
+ # own, under the id the agent gives it, deferred or accepted as a disposition is, so the record keeps both the
13
+ # part fixed and the part still open, rather than deferring the whole finding. Its outcome is checked as the
14
+ # disposition of that new finding.
15
+ class UnfixedPart
16
+ # What an unfixed part may be left as: open, since the part fixed belongs to the fix itself.
17
+ ACTIONS = %w[deferred accepted].freeze #: Array[String]
18
+
19
+ # part is the unfixed_part the disposition fixing in part gives, at place in the answer; outcome is part as
20
+ # the new finding's own disposition.
21
+ #: (Hash[String, untyped], of: Disposition, outcome: Disposition, place: AnswerPlace) -> void
22
+ def initialize(part, of:, outcome:, place:)
23
+ @part = part
24
+ @of = of
25
+ @outcome = outcome
26
+ @place = place
27
+ freeze
28
+ end
29
+
30
+ # The id of the finding it raises, as the agent gave it.
31
+ #: () -> untyped
32
+ def id = @part["id"]
33
+
34
+ # Its problem and reason when left empty or as the question's example, then each other field its outcome
35
+ # leaves for the agent still, as a disposition's, refusing it first when it is fixed or disagreed, which leave
36
+ # nothing open.
37
+ #: () -> Array[UnfinishedField]
38
+ def unfinished
39
+ action = @part["action"]
40
+ if (Disposition::ACTIONS - ACTIONS).include?(action)
41
+ refuse("/action", "is #{action.inspect}, not deferred or accepted",
42
+ "Set its action to deferred or accepted; a part fixed too belongs to the fix itself.")
43
+ end
44
+ own = DispositionPlaceholders::UNFIXED_TEXT_FIELDS.filter_map do |name, field|
45
+ field.left_in(@part[name], @place.child(name), name, sample: nil)
46
+ end
47
+ [*own, *@outcome.unfinished].uniq { it.field.fetch("pointer") }
48
+ end
49
+
50
+ # Refuses it unless it belongs to a fix, and its pointers and waits_on unless they are sound, as a disposition's.
51
+ #: () -> void
52
+ def check
53
+ unless @of.fixed?
54
+ refuse("", "is only for a fix, and this disposition is #{@of.action}", "Leave unfixed_part out.")
55
+ end
56
+ @outcome.claimed_members([])
57
+ end
58
+
59
+ # The finding it raises from finding, the one its fix settles in part: finding's members and evidence, with its
60
+ # own id, problem and outcome; refused when taken, the ids of the record's other findings, holds its id.
61
+ #: (Hash[String, untyped], Array[untyped]) -> Hash[String, untyped]
62
+ def raised_from(finding, taken)
63
+ if taken.include?(id)
64
+ refuse("/id", "takes the id #{id}, which another finding has",
65
+ "Give it an id that no other finding in this audit's record has.")
66
+ end
67
+ { "id" => id, **finding.slice("member_ids", "evidence"), "problem" => @part.fetch("problem"),
68
+ **@outcome.recorded_outcome }
69
+ end
70
+
71
+ private
72
+
73
+ # Refuses what sits at pointer, inside the unfixed part, with problem and repair.
74
+ #: (String, String, String) -> bot
75
+ def refuse(pointer, problem, repair)
76
+ message = "Finding #{@of.finding_id}'s unfixed_part #{problem}"
77
+ raise Error.new("invalid_disposition", message, repair,
78
+ fields: [{ "pointer" => "#{@place.pointer}#{pointer}", "problem" => message }])
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # A principle's plugin members no installed plugin gives, each with the refusal that says why, which no move or
10
+ # removal in the project fixes, so they are refused apart from its broken members.
11
+ class UnresolvedPluginMembers
12
+ # members are their entries, each its id with its refusal's code, message and repair.
13
+ #: (Array[Hash[String, untyped]], principle: String) -> void
14
+ def initialize(members, principle:)
15
+ @members = members
16
+ @principle = principle
17
+ freeze
18
+ end
19
+
20
+ #: () -> bool
21
+ def empty? = @members.empty?
22
+
23
+ # The refusal naming each member, with its own reason and repair.
24
+ #: () -> Error
25
+ def refusal
26
+ ids = @members.map { |member| member.fetch("id") }
27
+ Error.new("plugin_members_unresolved",
28
+ "#{ids.length} of #{@principle}'s members are in no plugin installed for this project: " \
29
+ "#{ids.join(", ")}",
30
+ "Follow each member's repair, then run the command again.")
31
+ .including("principle" => @principle, "members" => @members)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # How a full audit's request prints a whole-file member's text: in a part of its own, which the index lists and
8
+ # sizes, so a member's part does not print tens of kilobytes beside its metadata. A member the audit judges is
9
+ # read whole from that part, as a stated step of the judgement, since no diff shows a line a change elsewhere
10
+ # left stale, and so is a carried member a fact fires on, if the agent judges it again. A member judged for its
11
+ # text changing shows its changed lines beside that step: an acknowledged one in its acknowledged lines, any
12
+ # other in changed_lines. A passage keeps its text in its member part.
13
+ class WholeFileMemberRead
14
+ # whole_file says whether the member is a whole file; listed is the member as the request lists it, with
15
+ # carried_forward and flagged when its last assessment is carried, or judge_because when it is judged again.
16
+ #: (whole_file: bool, listed: Hash[String, untyped]) -> void
17
+ def initialize(whole_file:, listed:)
18
+ @whole_file = whole_file
19
+ @listed = listed
20
+ freeze
21
+ end
22
+
23
+ # Whether the member's text prints in a part of its own rather than in its member part.
24
+ #: () -> bool
25
+ def text_apart? = @whole_file
26
+
27
+ # When the request says to read that part whole: "judged", as a step of judging the member, or "flagged", for a
28
+ # carried member a fact fires on, if the agent judges it again; nil when it does not say to.
29
+ #: () -> String?
30
+ def read_whole
31
+ return unless @whole_file
32
+ return "judged" unless carried?
33
+
34
+ "flagged" if @listed["flagged"]
35
+ end
36
+
37
+ # Whether its part shows its changed lines since the last full audit: its text changed and no acknowledgement
38
+ # shows the change.
39
+ #: () -> bool
40
+ def changed_lines? = @whole_file && @listed["judge_because"] == "text_changed"
41
+
42
+ private
43
+
44
+ #: () -> bool
45
+ def carried? = !@listed["carried_forward"].nil?
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # The parts of a candidate outline that text other than Markdown lacks: a description and an opening line, which
8
+ # a script or a CI workflow, outlined by its comments or its jobs, never has.
9
+ module WithoutProse
10
+ #: () -> nil
11
+ def description = nil
12
+
13
+ #: () -> nil
14
+ def cut_description = nil
15
+
16
+ #: () -> nil
17
+ def opening_line = nil
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,92 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "psych"
5
+ require_relative "outline_section"
6
+ require_relative "text_within"
7
+ require_relative "without_prose"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # A CI workflow's text as its outline reads it: a section per job, headed by its id and name, its items the job's
13
+ # steps, each by its name or else what it runs or uses. A rule a project enforces in CI is named there, and a
14
+ # survey reading Markdown headings alone never found it. The YAML is read as nodes, which keep each job's lines
15
+ # and leave a key such as `on` a string.
16
+ class WorkflowJobs
17
+ include WithoutProse
18
+
19
+ # A GitHub Actions workflow file, the kind of text this reads.
20
+ PATH = %r{(?:\A|/)\.github/workflows/[^/]+\.ya?ml\z}
21
+ # What a step without a name is known by, in the order looked for.
22
+ STEP_KEYS = %w[run uses].freeze
23
+
24
+ #: (String) -> void
25
+ def initialize(text)
26
+ @text = text
27
+ freeze
28
+ end
29
+
30
+ # Each job as a section, spanning the lines from its id to its last; none when the YAML does not parse, so the
31
+ # file is listed by its path and size alone.
32
+ #: () -> Array[OutlineSection]
33
+ def sections
34
+ document = Psych.parse(@text) or return []
35
+
36
+ pairs(value(document.root, "jobs")).map do |id, job|
37
+ OutlineSection.new(heading: heading(id.value, value(job, "name")), items: steps(value(job, "steps")),
38
+ first_line: id.start_line + 1, last_line: job.end_line)
39
+ end
40
+ rescue Psych::SyntaxError
41
+ []
42
+ end
43
+
44
+ private
45
+
46
+ #: (String, Psych::Nodes::Node?) -> String
47
+ def heading(id, name) = name.is_a?(Psych::Nodes::Scalar) ? "job #{id}: #{name.value}" : "job #{id}"
48
+
49
+ # Each step as an item, by its name, or else by the first line of what it runs or the action it uses, on the line
50
+ # its step starts.
51
+ #: (Psych::Nodes::Node?) -> Array[OutlineItem]
52
+ def steps(sequence)
53
+ return [] unless sequence.is_a?(Psych::Nodes::Sequence)
54
+
55
+ sequence.children.filter_map do |step|
56
+ text = step_text(step) or next
57
+
58
+ OutlineItem.new("- #{TextWithin.new(text, at_most: OutlineSection::ITEM_CHARACTERS).by_words}",
59
+ line: step.start_line + 1)
60
+ end
61
+ end
62
+
63
+ # A step by its name, or else by the first line of what it runs or the action it uses; nil with none of them.
64
+ #: (Psych::Nodes::Node) -> String?
65
+ def step_text(step)
66
+ key = STEP_KEYS.find { |each| scalar(step, each) }
67
+ scalar(step, "name") || (key && "#{key}: #{scalar(step, key).to_s.lines.first.to_s.strip}")
68
+ end
69
+
70
+ # The text of a mapping's scalar value under key; nil when it has none.
71
+ #: (Psych::Nodes::Node?, String) -> String?
72
+ def scalar(mapping, key)
73
+ found = value(mapping, key)
74
+ found.value if found.is_a?(Psych::Nodes::Scalar)
75
+ end
76
+
77
+ # A mapping's value node under key; nil when the node is no mapping or lacks the key.
78
+ #: (Psych::Nodes::Node?, String) -> Psych::Nodes::Node?
79
+ def value(mapping, key) = pairs(mapping).find { |found, _| found.value == key }&.last
80
+
81
+ # A mapping's keys with their values, its keys scalars; none for any other node.
82
+ #: (Psych::Nodes::Node?) -> Array[[Psych::Nodes::Scalar, Psych::Nodes::Node]]
83
+ def pairs(mapping)
84
+ return [] unless mapping.is_a?(Psych::Nodes::Mapping)
85
+
86
+ mapping.children.each_slice(2).filter_map do |key, found|
87
+ [key, found] if key.is_a?(Psych::Nodes::Scalar) && found
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,27 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The options choosing which form show-members-in-logged-requests prints, --short, --places or --member, and what
8
+ # is wrong with them as given, which CommandLine refuses as a usage error.
9
+ class ShowMembersInLoggedRequestsOptions
10
+ #: (InvocationOptions) -> void
11
+ def initialize(options)
12
+ @places = !options.value("places").nil? #: bool
13
+ @short = !options.value("short").nil? #: bool
14
+ @member = !options.value("member").nil? #: bool
15
+ freeze
16
+ end
17
+
18
+ # What is wrong with the options as given, or nil when they fit.
19
+ #: () -> String?
20
+ def fault
21
+ return "--member lists the named members' places, which --short does not print; give one" if @member && @short
22
+ return "--member lists the named members' places, and --places every member's; give one" if @member && @places
23
+
24
+ "--places lists every place a member was seen, which --short does not print; give one" if @places && @short
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The options choosing what show-principle prints, every member or the one --member names, and what is wrong with
8
+ # them as given, which CommandLine refuses as a usage error.
9
+ class ShowPrincipleOptions
10
+ COMMAND = "show-principle"
11
+ # How a refusal of several --member options says to repair it.
12
+ ONE_OR_NONE = "give one, or none for every member"
13
+
14
+ #: (InvocationOptions) -> void
15
+ def initialize(options)
16
+ @members = (options.value("member") || []).size #: Integer
17
+ @loads = !options.value("loads").nil? #: bool
18
+ freeze
19
+ end
20
+
21
+ # What is wrong with the options as given, or nil when they fit: --member prints one member, so a second would be
22
+ # dropped without a word, and so would --loads, which adds to the whole map.
23
+ #: () -> String?
24
+ def fault
25
+ return "#{COMMAND} prints one member, but --member was given #{@members} times; #{ONE_OR_NONE}" if @members > 1
26
+ return unless @loads && @members == 1
27
+
28
+ "--loads adds when each member's file loads to the whole map, which --member does not print; drop --loads to " \
29
+ "see one member, or --member to see every member's loads"
30
+ end
31
+ end
32
+ end
@@ -3,9 +3,9 @@
3
3
 
4
4
  module Principles
5
5
  # The next production release, as major.minor.patch. A production build is versioned with this alone.
6
- RELEASE = "0.1.2"
6
+ RELEASE = "0.1.4"
7
7
  # The version a built gem prints. `rake build[production]` stamps RELEASE here, in the copy of lib/ it
8
8
  # packages, and `rake build[development]` stamps RELEASE.g<short sha>. A checkout leaves it nil, and
9
9
  # Data::RunningVersion reads the commit this tool runs from instead.
10
- BUILT_VERSION = "0.1.2" #: String?
10
+ BUILT_VERSION = "0.1.4" #: String?
11
11
  end
@@ -17,43 +17,62 @@ module Principles
17
17
  freeze
18
18
  end
19
19
 
20
- # The acknowledgement of each of member_ids was accepted, and file holds them all.
21
- #: (principle_id: String, member_ids: Array[String], file: String) -> AnsweredRequest
22
- def several_acknowledged(principle_id:, member_ids:, file:)
20
+ # The acknowledgement of each of member_ids was accepted, and file holds them all; open_findings are the ids of
21
+ # the findings the last audit left open on them, which it leaves open.
22
+ #: (principle_id: String, member_ids: Array[String], file: String, ?open_findings: Array[String])
23
+ #| -> AnsweredRequest
24
+ def several_acknowledged(principle_id:, member_ids:, file:, open_findings: [])
23
25
  AnsweredRequest.new(
24
26
  "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => member_ids,
25
27
  "files_to_commit" => [file],
26
28
  "next_action" => "Commit #{file}. #{ProseList.new(member_ids)} read as judged until each is edited again.\n" \
27
- "This no longer lists them: " \
29
+ "#{still_open(principle_id, open_findings)}This no longer lists them: " \
28
30
  "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
29
31
  )
30
32
  end
31
33
 
32
34
  # The acknowledgement of each of member_ids was accepted for every principle that maps it, each principle's in its
33
- # file, under its id in files.
34
- #: (member_ids: Array[String], files: Hash[String, String]) -> AnsweredRequest
35
- def across_acknowledged(member_ids:, files:)
35
+ # file, under its id in files; open_findings are, under a principle's id, the ids of the findings its last audit
36
+ # left open on them, which it leaves open.
37
+ #: (member_ids: Array[String], files: Hash[String, String], ?open_findings: Hash[String, Array[String]])
38
+ #| -> AnsweredRequest
39
+ def across_acknowledged(member_ids:, files:, open_findings: {})
36
40
  AnsweredRequest.new(
37
41
  "status" => "acknowledged", "principle_ids" => files.keys, "member_ids" => member_ids,
38
42
  "files_to_commit" => files.values,
39
43
  "next_action" => "Commit #{ProseList.new(files.values)}. #{ProseList.new(member_ids)} read as judged until " \
40
- "each is edited again.\nThis no longer lists them: " \
44
+ "each is edited again.\n#{open_findings.map { |id, ids| still_open(id, ids) }.join}" \
45
+ "This no longer lists them: " \
41
46
  "#{@invocation.in_project("list-member-problems", usage: "--short")}"
42
47
  )
43
48
  end
44
49
 
45
- # The acknowledgement was accepted and file holds it.
46
- #: (principle_id: String, member_id: String, file: String) -> AnsweredRequest
47
- def acknowledged(principle_id:, member_id:, file:)
50
+ # The acknowledgement was accepted and file holds it; open_findings are the ids of the findings the last audit
51
+ # left open on the member, which it leaves open.
52
+ #: (principle_id: String, member_id: String, file: String, ?open_findings: Array[String]) -> AnsweredRequest
53
+ def acknowledged(principle_id:, member_id:, file:, open_findings: [])
48
54
  fields = {
49
55
  "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => [member_id],
50
56
  "files_to_commit" => [file],
51
57
  "next_action" => "Commit #{file}. #{member_id} reads as judged until it is edited again.\n" \
52
- "This no longer lists it: " \
58
+ "#{still_open(principle_id, open_findings)}This no longer lists it: " \
53
59
  "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
54
60
  }
55
61
  AnsweredRequest.new(fields)
56
62
  end
63
+
64
+ private
65
+
66
+ # The line saying that open_findings stay open, since only a full audit of principle_id decides one, with the
67
+ # command that starts it; nothing when there are none.
68
+ #: (String, Array[String]) -> String
69
+ def still_open(principle_id, open_findings)
70
+ return "" if open_findings.empty?
71
+
72
+ stays, each = open_findings.one? ? %w[stays it] : %w[stay each]
73
+ "#{ProseList.new(open_findings)} #{stays} open: an acknowledgement decides no finding, and the next full " \
74
+ "audit decides #{each}: #{@invocation.in_project("start-audit", principle_id)}\n"
75
+ end
57
76
  end
58
77
  end
59
78
  end