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,143 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "frontmatter_fields"
6
+ require_relative "outline_section"
7
+ require_relative "text_within"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # A Markdown file's text as its outline reads it: its sections, each a heading and the top-level list items under
13
+ # it, its frontmatter description and its opening line. One user scripted a heading grep over 45 files to survey
14
+ # them, and missed a principles section written as one numbered list, so the outline reads both.
15
+ class MarkdownText
16
+ HEADING = /\A#+\s/
17
+ FENCE = /\A\s*(?:```|~~~)/
18
+ # A top-level list item, its marker and its text; an indented one is nested, and left out.
19
+ ITEM = /\A(\d+\.|[-*])\s+(.*)/
20
+ # A horizontal rule, such as `* * *` or `- - -`, which is no item.
21
+ RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
22
+ LINK = /\[([^\]]*)\]\([^)]*\)/
23
+ BOLD_LEAD = /\A\*\*[^*]+\*\*/
24
+ # The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
25
+ # mid-clause left 30 of one user's 45 opening lines a fragment. The line is short only when
26
+ # its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
27
+ # accepted, since the file's path and outline still say what it holds.
28
+ OPENING_CHARACTERS = 160
29
+ # The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
30
+ # one user's descriptions printed 12,537 B uncut, and suggested about 300.
31
+ DESCRIPTION_CHARACTERS = 300
32
+
33
+ # A description's key and any block scalar indicator, which its text starts after.
34
+ DESCRIPTION_KEY = /\Adescription:\s*(?:[>|][-+]?\s)?/
35
+ # A value inside a matching pair of quotes, printed without them; its escapes are left as written.
36
+ QUOTED = /\A(["'])(.*)\1\z/
37
+
38
+ #: (String) -> void
39
+ def initialize(text)
40
+ @lines = text.lines #: Array[String]
41
+ @frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
42
+ freeze
43
+ end
44
+
45
+ # Each heading with the items under it, and the items before the first heading when there are any, each with
46
+ # the lines of the file it spans.
47
+ #: () -> Array[OutlineSection]
48
+ def sections
49
+ body = unfenced
50
+ starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
51
+ starts.zip(starts.drop(1)).filter_map do |first, after|
52
+ section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
53
+ end
54
+ end
55
+
56
+ # The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
57
+ #: () -> String?
58
+ def description
59
+ written = @frontmatter.field_lines("$.description") or return nil
60
+ text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
61
+ text[QUOTED, 2] || text
62
+ rescue Error
63
+ nil
64
+ end
65
+
66
+ # The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
67
+ # characters it holds and the lines of the file that hold it, so the agent reads just those back.
68
+ #: () -> String?
69
+ def cut_description
70
+ text = description or return nil
71
+ within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
72
+ return text unless within.cut?
73
+
74
+ kept = within.kept
75
+ first, last = @frontmatter.field("$.description")
76
+ "#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
77
+ end
78
+
79
+ # The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
80
+ # joined, with links as their text. The first physical line was a fragment in a hard-wrapped file.
81
+ #: () -> String?
82
+ def opening_line
83
+ body = unfenced
84
+ first = body.index { |line| prose?(line) } or return nil
85
+ paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
86
+ TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
87
+ end
88
+
89
+ private
90
+
91
+ # The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
92
+ # heading nor an item.
93
+ #: (Array[String], first_line: Integer) -> OutlineSection?
94
+ def section(lines, first_line:)
95
+ heading = lines.first if lines.first&.match?(HEADING)
96
+ items = outline_items(lines, first_line:)
97
+ return nil unless heading || items.any?
98
+
99
+ OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
100
+ end
101
+
102
+ # The top-level list items among these body lines, each on its line of the file, the first of them first_line.
103
+ #: (Array[String], first_line: Integer) -> Array[OutlineItem]
104
+ def outline_items(lines, first_line:)
105
+ lines.each_index.select { |index| item?(lines.fetch(index)) }
106
+ .map { |index| OutlineItem.new(item(lines.fetch(index)), line: first_line + index) }
107
+ end
108
+
109
+ # A top-level list item, not a horizontal rule written with the same marks.
110
+ #: (String) -> bool
111
+ def item?(line) = line.match?(ITEM) && !line.match?(RULE)
112
+
113
+ # The index in the file of the body's first line, after any frontmatter.
114
+ #: () -> Integer
115
+ def body_start = (@frontmatter.closing_line || -1) + 1
116
+
117
+ #: (String) -> bool
118
+ def prose?(line)
119
+ text = line.strip
120
+ !text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
121
+ end
122
+
123
+ # The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
124
+ #: () -> Array[String]
125
+ def unfenced
126
+ fenced = false #: bool
127
+ body = @lines.drop(body_start).map(&:chomp)
128
+ body.map do |line|
129
+ fenced = !fenced if line.match?(FENCE)
130
+ fenced || line.match?(FENCE) ? "" : line
131
+ end
132
+ end
133
+
134
+ # An item by its marker and its bold lead, or its opening words, with links as their text.
135
+ #: (String) -> String
136
+ def item(line)
137
+ marker, text = line.match(ITEM)&.captures
138
+ text = text.to_s.gsub(LINK, '\1')
139
+ "#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: OutlineSection::ITEM_CHARACTERS).by_words}"
140
+ end
141
+ end
142
+ end
143
+ end
@@ -4,6 +4,7 @@
4
4
  require_relative "../error"
5
5
  require_relative "locator"
6
6
  require_relative "meta_principle"
7
+ require_relative "plugin_reference"
7
8
  require_relative "report_hooks"
8
9
 
9
10
  module Principles
@@ -31,7 +32,8 @@ module Principles
31
32
  # A new member field that changes what an audit asks or records gets the next format, and
32
33
  # Data::MapFiles::NEWEST_FORMAT moves with it.
33
34
  FIELD_FORMATS = { "path" => 1, "section" => 1, "starting_at" => 1, "ending_at" => 1, "role" => 1,
34
- "key" => 1, "check" => 2, "query" => 2 }.freeze #: Hash[String, Integer]
35
+ "key" => 1, "check" => 2, "query" => 2,
36
+ "pinned" => 4 }.freeze #: Hash[String, Integer]
35
37
 
36
38
  # The fields that say where a member's text is; a move replaces them whole.
37
39
  LOCATORS = %w[path section starting_at ending_at query].freeze #: [String, String, String, String, String]
@@ -111,6 +113,17 @@ module Principles
111
113
  @fields["role"]
112
114
  end
113
115
 
116
+ # What add-member read of a plugin's file when it mapped it, its version and the hash of its text, which no
117
+ # commit holds; nil for a project file.
118
+ #: () -> Hash[String, String]?
119
+ def pinned
120
+ @fields["pinned"]
121
+ end
122
+
123
+ # The installed plugin's file the member is in, which git holds no history of; nil for a project file.
124
+ #: () -> PluginReference?
125
+ def plugin_reference = PluginReference.in(path)
126
+
114
127
  # The command that enforces the member, which an audit asks the agent to run; nil when it has none.
115
128
  #: () -> String?
116
129
  def check
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "locate_refusal"
5
+ require_relative "mapped_baseline"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # One member as list-member-problems lists it: its principle, id and state against what this tool last knew of
11
+ # its text, with what a changed member was compared with, or, when it cannot be found, its refusal.
12
+ class MemberEntry
13
+ # now is the member's hash now, or the refusal that says why it cannot be found. source is where a plugin
14
+ # member found now comes from, at the version installed now.
15
+ #: (String, Member, untyped, MemberProblems::Baselines, ?source: Hash[String, untyped]?) -> void
16
+ def initialize(principle_id, member, now, baselines, source: nil)
17
+ @principle_id = principle_id
18
+ @member = member
19
+ @now = now #: untyped
20
+ @baselines = baselines
21
+ @source = source
22
+ freeze
23
+ end
24
+
25
+ #: () -> Hash[String, untyped]
26
+ def to_h
27
+ listed = { "principle" => @principle_id, "id" => @member.id }
28
+ now = @now
29
+ return compared(listed, now.to_s).merge(@source ? { "source" => @source } : {}) unless now.is_a?(Hash)
30
+ # A plugin member found in no installed plugin, for any reason, is one quiet state, not broken, so a teammate
31
+ # without the plugin, or with it in a shape this tool does not read, keeps every other member and map.
32
+ return listed.merge("state" => "plugin_unresolved", "reason" => now.fetch("code")) if @member.plugin_reference
33
+
34
+ listed.merge("state" => LocateRefusal.new(now).member_state).merge(now.except("status"))
35
+ end
36
+
37
+ private
38
+
39
+ # listed, compared with the last audit's hash for the member, or else with its hash at the commit that mapped
40
+ # it. An unchanged member compared only with the commit that mapped it has never been assessed, so it is
41
+ # counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited.
42
+ #: (Hash[String, untyped], String) -> Hash[String, untyped]
43
+ def compared(listed, sha)
44
+ then_sha, since = @baselines.of(@member.key)
45
+ return listed.merge("state" => "no_baseline") unless since
46
+ unless then_sha == sha
47
+ return listed.merge("state" => "changed", "since" => since,
48
+ **(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
49
+ end
50
+
51
+ assessed = !MappedBaseline::KINDS.include?(since["baseline"])
52
+ listed.merge("state" => assessed ? "unchanged" : "unchanged_since_mapping")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -64,6 +64,17 @@ module Principles
64
64
  { **regions.shown, "lines" => counts }
65
65
  end
66
66
 
67
+ # Its changed regions with context unchanged lines around each, as a full audit's request shows a whole file
68
+ # whose text changed beside the text it reads apart; left out once both sides' lines pass half the bytes of
69
+ # its text now, since the text, read whole, then costs less than the regions beside it.
70
+ #: (context: Integer) -> Hash[String, untyped]
71
+ def regions(context:)
72
+ found = ChangedRegions.new(@at_baseline, @now, hunks: LineDiff.new(@at_baseline, @now).hunks, context:)
73
+ return { "omitted" => "over_half_the_text" } if 2 * bytes(found.lines) > @now.sum(&:bytesize)
74
+
75
+ found.shown
76
+ end
77
+
67
78
  private
68
79
 
69
80
  # How many bytes the sides' lines hold together.
@@ -7,7 +7,9 @@ require_relative "frontmatter_fields"
7
7
  require_relative "member_file"
8
8
  require_relative "text_size"
9
9
  require_relative "agent_loads"
10
+ require_relative "carrier_kind"
10
11
  require_relative "hook_commands"
12
+ require_relative "plugin_reference"
11
13
  require_relative "skill_loads"
12
14
 
13
15
  module Principles
@@ -46,6 +48,12 @@ module Principles
46
48
  "when" => "not_determined", "not_derived" => "a rules folder below the project root"
47
49
  }.freeze #: Hash[String, String]
48
50
 
51
+ # A file of an installed plugin, which reaches a session by the plugin's own means, such as its hooks or
52
+ # skills, which this tool does not derive.
53
+ PLUGIN_FILE = {
54
+ "when" => "not_determined", "not_derived" => "a file of an installed plugin"
55
+ }.freeze #: Hash[String, String]
56
+
49
57
  # The member's loads, from its whole file as files hold it and its own lines in it; a file that cannot be
50
58
  # read gives no size, a member that cannot be found there no size of its own, and freshness reports why.
51
59
  #: (Data::ProjectFiles, Locator, hooks: HookCommands) -> MemberLoads
@@ -88,6 +96,11 @@ module Principles
88
96
  { "claude_code" => named.empty? ? claude_code : claude_code.merge("named_in_hooks" => named) }
89
97
  end
90
98
 
99
+ # The kind of carrier the member's file is, whose practices a request names for judging and editing it; kept out
100
+ # of to_h, so what each assessment was judged on stays as it was.
101
+ #: () -> CarrierKind
102
+ def carrier_kind = CarrierKind.new(@path, named_in_hooks: @hooks.naming(@path).any?)
103
+
91
104
  # The moments Claude Code loads the member's file at, as to_h names them.
92
105
  #: () -> Array[String]
93
106
  def moments
@@ -109,7 +122,9 @@ module Principles
109
122
  # When Claude Code loads the file, by its facility, with the size of what loads.
110
123
  #: () -> Hash[String, untyped]
111
124
  def claude_code
112
- found = carrier
125
+ return PLUGIN_FILE if PluginReference.in(@path)
126
+
127
+ found = loads_by_path
113
128
  return { "when" => "no_known_carrier" } unless found
114
129
 
115
130
  # A skill's description member costs its description at start, not the file, so it has only its own size.
@@ -157,7 +172,7 @@ module Principles
157
172
  # When Claude Code loads the file, by the facility its path makes it, or nil for a path it does not load
158
173
  # by itself.
159
174
  #: () -> Hash[String, untyped]?
160
- def carrier
175
+ def loads_by_path
161
176
  if @path.end_with?(".md")
162
177
  facility_loads = facility&.to_h
163
178
  return facility_loads if facility_loads
@@ -9,6 +9,8 @@ require_relative "principle_history"
9
9
  require_relative "principle_mapping_history"
10
10
  require_relative "member_state"
11
11
  require_relative "locate_refusal"
12
+ require_relative "mapped_baseline"
13
+ require_relative "member_entry"
12
14
 
13
15
  module Principles
14
16
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -22,20 +24,23 @@ module Principles
22
24
  # from, and each member's hash and commit at the commit that mapped it where it is.
23
25
  class Baselines
24
26
  # The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
25
- # where it is, read with the map as that commit held it; none outside git.
27
+ # where it is, read with the map as that commit held it, none outside git, or for a plugin member, which no
28
+ # commit holds, its version and hash as the map pinned them.
26
29
  #: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Baselines
27
30
  def self.of(project, members, mapping: nil)
28
31
  records = project.audit_records
29
- mapped = mapped_where_it_is(project, members, mapping: mapping)
30
- new(audit: records.readable(members.principle_id), mapped: mapped, in_git: project.history.inside_git?,
31
- hashes: records.hashes_to_compare(members.principle_id), mapping: mapping)
32
+ new(audit: records.readable(members.principle_id), mapped: mapped(project, members, mapping: mapping),
33
+ in_git: project.history.inside_git?, hashes: records.hashes_to_compare(members.principle_id),
34
+ mapping: mapping)
32
35
  end
33
36
 
34
- # Each member's hash and commit at the commit that mapped it where it is, read with the map as that commit
35
- # held it.
36
- #: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String, Hash[String, String]]
37
- def self.mapped_where_it_is(project, members, mapping: nil)
37
+ # What this tool knew of each member's text when it was mapped: its hash at the commit that mapped it where it
38
+ # is, read with the map as that commit held it, or a plugin member's pin.
39
+ #: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String, MappedBaseline]
40
+ def self.mapped(project, members, mapping: nil)
38
41
  project.principle_history(members.principle_id, mapping: mapping).mapped_baselines(members.keys)
42
+ .transform_values { MappedBaseline.at_commit(it.fetch("sha256"), it.fetch("commit")) }
43
+ .merge(members.pinned.transform_values { MappedBaseline.pinned(it) })
39
44
  end
40
45
 
41
46
  # Whether the project is in git, so a member with no baseline is one no commit holds yet.
@@ -49,7 +54,8 @@ module Principles
49
54
  # audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
50
55
  # completed, so a one-member audit is offered only where one would be accepted. hashes is the member
51
56
  # hashes the record holds, which a later copy may have written, so its members are compared read-only.
52
- #: (audit: AuditRecord?, mapped: Hash[String, Hash[String, String]], in_git: bool,
57
+ # mapped holds what this tool knew of each member's text when it was mapped, by key.
58
+ #: (audit: AuditRecord?, mapped: Hash[String, MappedBaseline], in_git: bool,
53
59
  #| ?hashes: RecordedHashes, ?mapping: PrincipleMappingHistory?) -> void
54
60
  def initialize(audit:, mapped:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE, mapping: nil)
55
61
  @hashes = hashes
@@ -66,19 +72,18 @@ module Principles
66
72
  def mapping_for(key)
67
73
  return if @hashes.hash_for(key)
68
74
 
69
- @mapping if @mapped.key?(key)
75
+ @mapping if @mapped[key]&.walks_history?
70
76
  end
71
77
 
72
78
  # The hash this tool last knew for the member known by key, and what it was: the last audit's, or else its
73
- # hash at the commit that mapped it, with why no audit gave one; neither when it has no baseline.
79
+ # hash when it was mapped, with why no audit gave one; neither when it has no baseline.
74
80
  #: (String) -> [String?, Hash[String, untyped]?]
75
81
  def of(key)
76
82
  if (audited = @hashes.hash_for(key))
77
83
  [audited, { "baseline" => "audit", "commit" => @audit_base }]
78
- elsif @mapped.key?(key)
79
- mapped = @mapped.fetch(key)
80
- [mapped.fetch("sha256"), { "baseline" => "mapping_commit", "commit" => mapped.fetch("commit"),
81
- "no_audit_because" => @hashes.empty? ? "no_audit_record" : "not_in_last_audit" }]
84
+ elsif (mapped = @mapped[key])
85
+ because = @hashes.empty? ? "no_audit_record" : "not_in_last_audit"
86
+ [mapped.sha256, { **mapped.since, "no_audit_because" => because }]
82
87
  else
83
88
  [nil, nil]
84
89
  end
@@ -113,8 +118,9 @@ module Principles
113
118
  map = project.principles.find(id)
114
119
  members = map.members
115
120
  mapping = PrincipleMappingHistory.load_if_linked(current: map, project: project)
116
- new(members: members, now: project.current_by_key(members),
117
- baselines: Baselines.of(project, members, mapping: mapping))
121
+ now = project.current_by_key(members)
122
+ new(members: members, now: now, baselines: Baselines.of(project, members, mapping: mapping),
123
+ sources: plugin_sources(project, members, now))
118
124
  rescue Error => e
119
125
  raise unless listing_all
120
126
 
@@ -122,15 +128,31 @@ module Principles
122
128
  new(members: none, now: {}, baselines: Baselines.of(project, none), unreadable: e.payload)
123
129
  end
124
130
 
131
+ # Where each plugin member found now comes from, by key, at the version installed now.
132
+ #: (Project, PrincipleMembers, Hash[String, untyped]) -> Hash[String, Hash[String, untyped]]
133
+ def self.plugin_sources(project, members, now)
134
+ sources = {} #: Hash[String, Hash[String, untyped]]
135
+ members.each do |member|
136
+ reference = member.plugin_reference
137
+ next unless reference && now[member.key].is_a?(String)
138
+
139
+ sources[member.key] = project.installed_plugins.source(reference)
140
+ end
141
+ sources
142
+ end
143
+ private_class_method :plugin_sources
144
+
125
145
  # now holds, for each member by key, its hash now or the refusal that says why it cannot be found.
126
146
  # unreadable is the refusal for a map this tool could not read, which is listed as one broken entry.
127
- #: (members: PrincipleMembers, now: Hash[String, untyped],
128
- #| baselines: Baselines, ?unreadable: Hash[String, untyped]?) -> void
129
- def initialize(members:, now:, baselines:, unreadable: nil)
147
+ # sources holds where each plugin member found now comes from, by key.
148
+ #: (members: PrincipleMembers, now: Hash[String, untyped], baselines: Baselines,
149
+ #| ?unreadable: Hash[String, untyped]?, ?sources: Hash[String, Hash[String, untyped]]) -> void
150
+ def initialize(members:, now:, baselines:, unreadable: nil, sources: {})
130
151
  @members = members
131
152
  @now = now
132
153
  @baselines = baselines
133
154
  @unreadable = unreadable
155
+ @sources = sources
134
156
  freeze
135
157
  end
136
158
 
@@ -162,7 +184,7 @@ module Principles
162
184
  # How many members no audit has assessed, compared only with the commit that mapped them, edited or not, which
163
185
  # --short counts on stdout; none while the principle's audits wait on an upgrade.
164
186
  #: () -> Integer
165
- def never_assessed = @baselines.waiting? ? 0 : compared_with.fetch("mapping_commit", 0)
187
+ def never_assessed = @baselines.waiting? ? 0 : MappedBaseline::KINDS.sum { compared_with.fetch(it, 0) }
166
188
 
167
189
  # The entries whose own text changed since this tool last knew it, those an audit assessed first. Given a
168
190
  # block, each gains "history", what the block makes of its member, the hash it was compared with, and its
@@ -172,7 +194,7 @@ module Principles
172
194
  def changed(&history)
173
195
  assessed, unassessed = changed_members.partition { |member| assessed?(member) }
174
196
  (assessed + unassessed).map do |member|
175
- history ? history_entry(member, history) : entry(member)
197
+ history && !member.plugin_reference ? history_entry(member, history) : entry(member)
176
198
  end
177
199
  end
178
200
 
@@ -281,26 +303,7 @@ module Principles
281
303
 
282
304
  #: (Member) -> Hash[String, untyped]
283
305
  def entry(member)
284
- listed = { "principle" => principle_id, "id" => member.id }
285
- now = @now[member.key]
286
- return compared(listed, member.key, now.to_s) unless now.is_a?(Hash)
287
-
288
- listed.merge("state" => LocateRefusal.new(now).member_state).merge(now.except("status"))
289
- end
290
-
291
- # listed, compared with the last audit's hash for key, or else with its hash at the commit that mapped it.
292
- # An unchanged member compared only with the commit that mapped it has never been assessed, so it is
293
- # counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited.
294
- #: (Hash[String, untyped], String, String) -> Hash[String, untyped]
295
- def compared(listed, key, sha)
296
- then_sha, since = baseline(key)
297
- return listed.merge("state" => "no_baseline") unless since
298
- unless then_sha == sha
299
- return listed.merge("state" => "changed", "since" => since,
300
- **(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
301
- end
302
-
303
- listed.merge("state" => since["baseline"] == "mapping_commit" ? "unchanged_since_mapping" : "unchanged")
306
+ MemberEntry.new(principle_id, member, @now[member.key], @baselines, source: @sources[member.key]).to_h
304
307
  end
305
308
 
306
309
  #: (String) -> [String?, Hash[String, untyped]?]
@@ -0,0 +1,36 @@
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 far one member's text reached the captured requests, from the places the scan saw it: how many requests
8
+ # held its lines, and the most bytes of them one request held.
9
+ class MemberReach
10
+ # member is one member as the scan reports it, with its status and the places it was seen.
11
+ #: (Hash[String, untyped]) -> void
12
+ def initialize(member)
13
+ @member = member
14
+ freeze
15
+ end
16
+
17
+ # Its key, its id where it is now once moved, status, the requests seen holding its lines and its most bytes in
18
+ # one.
19
+ #: () -> Hash[String, untyped]
20
+ def to_h
21
+ by_request = @member.fetch("seen").group_by { it.fetch("request") }.values
22
+ bytes = by_request.map { |places| places.sum { it.fetch("bytes") } }
23
+ { **@member.slice("member", "id"),
24
+ "status" => @member.fetch("status"), "seen_in" => bytes.size, "most_bytes" => bytes.max || 0 }
25
+ end
26
+
27
+ # Its reach as to_h gives it, after its principle, with the segments it was seen in, each once: bounded by the
28
+ # member, however many requests and places hold it.
29
+ #: () -> Hash[String, untyped]
30
+ def listed
31
+ { "principle" => @member.fetch("principle"), **to_h,
32
+ "segments" => @member.fetch("seen").map { it.fetch("segment") }.uniq }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -3,6 +3,8 @@
3
3
 
4
4
  require_relative "audited_member_lines"
5
5
  require_relative "located_text"
6
+ require_relative "missing_files"
7
+ require_relative "unresolved_plugin_members"
6
8
 
7
9
  module Principles
8
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -10,18 +12,35 @@ module Principles
10
12
  # Each of a map's members by id, where it is in its file now and the hash of what it says there, as
11
13
  # the project located them all.
12
14
  class MemberSnapshots
13
- # Locate every member before refusing, so one broken reference never hides another.
15
+ # Locate every member before refusing, so one broken reference never hides another. A plugin member no
16
+ # installed plugin gives is refused apart from the broken ones, since no move or removal in the project fixes it.
14
17
  #: (Project, Principle) -> MemberSnapshots
15
18
  def self.read(project, map)
19
+ found, broken, unresolved = located(project, map.members)
20
+ raise MissingFiles.new(broken, principle: map.id, history: project.history).refusal_of_map unless broken.empty?
21
+
22
+ unresolved = UnresolvedPluginMembers.new(unresolved, principle: map.id)
23
+ raise unresolved.refusal unless unresolved.empty?
24
+
25
+ new(found)
26
+ end
27
+
28
+ # Each of members located by id, and the entry of each that cannot be, with its refusal: the project's
29
+ # members apart from the plugin members no installed plugin gives.
30
+ #: (Project, PrincipleMembers)
31
+ #| -> [Hash[String, LocatedText], Array[Hash[String, untyped]], Array[Hash[String, untyped]]]
32
+ def self.located(project, members)
16
33
  broken = [] #: Array[Hash[String, untyped]]
34
+ unresolved = [] #: Array[Hash[String, untyped]]
17
35
  found = {} #: Hash[String, LocatedText]
18
- map.members.each do |member|
36
+ members.each do |member|
19
37
  found[member.id] = project.located_text(member.locator)
20
38
  rescue Error => e
21
- broken << { "id" => member.id }.merge(e.payload.except("status"))
39
+ (member.plugin_reference ? unresolved : broken) << { "id" => member.id }.merge(e.payload.except("status"))
22
40
  end
23
- broken.empty? ? new(found) : project.refuse_broken(map.id, broken)
41
+ [found, broken, unresolved]
24
42
  end
43
+ private_class_method :located
25
44
 
26
45
  #: (Hash[String, LocatedText]) -> void
27
46
  def initialize(by_id)
@@ -0,0 +1,31 @@
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
+ # A member's text as a host sends it. A host lists a skill by its frontmatter description's value, on one line
8
+ # after the skill's name, so a frontmatter field is that value alone: without its key, a block scalar's indicator
9
+ # or the quotes round it. Its lines are matched one by one, stripped, so a folded value's lines still match the
10
+ # one line the host joins them into.
11
+ class MemberTextAsSent
12
+ # The text of the member locator finds in project, a field when locator queries one.
13
+ #: (Project, Locator) -> MemberTextAsSent
14
+ def self.of(project, locator) = new(project.member_text(locator), field: !locator.query.nil?)
15
+
16
+ #: (String, field: bool) -> void
17
+ def initialize(text, field:)
18
+ @text = text
19
+ @field = field
20
+ freeze
21
+ end
22
+
23
+ #: () -> String
24
+ def to_s
25
+ return @text unless @field
26
+
27
+ @text.sub(/\A[\w-]+:[ \t]*(?:[>|][-+]?[ \t]*\n)?/, "").sub(/\A(["'])(.*)\1\s*\z/m, '\2')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "whole_file_member_read"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # Each member of a map's lines now, by id, without their line endings, which a full audit's request parts print
10
+ # so the agent reads the text each member is judged on, and which members' text prints in a part of its own.
11
+ class MemberTexts
12
+ # listed is each member as the request lists it, which says whether the audit carries or judges it.
13
+ #: (Project, Principle, listed: Array[Hash[String, untyped]]) -> void
14
+ def initialize(project, map, listed:)
15
+ @project = project
16
+ @map = map
17
+ @listed = listed.to_h { [it.fetch("id"), it] } #: Hash[String, Hash[String, untyped]]
18
+ freeze
19
+ end
20
+
21
+ # Each member's lines now, by id.
22
+ #: () -> Hash[String, Array[String]]
23
+ def lines
24
+ @map.members.to_h { [it.id, @project.member_file(it.path).lines_of(it.locator).map(&:chomp)] }
25
+ end
26
+
27
+ # The id of each member whose text prints in a part of its own, as WholeFileMemberRead decides.
28
+ #: () -> Array[String]
29
+ def apart_ids
30
+ @map.members.select { read(it).text_apart? }.map(&:id)
31
+ end
32
+
33
+ # When the request says to read each member's text part whole, by id, as WholeFileMemberRead#read_whole says.
34
+ #: () -> Hash[String, String]
35
+ def read_whole
36
+ @map.members.filter_map { |member| (when_read = read(member).read_whole) && [member.id, when_read] }.to_h
37
+ end
38
+
39
+ private
40
+
41
+ #: (Member) -> WholeFileMemberRead
42
+ def read(member) = WholeFileMemberRead.new(whole_file: member.whole_file?, listed: @listed.fetch(member.id))
43
+ end
44
+ end
45
+ end