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,61 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require "tempfile"
6
+ require_relative "ran"
7
+
8
+ module Principles
9
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
10
+ module Data
11
+ # The request files that may hold one of some patterns, found by one rg run over the files as the host wrote them,
12
+ # so only those are decoded. The JSON writers of the hosts it captures, Node's among them, and jq and Ruby's, agree
13
+ # on writing a quote, a backslash and a control character, and differ on a slash, a DEL and a non-ASCII character,
14
+ # each written raw or as an escape, so each pattern is looked for in every one of those forms. A writer escaping
15
+ # < > & as Go's HTML-safe form does is not covered.
16
+ class RawRequestFilter
17
+ # rg's options for listing each file holding a fixed string, one a line, ignore files left unread, since git
18
+ # ignores the folder the requests are in.
19
+ SEARCH = %w[--no-config --no-ignore -F -l].freeze #: Array[String]
20
+ # A character outside ASCII, which a writer may write as itself or as \u escapes, in either case of hex digit.
21
+ NON_ASCII = /[^\x00-\x7f]/
22
+
23
+ # Each of files, in the requests folder, that may hold one of patterns, none of them empty, and whether rg read
24
+ # every file, finding one or none, and wrote no error.
25
+ #: (String, Array[String], Array[String]) -> [Array[String], bool]
26
+ def self.listing(requests, files, patterns)
27
+ Tempfile.create("principles-raw-patterns") do |listed|
28
+ listed.write(patterns.flat_map { written_forms(it) }.uniq.join("\n"))
29
+ listed.flush
30
+ search = ["rg", *SEARCH, "-f", listed.path]
31
+ Tempfile.create("principles-raw-errors") { listed_by(requests, search, files, it) }
32
+ end
33
+ end
34
+
35
+ # Each of files the command lists, run with them in the requests folder, and whether it found one or none and
36
+ # wrote no error to errors.
37
+ #: (String, Array[String], Array[String], File) -> [Array[String], bool]
38
+ def self.listed_by(requests, command, files, errors)
39
+ printed, status = Ran.run([*command, "--", *files], requests, errors.path)
40
+ [files & printed.split("\n"), [0, 1].include?(status) && File.empty?(errors.path)]
41
+ end
42
+
43
+ # Each form a JSON writer may write pattern in inside a string.
44
+ #: (String) -> Array[String]
45
+ def self.written_forms(pattern)
46
+ [JSON.generate(pattern)[1..-2].to_s]
47
+ .flat_map { [it, it.gsub("/", "\\/")] }
48
+ .flat_map { [it, it.gsub("\u007f", "\\u007f")] }
49
+ .flat_map { |form| [form, *%w[%04x %04X].map { |hex| form.gsub(NON_ASCII) { escaped(it, hex) } }] }
50
+ .uniq
51
+ end
52
+
53
+ # character as \u escapes, a surrogate pair beyond the first plane, with hex digits as hex writes them.
54
+ #: (String, String) -> String
55
+ def self.escaped(character, hex)
56
+ character.encode("UTF-16BE").unpack("n*").map { "\\u#{format(hex, it)}" }.join
57
+ end
58
+ private_class_method :listed_by, :written_forms, :escaped
59
+ end
60
+ end
61
+ end
@@ -5,6 +5,8 @@ require_relative "git_command"
5
5
  require_relative "verified_head"
6
6
  require_relative "first_parent_log"
7
7
  require_relative "working_tree_changes"
8
+ require_relative "changes_since"
9
+ require_relative "branches_bringing_in"
8
10
  require_relative "committed_texts"
9
11
 
10
12
  module Principles
@@ -29,6 +31,8 @@ module Principles
29
31
  @texts = CommittedTexts.new(root, ->(name) { show(name) }) #: CommittedTexts
30
32
  @log = FirstParentLog.new(@git) #: FirstParentLog
31
33
  @changes = WorkingTreeChanges.new(@git) #: WorkingTreeChanges
34
+ @since = ChangesSince.new(@git) #: ChangesSince
35
+ @branches = BranchesBringingIn.new(@git) #: BranchesBringingIn
32
36
  end
33
37
 
34
38
  # A strict permission snapshot; legacy best-effort readers keep their existing behavior.
@@ -42,11 +46,16 @@ module Principles
42
46
  ok && output.strip == "true"
43
47
  end
44
48
 
45
- # The user name git commits as here, or nil when none is set.
46
- #: () -> String?
47
- def user_name
48
- name, ok = git(["config", "user.name"])
49
- ok && !name.strip.empty? ? name.strip : nil
49
+ # The project's root at its place in the repository's main checkout, which a worktree shares its history with;
50
+ # in the main checkout, or outside git, the project's own root.
51
+ #: () -> String
52
+ def main_checkout_root
53
+ top, = git(["rev-parse", "--path-format=absolute", "--show-toplevel"])
54
+ common, ok = git(["rev-parse", "--path-format=absolute", "--git-common-dir"])
55
+ return @root unless ok
56
+
57
+ inside = File.realpath(@root).delete_prefix(File.realpath(top.strip))
58
+ File.join(File.realpath(File.dirname(common.strip)), inside)
50
59
  end
51
60
 
52
61
  # The full sha of the last commit that changed path, or nil outside git or when no commit has.
@@ -56,6 +65,14 @@ module Principles
56
65
  ok && !sha.strip.empty? ? sha.strip : nil
57
66
  end
58
67
 
68
+ # The full sha of the newest commit on at's first-parent line that changed any of paths, nil when none did. git
69
+ # stops at the first it finds, so this reads no further back than that commit.
70
+ #: (Array[String], at: String) -> String?
71
+ def last_change(paths, at:)
72
+ sha, ok = git(["log", "-1", "--first-parent", "--format=%H", "--end-of-options", revision(at), "--", *paths])
73
+ ok && !sha.strip.empty? ? sha.strip : nil
74
+ end
75
+
59
76
  # Whether path, relative to the project, is absent from the working tree.
60
77
  #: (String) -> bool
61
78
  def absent?(path)
@@ -65,16 +82,12 @@ module Principles
65
82
  # Each rename git detects between commit and the working tree, as {"from", "to", "similarity"}, with paths
66
83
  # relative to the project; none outside git or when commit is not there, as in a shallow clone.
67
84
  #: (String) -> Array[Hash[String, untyped]]
68
- def renames_since(commit)
69
- output, ok = git(["diff", "-M", "-z", "--name-status", "--relative", "--diff-filter=R", revision(commit), "--"])
70
- return [] unless ok
71
-
72
- output.force_encoding("UTF-8").split("\0").each_slice(3).filter_map do |status, from, to|
73
- next unless status.to_s.start_with?("R") && from && to
85
+ def renames_since(commit) = @since.renames(revision(commit))
74
86
 
75
- { "from" => from, "to" => to, "similarity" => status.to_s.delete_prefix("R").to_i }
76
- end
77
- end
87
+ # Each of paths that a local branch's commits not on HEAD bring in, with the branches that do, as
88
+ # BranchesBringingIn reads them.
89
+ #: (Array[String]) -> Hash[String, Array[String]]
90
+ def branches_bringing_in(paths) = @branches.of(paths)
78
91
 
79
92
  # The full sha at HEAD, or nil outside git or before the first commit.
80
93
  #: () -> String?
@@ -95,10 +108,7 @@ module Principles
95
108
  # deleted, and a rename by both its names, since git is asked to detect none. commit is a full sha, as commit_of
96
109
  # gives it, so git cannot read it as an option.
97
110
  #: (String) -> Array[String]
98
- def changed_since(commit)
99
- output, ok = git(["diff", "--name-only", "-z", "--relative", "--no-renames", revision(commit), "HEAD", "--"])
100
- ok ? output.force_encoding("UTF-8").split("\0").sort : []
101
- end
111
+ def changed_since(commit) = @since.paths(revision(commit))
102
112
 
103
113
  # Which of paths, relative to the project, are untracked or ignored, or differ from HEAD in the index
104
114
  # or the working tree. Before the first commit, every path does.
@@ -109,6 +119,11 @@ module Principles
109
119
  #: (Array[String]) -> Array[String]
110
120
  def untracked_excluding_ignored(paths) = @changes.untracked_excluding_ignored(paths)
111
121
 
122
+ # Whether git ignores path, relative to the project, a folder ending in "/"; false outside git. check-ignore
123
+ # refuses literal pathspecs, and reads each path as a name, never a glob, without them.
124
+ #: (String) -> bool
125
+ def ignores?(path) = git(["--no-literal-pathspecs", "check-ignore", "-q", "--", path]).last
126
+
112
127
  # Which of paths, relative to the project, git does not track, ignored or not.
113
128
  #: (Array[String]) -> Array[String]
114
129
  def untracked_including_ignored(paths) = @changes.untracked_including_ignored(paths)
@@ -138,15 +153,7 @@ module Principles
138
153
  # The commits after commit, up to HEAD, that changed any of paths, newest first, each as its short sha and
139
154
  # subject line.
140
155
  #: (String, Array[String]) -> Array[Hash[String, String]]
141
- def commits_since(commit, paths)
142
- output, ok = git(["log", "--format=%h%x00%s", "--end-of-options", "#{revision(commit)}..HEAD", "--", *paths])
143
- return [] unless ok
144
-
145
- output.force_encoding("UTF-8").lines.map do |line|
146
- sha, subject = line.chomp.split("\0", 2)
147
- { "commit" => sha.to_s, "subject" => subject.to_s }
148
- end
149
- end
156
+ def commits_since(commit, paths) = @since.commits(revision(commit), paths)
150
157
 
151
158
  # Every commit on up_to's first-parent line, HEAD's unless given, that changed any of paths, newest first, each
152
159
  # as its full and short sha, subject line, author date and whether it is a root commit ("true" or "false"); none
@@ -0,0 +1,167 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "principles_directory"
5
+ require_relative "logged_request_scan"
6
+ require "fileutils"
7
+ require "json"
8
+ require "tempfile"
9
+
10
+ module Principles
11
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
12
+ module Data
13
+ # The folder where the host writes each request it sends, with the files this tool writes beside them: the
14
+ # .gitignore that has git ignore the folder, and the launch file that switches the capture. Each name is
15
+ # relative to the folder.
16
+ class RequestLoggingFolder
17
+ NAME = "request-logging"
18
+ FOLDER = "#{PrinciplesDirectory::FOLDER}/#{NAME}".freeze #: String
19
+ IGNORE = ".gitignore"
20
+ SETTINGS = "settings.json"
21
+ REQUESTS = "requests"
22
+ # The host's one line per response it received, naming the request and response files and the session.
23
+ INDEX = "#{REQUESTS}/index.jsonl".freeze #: String
24
+
25
+ # A file the host wrote under requests/: its name there, its size and when it was last written.
26
+ class CapturedFile
27
+ #: String
28
+ attr_reader :name
29
+ #: Integer
30
+ attr_reader :bytes
31
+ #: Time
32
+ attr_reader :modified_at
33
+
34
+ #: (name: String, bytes: Integer, modified_at: Time) -> void
35
+ def initialize(name:, bytes:, modified_at:)
36
+ @name = name
37
+ @bytes = bytes
38
+ @modified_at = modified_at
39
+ freeze
40
+ end
41
+ end
42
+
43
+ # One line of the host's index: the session, when, and the paths of the request and response files it names.
44
+ class IndexLine
45
+ #: String
46
+ attr_reader :session_id, :timestamp, :request_file, :response_file
47
+
48
+ #: (Hash[String, String]) -> void
49
+ def initialize(fields)
50
+ @session_id = fields.fetch("session_id") #: String
51
+ @timestamp = fields.fetch("timestamp") #: String
52
+ @request_file = fields.fetch("request_file") #: String
53
+ @response_file = fields.fetch("response_file") #: String
54
+ freeze
55
+ end
56
+ end
57
+
58
+ #: (String) -> void
59
+ def initialize(root)
60
+ @root = root
61
+ @directory = PrinciplesDirectory.new(root, NAME) #: PrinciplesDirectory
62
+ freeze
63
+ end
64
+
65
+ # name as a path relative to the project.
66
+ #: (String) -> String
67
+ def relative(name) = "#{FOLDER}/#{name}"
68
+
69
+ # name as an absolute path, as a launch file must name the folder the host writes to.
70
+ #: (String) -> String
71
+ def absolute(name) = File.join(@root, FOLDER, name)
72
+
73
+ #: () -> bool
74
+ def exist? = File.directory?(@directory.path)
75
+
76
+ # Every file in the folder, as a name relative to it, sorted.
77
+ #: () -> Array[String]
78
+ def files
79
+ base = @directory.path
80
+ Dir.glob("**/*", File::FNM_DOTMATCH, base: base).select { |name| File.file?(File.join(base, name)) }.sort
81
+ end
82
+
83
+ # Every file the host wrote under requests/, but its index, sorted by name.
84
+ #: () -> Array[CapturedFile]
85
+ def captured_files
86
+ base = File.join(@directory.path, REQUESTS)
87
+ (Dir.exist?(base) ? Dir.children(base).sort : []).filter_map do |name|
88
+ path = File.join(base, name)
89
+ next if name == File.basename(INDEX) || !File.file?(path)
90
+
91
+ stat = File.stat(path)
92
+ CapturedFile.new(name: name, bytes: stat.size, modified_at: stat.mtime.utc)
93
+ end
94
+ end
95
+
96
+ # Each line of the host's index, leaving out a line that is not a JSON object naming a session and its files.
97
+ #: () -> Array[IndexLine]
98
+ def index_lines
99
+ path = File.join(@directory.path, INDEX)
100
+ File.file?(path) ? IndexLines.new(File.read(path)).lines : []
101
+ end
102
+
103
+ # Writes name, creating the folder readable only by its owner, since what it holds is a whole session's context.
104
+ #: (String, String) -> void
105
+ def write(name, text)
106
+ target = File.join(@directory.path, name)
107
+ FileUtils.mkdir_p(File.dirname(target), mode: 0o700)
108
+ Tempfile.create(["request-logging", ".tmp"], File.dirname(target)) do |temporary|
109
+ temporary.write(text)
110
+ temporary.flush
111
+ File.rename(temporary.path, target)
112
+ end
113
+ end
114
+
115
+ # Writes the launch file, its fields as JSON.
116
+ #: (Hash[String, untyped]) -> void
117
+ def write_settings(fields) = write(SETTINGS, "#{JSON.pretty_generate(fields)}\n")
118
+
119
+ #: (String) -> void
120
+ def remove(name) = File.delete(File.join(@directory.path, name))
121
+
122
+ # Removes one file the host wrote directly under requests/, refusing any other name, an index line's included,
123
+ # so a line naming a path elsewhere or the index itself cannot reach it.
124
+ #: (String) -> void
125
+ def remove_request(name)
126
+ unless name.match?(%r{\A[^/]+\z}) && !%w[. ..].include?(name) && name != File.basename(INDEX)
127
+ raise ArgumentError, "not a captured file under #{REQUESTS}/: #{name.inspect}"
128
+ end
129
+
130
+ remove("#{REQUESTS}/#{name}")
131
+ end
132
+
133
+ # The requests the host captured here, scanned by jq and rg.
134
+ #: () -> LoggedRequestScan
135
+ def scan = LoggedRequestScan.new(File.join(@directory.path, REQUESTS))
136
+
137
+ # Removes the folder when nothing is left in it.
138
+ #: () -> void
139
+ def remove_if_empty
140
+ Dir.rmdir(@directory.path) if exist? && Dir.empty?(@directory.path)
141
+ end
142
+ end
143
+
144
+ # The host's index text read as lines, shared by the folder and its stand-in.
145
+ class IndexLines
146
+ FIELDS = %w[session_id timestamp request_file response_file].freeze #: Array[String]
147
+
148
+ #: (String) -> void
149
+ def initialize(text)
150
+ @text = text
151
+ freeze
152
+ end
153
+
154
+ #: () -> Array[RequestLoggingFolder::IndexLine]
155
+ def lines
156
+ @text.each_line.filter_map do |line|
157
+ fields = JSON.parse(line)
158
+ next unless fields.is_a?(Hash) && FIELDS.all? { |field| fields[field].is_a?(String) }
159
+
160
+ RequestLoggingFolder::IndexLine.new(fields)
161
+ rescue JSON::ParserError
162
+ nil
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -12,7 +12,7 @@ module Principles
12
12
  class RunningVersion
13
13
  # git archive writes the short sha of the commit it archives here, since .gitattributes marks this file
14
14
  # export-subst; a checkout keeps the placeholder as written.
15
- ARCHIVED_COMMIT = "f91461e6" #: String
15
+ ARCHIVED_COMMIT = "e3a7f9f7" #: String
16
16
 
17
17
  #: (?String, release: String, ?built: String?, ?archived_commit: String) -> void
18
18
  def initialize(checkout = File.expand_path("../../..", __dir__), release:, built: nil,
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "acknowledgement-answer.schema.json",
4
4
  "title": "Acknowledgement answer",
5
- "description": "What an agent answers a one-member audit with: the request id and basis, and under members one entry keyed by the member id, as an answer for several members holds it, saying whether the change keeps the member's meaning, a one-line reason, and a line quoted from the member's text before the change and one from after it, or \"\" for a side with no line the other lacks; a quote left out, as is the basis's base_commit, which the request id already pins, is read as the request's first_changed_lines printed it. Fields this tool does not read are refused. Models::Acknowledgement checks the quotes and the reason.",
5
+ "description": "What an agent answers a one-member audit with: the request id and basis, and under members one entry keyed by the member id, as an answer for several members holds it, saying whether the change keeps the member's meaning, a one-line reason, and a line quoted from the member's text before the change and one from after it, or \"\" for a side with no line the other lacks; a quote left out, as is the basis's base_commit, which the request id already pins, is read as the request's first_changed_lines printed it. Fields this tool does not read are refused, but for answer_with and each entry's role, which the template printed alone carries for the agent to read and which are read as nothing. Models::Acknowledgement checks the quotes and the reason.",
6
6
  "type": "object",
7
7
  "additionalProperties": false,
8
8
  "required": [
@@ -14,6 +14,10 @@
14
14
  "request_id": {
15
15
  "type": "string"
16
16
  },
17
+ "answer_with": {
18
+ "type": "string",
19
+ "description": "The command that submits this answer from the file it is saved in, as the template printed alone carries it. Sent back, it is read as nothing."
20
+ },
17
21
  "basis": {
18
22
  "type": "object",
19
23
  "additionalProperties": false,
@@ -49,6 +53,17 @@
49
53
  "reason"
50
54
  ],
51
55
  "properties": {
56
+ "roles": {
57
+ "type": "object",
58
+ "additionalProperties": {
59
+ "type": "string"
60
+ },
61
+ "description": "The member's role by each principle that maps it, which the template printed alone across principles carries beside meaning_kept for the agent judging it. Sent back, it is read as nothing."
62
+ },
63
+ "role": {
64
+ "type": "string",
65
+ "description": "The member's role as its map names it, which the template printed alone carries beside meaning_kept for the agent judging it. Sent back, it is read as nothing."
66
+ },
52
67
  "meaning_kept": {
53
68
  "type": "boolean"
54
69
  },
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "acknowledgements-answer.schema.json",
4
4
  "title": "Acknowledgements answer",
5
- "description": "What an agent answers a request to acknowledge several members of one principle, or the members several principles map, holding: the request's id, its basis naming each member, and under members one entry per member, keyed by its id, holding what a one-member answer holds beside its head. Fields this tool does not read are refused. Models::Acknowledgements refuses an answer whose members differ from its basis, and each entry is checked as Models::Acknowledgement checks a one-member answer.",
5
+ "description": "What an agent answers a request to acknowledge several members of one principle, or the members several principles map, holding: the request's id, its basis naming each member, and under members one entry per member, keyed by its id, holding what a one-member answer holds beside its head. Fields this tool does not read are refused, but for answer_with and each entry's role, or roles across principles, which the template printed alone carries for the agent to read and which are read as nothing. Models::Acknowledgements refuses an answer whose members differ from its basis, and each entry is checked as Models::Acknowledgement checks a one-member answer.",
6
6
  "type": "object",
7
7
  "additionalProperties": false,
8
8
  "required": [
@@ -14,6 +14,10 @@
14
14
  "request_id": {
15
15
  "type": "string"
16
16
  },
17
+ "answer_with": {
18
+ "type": "string",
19
+ "description": "The command that submits this answer from the file it is saved in, as the template printed alone carries it. Sent back, it is read as nothing."
20
+ },
17
21
  "basis": {
18
22
  "type": "object",
19
23
  "additionalProperties": false,
@@ -47,6 +51,17 @@
47
51
  "reason"
48
52
  ],
49
53
  "properties": {
54
+ "roles": {
55
+ "type": "object",
56
+ "additionalProperties": {
57
+ "type": "string"
58
+ },
59
+ "description": "The member's role by each principle that maps it, which the template printed alone across principles carries beside meaning_kept for the agent judging it. Sent back, it is read as nothing."
60
+ },
61
+ "role": {
62
+ "type": "string",
63
+ "description": "The member's role as its map names it, which the template printed alone carries beside meaning_kept for the agent judging it. Sent back, it is read as nothing."
64
+ },
50
65
  "meaning_kept": {
51
66
  "type": "boolean"
52
67
  },
@@ -57,6 +57,10 @@
57
57
  "carried_forward": {
58
58
  "const": true
59
59
  },
60
+ "judge_because": {
61
+ "type": "string",
62
+ "description": "Why the request judges this member afresh, as its template prints it; sent back or not, Models::MemberAssessments keeps nothing from it."
63
+ },
60
64
  "assessment": {
61
65
  "type": "string"
62
66
  },
@@ -232,6 +236,10 @@
232
236
  "required": ["finding_id", "decision"],
233
237
  "properties": {
234
238
  "finding_id": { "type": "string" },
239
+ "finding_problem": {
240
+ "type": "string",
241
+ "description": "The finding's problem as the template prints it beside its decision, for the agent deciding it to read. Sent back, it is read as nothing; problem restates the finding."
242
+ },
235
243
  "decision": { "type": ["string", "null"] },
236
244
  "reason": { "type": "string" },
237
245
  "as": { "type": "string" },
@@ -72,7 +72,7 @@
72
72
  "usage": { "$ref": "#/$defs/prose" },
73
73
  "group": { "$ref": "#/$defs/slug" },
74
74
  "options": { "type": "array", "uniqueItems": true,
75
- "items": { "enum": ["description", "path", "section", "starting-at", "ending-at", "query", "role", "check", "file", "short", "session-start", "commits-after", "hook-event", "member", "when-files", "when-invoked", "always", "write-ups", "as", "instruction", "part", "also", "only", "confirm", "lines", "open-findings", "history"] } },
75
+ "items": { "enum": ["description", "path", "section", "starting-at", "ending-at", "query", "plugin", "role", "check", "file", "short", "session-start", "commits-after", "hook-event", "member", "when-files", "when-invoked", "always", "write-ups", "as", "instruction", "part", "also", "only", "confirm", "lines", "open-findings", "history", "loads", "keep-sessions", "findings", "places"] } },
76
76
  "requires": { "type": "array", "uniqueItems": true, "items": { "enum": ["file"] } },
77
77
  "summary": { "$ref": "#/$defs/prose" },
78
78
  "help": { "type": "string", "pattern": "^[a-z]+(-[a-z]+)+/[a-z]+(-[a-z]+)+$" },
@@ -14,12 +14,13 @@
14
14
  "properties": {
15
15
  "fixed": {
16
16
  "type": "object",
17
- "required": ["action", "reason", "changed_members", "removed_members", "evidence", "reassessment", "recorded_at"],
17
+ "required": ["action", "reason", "changed_members", "changed_map_entries", "removed_members", "evidence", "reassessment", "recorded_at"],
18
18
  "additionalProperties": false,
19
19
  "properties": {
20
20
  "action": { "const": "fixed" },
21
21
  "reason": { "type": "string", "minLength": 1 },
22
22
  "changed_members": { "type": "array", "items": { "type": "string" } },
23
+ "changed_map_entries": { "type": "array", "items": { "type": "string" } },
23
24
  "removed_members": { "type": "array", "items": { "type": "string" } },
24
25
  "evidence": { "type": "array", "items": { "type": "object" } },
25
26
  "reassessment": { "type": "string", "minLength": 1 },
@@ -241,6 +241,20 @@
241
241
  "waits_on": {
242
242
  "type": ["string", "null"],
243
243
  "description": "On a deferral, one line saying whom it waits on and to decide what; null on any disposition. Models::CorrectionAnswer refuses a value on another action, or one not one line."
244
+ },
245
+ "unfixed_part": {
246
+ "type": "object",
247
+ "additionalProperties": false,
248
+ "required": ["id", "problem", "action", "reason"],
249
+ "description": "On a fix that settles only part of its finding, the part left unfixed, raised as a new finding of the finding's members under its own id, deferred or accepted as a disposition is. Models::Disposition refuses it on any other action.",
250
+ "properties": {
251
+ "id": { "type": "string" },
252
+ "problem": { "type": "string" },
253
+ "action": { "type": ["string", "null"] },
254
+ "reason": { "type": "string" },
255
+ "recorded_at": {"x-type-refusal-advice":{"keys":["path","url","heading","starting_at","ending_at","query"],"says":"with path, plus starting_at (or heading) when the file holds more than this finding, or with url alone, a whole https link, for a write-up outside the project such as an issue"},"type":["object","null"],"additionalProperties":false,"properties":{"path":{"type":"string"},"url":{"type":"string"},"heading":{"type":"string"},"starting_at":{"type":"string"},"ending_at":{"type":"string"},"query":{"type":"string"}}},
256
+ "waits_on": {"type":["string","null"]}
257
+ }
244
258
  }
245
259
  }
246
260
  }
@@ -31,7 +31,16 @@
31
31
  "ending_at": { "type": "string", "minLength": 1 },
32
32
  "role": { "type": "string", "minLength": 1 },
33
33
  "key": { "type": "string", "minLength": 1, "description": "What the member is known by across moves, which its audit record files its hash under. Absent, it is the member's id. move-member stores the old id here on a member's first move, and add-member gives a member a key of its own when its id is the key of a member that moved away." },
34
- "check": { "type": "string", "minLength": 1, "description": "The command that enforces this member, which an audit asks the agent to run and report. This tool never runs it." }
34
+ "check": { "type": "string", "minLength": 1, "description": "The command that enforces this member, which an audit asks the agent to run and report. This tool never runs it." },
35
+ "pinned": {
36
+ "type": "object",
37
+ "description": "For a member read from an installed plugin: the version the host had installed when it was mapped, and the SHA-256 of the member's text then. Only the hash says whether the text changed; the version is shown for information.",
38
+ "required": ["version", "sha256"],
39
+ "properties": {
40
+ "version": { "type": "string", "minLength": 1 },
41
+ "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
42
+ }
43
+ }
35
44
  }
36
45
  }
37
46
  }
@@ -0,0 +1,39 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "tempfile"
5
+ require_relative "ran"
6
+
7
+ module Principles
8
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
9
+ module Data
10
+ # How many strings each of some request files holds, counted by one jq run without decoding them, for the requests
11
+ # the raw filter leaves undecoded, so the scan still says how much it read.
12
+ module StringCounts
13
+ # Each request with its count, as request<TAB>count.
14
+ COUNT = '"\(input_filename | split("/") | last)\t\([.. | strings] | length)"'
15
+
16
+ # Each of files, in the requests folder, with its count of strings, and whether jq read every file through and
17
+ # wrote no error, whose words are never kept, since they can quote a value from a request.
18
+ #: (String, Array[String]) -> [Hash[String, Integer], bool]
19
+ def self.of(requests, files)
20
+ return [{}, true] if files.empty?
21
+
22
+ Tempfile.create("principles-count-errors") do |errors|
23
+ printed, status = Ran.run(["jq", "-r", COUNT, *files], requests, errors.path)
24
+ [counted(printed), [0].include?(status) && File.empty?(errors.path)]
25
+ end
26
+ end
27
+
28
+ # Each request jq printed, with its count.
29
+ #: (String) -> Hash[String, Integer]
30
+ def self.counted(printed)
31
+ printed.split("\n").to_h do |line|
32
+ request, count = line.split("\t", 2)
33
+ [request.to_s, Integer(count)]
34
+ end
35
+ end
36
+ private_class_method :counted
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
6
+ module Data
7
+ # The fast standard tools PATH holds, such as jq and rg, which a bulk scan runs in place of Ruby: a tool is on
8
+ # PATH when a folder on it holds an executable file of that name.
9
+ class ToolsOnPath
10
+ #: (String) -> void
11
+ def initialize(path)
12
+ @folders = path.split(File::PATH_SEPARATOR).reject(&:empty?) #: Array[String]
13
+ freeze
14
+ end
15
+
16
+ #: (String) -> bool
17
+ def include?(tool)
18
+ @folders.any? do |folder|
19
+ found = File.join(folder, tool)
20
+ File.file?(found) && File.executable?(found)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -9,9 +9,11 @@ module Principles
9
9
  class InvocationOptions
10
10
  # The options that take a value; --help, -h and --version take none.
11
11
  VALUE_OPTIONS = %w[project file description path section starting-at ending-at query role
12
- check session-start commits-after hook-event as instruction].freeze #: Array[String]
12
+ check plugin session-start commits-after hook-event as instruction
13
+ keep-sessions].freeze #: Array[String]
13
14
  # The options that take no value, as list-member-problems --short.
14
- FLAG_OPTIONS = %w[short lines when-invoked always write-ups confirm open-findings history].freeze #: Array[String]
15
+ FLAG_OPTIONS = %w[short lines when-invoked always write-ups confirm open-findings history
16
+ loads findings places].freeze #: Array[String]
15
17
  # The options that may be given more than once, each value kept in order, as change-activation --when-files and
16
18
  # start-audit --member and --part.
17
19
  LIST_OPTIONS = %w[when-files also only member part].freeze #: Array[String]
@@ -5,6 +5,7 @@ require "tmpdir"
5
5
  require_relative "version"
6
6
  require_relative "data/running_version"
7
7
  require_relative "data/principles_on_path"
8
+ require_relative "data/tools_on_path"
8
9
  require_relative "controllers/running_tool"
9
10
 
10
11
  module Principles
@@ -22,15 +23,21 @@ module Principles
22
23
  # each read only when a command needs it.
23
24
  #: () -> Controllers::RunningTool
24
25
  def running_tool
25
- Controllers::RunningTool.new(executable: @executable, version: -> { running_version },
26
- other_on_path: ->(asking) { on_path.other(asking) },
27
- launched_on_path: -> { on_path.own_first? },
26
+ Controllers::RunningTool.new(executable: @executable, version: -> { running_version }, on_path: path_says,
28
27
  folders: Controllers::RunningTool::Folders.new(cwd: started_in,
29
28
  temp_directory: Dir.tmpdir))
30
29
  end
31
30
 
32
31
  private
33
32
 
33
+ # What PATH says of this run, each fact read only when a command asks for it.
34
+ #: () -> Controllers::RunningTool::OnPath
35
+ def path_says
36
+ Controllers::RunningTool::OnPath.new(other: ->(asking) { on_path.other(asking) },
37
+ launched: -> { on_path.own_first? },
38
+ tool: ->(tool) { Data::ToolsOnPath.new(path).include?(tool) })
39
+ end
40
+
34
41
  # The folder this run was started in, by its real path, as a project's root is given, or nil when it is gone.
35
42
  #: () -> String?
36
43
  def started_in
@@ -42,7 +49,10 @@ module Principles
42
49
  # The principles on PATH, against this run's own file: the plugin's bin or a RubyGems binstub when either
43
50
  # launched it, else this tool's executable.
44
51
  #: () -> Data::PrinciplesOnPath
45
- def on_path = Data::PrinciplesOnPath.new(ENV.fetch("PATH", ""), own: File.expand_path($PROGRAM_NAME))
52
+ def on_path = Data::PrinciplesOnPath.new(path, own: File.expand_path($PROGRAM_NAME))
53
+
54
+ #: () -> String
55
+ def path = ENV.fetch("PATH", "")
46
56
 
47
57
  # The version of this tool that is running, as a build stamped it or a checkout's commit gives it.
48
58
  #: () -> String