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,53 @@
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 feature that runs fast standard tools in place of Ruby, on only while every tool it needs is on PATH, with
10
+ # no Ruby fallback. TOOLS is the one central table of them, so no command checks PATH
11
+ # itself.
12
+ class Feature
13
+ # The command that scans the logged requests, which a full audit's request also runs.
14
+ LOGGED_REQUEST_SCAN = "show-members-in-logged-requests"
15
+
16
+ # Each feature's command, and the tools it runs, each with what it does there.
17
+ TOOLS = {
18
+ LOGGED_REQUEST_SCAN => {
19
+ "jq" => "decodes each captured request into its text lines",
20
+ "rg" => "finds mapped members' lines in the decoded requests"
21
+ }
22
+ }.freeze #: Hash[String, Hash[String, String]]
23
+
24
+ # The feature command runs, with on_path saying whether PATH holds a tool.
25
+ #: (String, on_path: ^(String) -> bool) -> void
26
+ def initialize(command, on_path:)
27
+ @command = command
28
+ @tools = TOOLS.fetch(command) #: Hash[String, String]
29
+ @on_path = on_path
30
+ freeze
31
+ end
32
+
33
+ # Refuses while a tool the feature runs is not on PATH, naming the first missing and what it does, so the agent
34
+ # asks the user to install it.
35
+ #: () -> void
36
+ def refuse_while_off
37
+ refusal = off_refusal
38
+ raise refusal if refusal
39
+ end
40
+
41
+ # The refusal the feature gives while a tool it runs is not on PATH, or nil while it is on; for a command that
42
+ # carries on without the feature, such as a full audit's request without its logged-request evidence.
43
+ #: () -> Error?
44
+ def off_refusal
45
+ tool, does = @tools.find { |name, _| !@on_path.call(name) }
46
+ return unless tool
47
+
48
+ Error.new("fast_tools_missing", "#{@command} needs #{tool}, which #{does}, and #{tool} is not on PATH.",
49
+ "Ask the user before installing #{tool}, then run this again.")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,55 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "decided_prior_findings"
5
+ require_relative "recorded_finding"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # The findings a completed full audit records: each finding its assessment raised, with its correction's
11
+ # disposition, each prior finding the audit kept, and each finding a fix raised from the part of its finding it
12
+ # left unfixed.
13
+ class FindingOutcomes
14
+ # findings are those the assessment raised, dispositions the correction's, one for each, and prior the
15
+ # decisions on the findings the last audit left open.
16
+ #: (Array[untyped], Array[Disposition], DecidedPriorFindings) -> void
17
+ def initialize(findings, dispositions, prior)
18
+ @findings = findings
19
+ @dispositions = dispositions
20
+ @prior = prior
21
+ freeze
22
+ end
23
+
24
+ # Each finding's outcome: its members and its disposition's action, where it is recorded, if anywhere, and
25
+ # what a deferral says it waits on, if anything.
26
+ # Then each prior finding kept; a new finding that raises one again keeps when it was first raised. Then each
27
+ # finding raised from an unfixed part, which keeps when the finding it was part of was first raised.
28
+ #: () -> Array[untyped]
29
+ def recorded
30
+ raised = @findings.map do |finding|
31
+ id = finding.fetch("id")
32
+ outcome = disposition_of(id).recorded_outcome
33
+ finding.slice(*RecordedFinding::RAISED_FIELDS).merge(outcome, @prior.first_raised(id))
34
+ end + @prior.kept
35
+ @findings.reduce(raised) { |so_far, finding| with_unfixed_part(so_far, finding) }
36
+ end
37
+
38
+ private
39
+
40
+ #: (untyped) -> Disposition
41
+ def disposition_of(id) = @dispositions.find { |each| each.finding_id == id } || raise(KeyError, id)
42
+
43
+ # recorded, with the finding raised from the part of finding its fix left unfixed, if any, refused when an id
44
+ # in recorded is its id.
45
+ #: (Array[untyped], Hash[String, untyped]) -> Array[untyped]
46
+ def with_unfixed_part(recorded, finding)
47
+ id = finding.fetch("id")
48
+ part = disposition_of(id).unfixed_part
49
+ return recorded unless part
50
+
51
+ recorded + [part.raised_from(finding, recorded.map { it.fetch("id") }).merge(@prior.first_raised(id))]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -7,7 +7,7 @@ module Principles
7
7
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # Every finding the records leave open, deferred or accepted, as one fact the session-start line states: how
10
- # many wait, and which has waited longest.
10
+ # many deferred wait, and which of them has waited longest.
11
11
  class FindingsLeftOpen
12
12
  # The findings each record leaves open for the next full audit.
13
13
  #: (Array[AuditRecord]) -> FindingsLeftOpen
@@ -19,19 +19,17 @@ module Principles
19
19
  freeze
20
20
  end
21
21
 
22
- # How many are open, how many of them are deferred with no waits_on and how many with one, so how many someone
23
- # should raise, and the first raised earliest of those with one and of all, each as it has waited until now, or
24
- # nil when none is open. How long it waited runs from first_raised_at, never from when its
25
- # waits_on was asked, which a later audit may have given it.
22
+ # How many someone should raise, those deferred, how many of them have no waits_on and how many one, and the
23
+ # first raised earliest of them as it has waited until now, or nil when none is deferred: an accepted finding
24
+ # waits on no one by design, so every start counts the same. How long it waited runs from first_raised_at,
25
+ # never from when its waits_on was asked, which a later audit may have given it.
26
26
  #: (Time) -> Hash[String, untyped]?
27
27
  def waiting_at(now)
28
- oldest = @findings.min_by(&:first_raised_time) or return nil
28
+ deferred = @findings.select { it.action == "deferred" }
29
+ oldest = deferred.min_by(&:first_raised_time) or return nil
29
30
 
30
- named = @findings.select(&:waiting_on_someone_named?)
31
- unnamed = @findings.count(&:waiting_on_no_one_named?)
32
- { "count" => @findings.length, "waiting_on_no_one_named" => unnamed,
33
- "waiting_on_someone_named" => named.length, "to_raise" => named.length + unnamed,
34
- "oldest_waiting_on_someone" => named.min_by(&:first_raised_time)&.waited_at(now), **oldest.waited_at(now) }
31
+ { "count" => deferred.length, "waiting_on_no_one_named" => deferred.count(&:waiting_on_no_one_named?),
32
+ "waiting_on_someone_named" => deferred.count(&:waiting_on_someone_named?), **oldest.waited_at(now) }
35
33
  end
36
34
  end
37
35
  end
@@ -10,7 +10,8 @@ module Principles
10
10
  # Which repositories' HEAD a shell call moved by committing, each named once, in the order the call's
11
11
  # directories name them, with the commit HEAD named before the move: what report-after-commit reports on. A
12
12
  # checkout or a reset moves HEAD to commits that exist already, so neither is named; the next session start
13
- # shows any change there. A project never mapped, under the folder's name now or its earlier one, is not named.
13
+ # shows any change there. A project never mapped, under the folder's name now or its earlier one, is not named,
14
+ # nor a repository other than the session's project's, such as a scratch clone; its worktrees are named.
14
15
  class HeadMoves
15
16
  # One repository's move: its root, and the full sha HEAD named before it.
16
17
  class Move
@@ -28,9 +29,12 @@ module Principles
28
29
  # The reflog subjects of moves that bring in no new commit.
29
30
  NOT_A_COMMIT = /\A(?:checkout|reset):/ #: Regexp
30
31
 
32
+ # What git says of a directory on this machine.
33
+ GIT_AT = ->(directory) { Data::HeadReflog.new(directory) } #: ^(String) -> untyped
34
+
31
35
  # git_at gives what git says of a directory, as Data::HeadReflog does.
32
36
  #: (AfterCommitInput, ?^(String) -> untyped) -> void
33
- def initialize(input, git_at = ->(directory) { Data::HeadReflog.new(directory) })
37
+ def initialize(input, git_at = GIT_AT)
34
38
  @input = input
35
39
  @git_at = git_at
36
40
  freeze
@@ -38,20 +42,33 @@ module Principles
38
42
 
39
43
  #: () -> Array[Move]
40
44
  def to_a
41
- seen = [] #: Array[String]
42
- @input.directories.filter_map do |directory|
43
- git = @git_at.call(directory)
44
- root = git.toplevel
45
- next if root.nil? || seen.include?(root)
46
-
47
- seen << root
45
+ project = nil #: String?
46
+ repositories.filter_map do |root, git|
48
47
  before = git.mapped? && before_the_move(git)
49
- Move.new(root:, before:) if before
48
+ next unless before && git.common_dir == (project ||= the_sessions_repository)
49
+
50
+ Move.new(root:, before:)
50
51
  end
51
52
  end
52
53
 
53
54
  private
54
55
 
56
+ # The git folder of the session's project, which its worktrees share and a clone does not, or a value no
57
+ # repository's matches when the session's directory is outside git. Asked only once a repository moved, so a
58
+ # call that committed nothing costs no more git.
59
+ #: () -> String
60
+ def the_sessions_repository = @git_at.call(@input.session_directory).common_dir || ""
61
+
62
+ # Each repository the call's directories are in, once, in their order: what git says of it, by its root.
63
+ #: () -> Hash[String, untyped]
64
+ def repositories
65
+ @input.directories.each_with_object({}) do |directory, found|
66
+ git = @git_at.call(directory)
67
+ root = git.toplevel
68
+ found[root] ||= git if root
69
+ end
70
+ end
71
+
55
72
  # The commit HEAD named before it moved during the call, or nil when it did not move then, or moved to no
56
73
  # new commit. Without a reflog, HEAD's committer time stands in, and the commit before HEAD starts the range.
57
74
  #: (untyped) -> String?
@@ -0,0 +1,55 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "digest"
5
+ require_relative "plugin_install"
6
+ require_relative "plugin_reference"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # A file of an installed plugin as a session here would read it: its reference, the install it is in and its
12
+ # text, read once.
13
+ class InstalledComponent
14
+ #: String
15
+ attr_reader :text
16
+
17
+ #: (PluginReference, PluginInstall, String) -> void
18
+ def initialize(reference, install, text)
19
+ @reference = reference
20
+ @install = install
21
+ @text = text
22
+ freeze
23
+ end
24
+
25
+ # The version the host installed, for the agent's information only.
26
+ #: () -> String?
27
+ def version = @install.version
28
+
29
+ # The member's path in its map, as its reference names it.
30
+ #: () -> String
31
+ def member_path = @reference.to_s
32
+
33
+ # What the map pins of it: the version installed, and the hash of its text, which alone says whether it changed.
34
+ #: () -> Hash[String, String]
35
+ def pinned = { "version" => version.to_s, "sha256" => Digest::SHA256.hexdigest(@text) }
36
+
37
+ # Where it comes from, as a result prints it.
38
+ #: () -> Hash[String, untyped]
39
+ def source = @reference.source(version)
40
+
41
+ # Its entry in a map, playing role.
42
+ #: (String) -> Hash[String, untyped]
43
+ def member(role) = { "path" => member_path, "role" => role, "pinned" => pinned }
44
+
45
+ # What add-member reports of it: its id, the lines it spans and where it comes from. No host's loading of a
46
+ # plugin's file is derived yet.
47
+ #: () -> Hash[String, untyped]
48
+ def added = { "id" => member_path, **lines, "loading" => "not_derived", "source" => source }
49
+
50
+ # The lines it spans: the whole file.
51
+ #: () -> Hash[String, Integer]
52
+ def lines = { "first_line" => 1, "last_line" => [@text.lines.size, 1].max }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,174 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "../data/claude_code_home"
7
+ require_relative "plugin_install"
8
+ require_relative "plugin_component"
9
+ require_relative "plugin_name"
10
+ require_relative "installed_component"
11
+ require_relative "member_file"
12
+
13
+ module Principles
14
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
15
+ module Models
16
+ # The plugins Claude Code installed that a session in the project loads, as the registry in its home records them;
17
+ # none while it has installed none.
18
+ class InstalledPlugins
19
+ # The most files a refusal names; it counts the rest.
20
+ LISTED = 20 #: Integer
21
+
22
+ # The marketplace kinds whose plugins Claude Code copies into the install folder its registry names, which is
23
+ # where a session reads them.
24
+ COPIED = %w[github git url].freeze #: Array[String]
25
+
26
+ #: (Data::ClaudeCodeHome, main_checkout: String) -> void
27
+ def initialize(claude_code, main_checkout:)
28
+ @claude_code = claude_code
29
+ @main_checkout = main_checkout
30
+ freeze
31
+ end
32
+
33
+ # The install of the plugin named that a session here loads, refused when there is none, naming those there
34
+ # are; when its marketplace is a local folder, whose session reads the folder rather than the install; and when
35
+ # its marketplace is of no kind COPIED names, since a session may read that from elsewhere too.
36
+ #: (String) -> PluginInstall
37
+ def install(name)
38
+ install = PluginInstall.applying(rows(name), main_checkout: @main_checkout) or refuse_not_installed(name)
39
+ kind = @claude_code.marketplaces&.source_kind(PluginName.new(name).marketplace)
40
+ refuse_directory_marketplace(name) if kind == "directory"
41
+ refuse_unknown_marketplace(name) unless COPIED.include?(kind)
42
+ install.version.to_s.empty? ? refuse_unversioned(name) : install
43
+ end
44
+
45
+ # The file component names in the plugin named, with its text, refused when it is reached through a symbolic
46
+ # link, which this tool never follows; when the plugin holds no such file, naming those it does; and when its
47
+ # text is not UTF-8 or larger than this tool reads.
48
+ #: (String, PluginComponent) -> InstalledComponent
49
+ def holding(name, component)
50
+ install = install(name)
51
+ folder = @claude_code.plugin_folder(install.install_path.to_s)
52
+ refuse_linked(name, component) if folder.linked?(component.path)
53
+ refuse_not_held(name, folder.files) unless folder.file?(component.path)
54
+ InstalledComponent.new(PluginReference.new(name, component), install, folder.read(component.path))
55
+ end
56
+
57
+ # Whether the plugin installed now holds the file reference names, as holding finds it.
58
+ #: (PluginReference) -> bool
59
+ def holds?(reference)
60
+ holding(reference.name, reference.component)
61
+ true
62
+ rescue Error
63
+ false
64
+ end
65
+
66
+ # Where the file reference names comes from, at the version installed now, refused as install refuses.
67
+ #: (PluginReference) -> Hash[String, untyped]
68
+ def source(reference) = reference.source(install(reference.name).version)
69
+
70
+ # Where member comes from when a plugin gives it, as source says; nil for a member in a project file.
71
+ #: (Member) -> Hash[String, untyped]?
72
+ def source_of(member)
73
+ reference = member.plugin_reference or return
74
+ source(reference)
75
+ end
76
+
77
+ # The file a mapped plugin member's reference names, as the type that finds the member in it, refused as
78
+ # holding refuses it.
79
+ #: (PluginReference) -> MemberFile
80
+ def member_file(reference)
81
+ MemberFile.for(path: reference.to_s, text: holding(reference.name, reference.component).text)
82
+ end
83
+
84
+ # The install names of the plugins a session here loads, sorted.
85
+ #: () -> Array[String]
86
+ def names
87
+ (@claude_code.registry&.names || []).select do |name|
88
+ PluginInstall.applying(rows(name), main_checkout: @main_checkout)
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ #: (String) -> Array[Hash[String, String?]]
95
+ def rows(name) = @claude_code.registry&.rows(name) || []
96
+
97
+ #: (String, Array[String]) -> bot
98
+ def refuse_not_held(name, files)
99
+ plain, skipped = files.partition { |path| PluginComponent.plain?(path) }
100
+ listed = plain.first(LISTED) + (plain.size > LISTED ? ["#{plain.size - LISTED} more"] : [])
101
+ repair = if listed.empty?
102
+ "#{name} holds no file this tool can map.#{left_out(skipped, "")} Map the project's own files " \
103
+ "instead."
104
+ else
105
+ "Name one of the files #{name} holds: #{ProseList.new(listed)}.#{left_out(skipped, " more")}"
106
+ end
107
+ raise Error.new("plugin_component_not_found", "#{name} holds no such file", repair)
108
+ end
109
+
110
+ # A sentence, after a space, counting the files skipped that a refusal leaves out for their paths, as more
111
+ # when it lists others; nothing when there are none.
112
+ #: (Array[String], String) -> String
113
+ def left_out(skipped, more)
114
+ return "" if skipped.empty?
115
+
116
+ " #{skipped.size}#{more} #{skipped.one? ? "is" : "are"} left out, since a member's path takes only plain " \
117
+ "characters."
118
+ end
119
+
120
+ #: (String, PluginComponent) -> bot
121
+ def refuse_linked(name, component)
122
+ raise Error.new("plugin_component_linked",
123
+ "#{component.path} in #{name} is reached through a symbolic link, which this tool does not " \
124
+ "follow, since it could lead out of the plugin",
125
+ "Name the file the link leads to by its own path inside the plugin, or map the project's own " \
126
+ "files instead.")
127
+ end
128
+
129
+ #: (String) -> bot
130
+ def refuse_directory_marketplace(name)
131
+ raise Error.new("plugin_from_directory_marketplace", "#{name} comes from a marketplace in a local folder",
132
+ "Map the project's own files instead; a plugin from a marketplace in a local folder is " \
133
+ "not supported yet.")
134
+ end
135
+
136
+ # A probe saw the host record a version in every row, a commit's first digits when the plugin names none.
137
+ #: (String) -> bot
138
+ def refuse_unversioned(name)
139
+ raise Error.new("unreadable_plugin_registry", "Claude Code's plugin registry records no version for #{name}",
140
+ "Reinstall the plugin with Claude Code, or map the project's own files instead.")
141
+ end
142
+
143
+ #: (String) -> bot
144
+ def refuse_unknown_marketplace(name)
145
+ raise Error.new("plugin_marketplace_unknown",
146
+ "Claude Code records no marketplace kind this tool reads for #{name}",
147
+ "Map the project's own files instead; this tool reads a plugin only from a marketplace " \
148
+ "Claude Code records as #{ProseList.new(COPIED, conjunction: "or")}.")
149
+ end
150
+
151
+ #: (String) -> bot
152
+ def refuse_not_installed(name)
153
+ here = names
154
+ choices = if here.empty?
155
+ "No plugin is installed for this project. Install #{name} with Claude Code first."
156
+ else
157
+ "Installed for this project: #{ProseList.new(here)}. Name one of them with --plugin, or install " \
158
+ "#{name} with Claude Code first."
159
+ end
160
+ repair = elsewhere(name) + choices
161
+ raise Error.new("plugin_not_installed", "#{name} is not installed for this project", repair)
162
+ end
163
+
164
+ # Why name's rows, when it has some, do not apply here: each installs it for another project.
165
+ #: (String) -> String
166
+ def elsewhere(name)
167
+ return "" if rows(name).empty?
168
+
169
+ "#{name} is installed only for another project, and only a user-scope install is read outside its own " \
170
+ "project. "
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,34 @@
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
+ # How many of the newest captured sessions remove-logged-requests keeps, as --keep-sessions gives it: a whole
10
+ # number, 0 keeping none, or 5 when it is not given.
11
+ class KeptSessions
12
+ DEFAULT = 5
13
+
14
+ #: Integer
15
+ attr_reader :count
16
+
17
+ #: (String?) -> void
18
+ def initialize(given)
19
+ @count = given ? whole(given) : DEFAULT #: Integer
20
+ freeze
21
+ end
22
+
23
+ private
24
+
25
+ #: (String) -> Integer
26
+ def whole(given)
27
+ return given.to_i if given.match?(/\A\d+\z/)
28
+
29
+ raise Error.new("invalid_keep_sessions", "--keep-sessions takes a whole number, not #{given.inspect}",
30
+ "Give how many of the newest sessions to keep, such as --keep-sessions 5; 0 keeps none.")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -50,6 +50,14 @@ module Principles
50
50
  !heading.nil? && starting_at.nil? && ending_at.nil? && query.nil?
51
51
  end
52
52
 
53
+ # This locator with its passage's opening quoted without its leading whitespace; nil when the opening has none.
54
+ #: () -> Locator?
55
+ def with_opening_unindented
56
+ opening = starting_at or return nil
57
+ unindented = opening.lstrip
58
+ Locator.new(@fields.merge("starting_at" => unindented)) unless unindented == opening
59
+ end
60
+
53
61
  # The locator as it was given.
54
62
  #: () -> Hash[String, untyped]
55
63
  def to_h = @fields
@@ -0,0 +1,44 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "member_reach"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # How far each member's text reached, compactly, from where the scan of the captured requests saw it: how many of
10
+ # the scanned requests held its lines, and the most bytes of them one request held. A full audit's request prints
11
+ # it, so the agent judging a member weighs whether it reaches the agent and what it costs there.
12
+ class LoggedRequestReach
13
+ # members is each member as the scan reports it, with its status and the places it was seen; scanned is how many
14
+ # requests the scan read whole, and unreadable how many it could not, since what they held is unknown; carried
15
+ # names each member a full audit carries forward, which is listed too, marked, since one that never loads still
16
+ # fails its principle.
17
+ #: (Array[Hash[String, untyped]], scanned: Integer, ?unreadable: Integer, ?carried: Array[String]) -> void
18
+ def initialize(members, scanned:, unreadable: 0, carried: [])
19
+ @members = members
20
+ @carried = carried
21
+ @scanned = scanned
22
+ @unreadable = unreadable
23
+ freeze
24
+ end
25
+
26
+ # The requests scanned, any it could not read, and each member's status, the requests seen holding its lines and
27
+ # its most bytes in one, and whether the audit carries it forward.
28
+ #: () -> Hash[String, untyped]
29
+ def to_h
30
+ { "requests" => @scanned, **({ "unreadable" => @unreadable } if @unreadable.positive?),
31
+ "members" => @members.map { reach(it) } }
32
+ end
33
+
34
+ private
35
+
36
+ # member's reach, marked when the audit carries it forward.
37
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
38
+ def reach(member)
39
+ reach = MemberReach.new(member).to_h
40
+ @carried.include?(member.fetch("member")) ? reach.merge("carried_forward" => true) : reach
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../data/logged_request_scan"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # How much of the captured requests one scan read: how many there were, how many strings it decoded, and whether
10
+ # it read every one through. A member reported absent is proven absent only when it did, so each request it did
11
+ # not decode to its end is named, beside those it could not read at all.
12
+ class LoggedRequestScanCompleteness
13
+ # What scan read in its run matched.
14
+ #: (Data::LoggedRequestScan, Data::LoggedRequestMatches) -> LoggedRequestScanCompleteness
15
+ def self.of(scan, matched)
16
+ new(requests: scan.requests.map { it.fetch("file").to_s }, unreadable: scan.unreadable, matched:)
17
+ end
18
+
19
+ #: (requests: Array[String], unreadable: Array[Hash[String, String]],
20
+ #| matched: Data::LoggedRequestMatches) -> void
21
+ def initialize(requests:, unreadable:, matched:)
22
+ @requests = requests
23
+ @matched = matched
24
+ undecoded = requests - unreadable.map { it.fetch("request") } - matched.leaves.keys
25
+ named = undecoded.map { { "request" => it, "reason" => "not_decoded" } }
26
+ @unreadable = [*unreadable, *named].freeze #: Array[Hash[String, String]]
27
+ freeze
28
+ end
29
+
30
+ # Each request the scan could not read through, by its request and reason.
31
+ #: Array[Hash[String, String]]
32
+ attr_reader :unreadable
33
+
34
+ # The requests captured, those it could not read too, the strings decoded in them, and whether the scan read
35
+ # every one through.
36
+ #: () -> Hash[String, untyped]
37
+ def to_h
38
+ { "captured" => @requests.size, "leaves" => @matched.leaves.values.sum,
39
+ "complete" => @unreadable.empty? && @matched.whole }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,46 @@
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
+ # What this tool knew of a member's text when it was mapped, which no audit has assessed: its hash at the commit
8
+ # that mapped it where it is, or, for a plugin member, which no commit holds, the hash its map pinned.
9
+ class MappedBaseline
10
+ # What "since" names each kind as, every one a baseline no audit gave, so a member compared with one alone has
11
+ # never been assessed.
12
+ KINDS = %w[mapping_commit pinned].freeze #: Array[String]
13
+
14
+ # The member's hash at the commit that mapped it where it is, from which its automatic history walks.
15
+ #: (String, String) -> MappedBaseline
16
+ def self.at_commit(sha256, commit)
17
+ new(sha256, { "baseline" => "mapping_commit", "commit" => commit }, walks_history: true)
18
+ end
19
+
20
+ # A plugin member's pin, its version and hash when add-member read it, which git holds no history of.
21
+ #: (Hash[String, String]) -> MappedBaseline
22
+ def self.pinned(pin)
23
+ new(pin.fetch("sha256"), { "baseline" => "pinned", "version" => pin.fetch("version") }, walks_history: false)
24
+ end
25
+
26
+ #: String
27
+ attr_reader :sha256
28
+
29
+ # What the baseline was, as a changed member's "since" says.
30
+ #: Hash[String, String]
31
+ attr_reader :since
32
+
33
+ #: (String, Hash[String, String], walks_history: bool) -> void
34
+ def initialize(sha256, since, walks_history:)
35
+ @sha256 = sha256
36
+ @since = since.freeze #: Hash[String, String]
37
+ @walks_history = walks_history
38
+ freeze
39
+ end
40
+
41
+ # Whether the member's history in git walks back to it.
42
+ #: () -> bool
43
+ def walks_history? = @walks_history
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "member"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # The other maps holding a new whole-file member's file whole too, by its own path or through a link, so a hub
11
+ # file mapped whole into several principles is seen as it is mapped.
12
+ class MapsHoldingFileWhole
13
+ #: (Project, Member) -> void
14
+ def initialize(project, member)
15
+ @project = project
16
+ @member = member
17
+ freeze
18
+ end
19
+
20
+ # The ids of the maps other than except holding the file whole; none when the member is a passage. A map that
21
+ # cannot be read is left out, since list-member-problems reports it.
22
+ #: (except: String) -> Array[String]
23
+ def elsewhere(except:)
24
+ return [] unless @member.whole_file?
25
+
26
+ maps = @project.principles
27
+ (maps.ids - [except]).select { |id| holds_whole?(maps, id) }
28
+ end
29
+
30
+ private
31
+
32
+ #: (MappedPrinciples, String) -> bool
33
+ def holds_whole?(maps, id)
34
+ maps.find(id).members.to_a.any? do |member|
35
+ member.whole_file? && @project.same_file?(member.path, @member.path)
36
+ end
37
+ rescue Error
38
+ false
39
+ end
40
+ end
41
+ end
42
+ end