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,52 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../views/request_logging_result"
6
+
7
+ module Principles
8
+ # Each runs one command: reads models, applies their rules and prints through a view.
9
+ # controllers/CLAUDE.md owns the boundary.
10
+ module Controllers
11
+ # The switch for request logging, each request the host sends written under .principles/request-logging/,
12
+ # and the read of what was captured there.
13
+ class RequestLogging < Command
14
+ # Each command, by the private method that runs it.
15
+ COMMANDS = { "turn-on-request-logging" => :turned_on,
16
+ "turn-off-request-logging" => :turned_off,
17
+ "show-logged-requests" => :shown,
18
+ "remove-logged-requests" => :removed }.freeze #: Hash[String, Symbol]
19
+
20
+ #: (String, String?, Hash[String, untyped]) -> untyped
21
+ def call(command, _id, options)
22
+ naming_the_executable do
23
+ operation = COMMANDS[command] or unknown(command)
24
+ send(operation, @project.request_logging, Views::RequestLoggingResult.new(invocation), options)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ #: (Models::RequestLogging, Views::RequestLoggingResult, Hash[String, untyped]) -> Hash[String, untyped]
31
+ def turned_on(logging, result, _options)
32
+ result.turned_on(wrote: logging.turn_on, launch_file: logging.launch_file)
33
+ end
34
+
35
+ #: (Models::RequestLogging, Views::RequestLoggingResult, Hash[String, untyped]) -> Hash[String, untyped]
36
+ def turned_off(logging, result, _options) = result.turned_off(wrote: logging.turn_off)
37
+
38
+ #: (Models::RequestLogging, Views::RequestLoggingResult, Hash[String, untyped]) -> Hash[String, untyped]
39
+ def shown(logging, result, _options)
40
+ captured = logging.captured
41
+ result.shown(sessions: captured.sessions.map(&:to_h), orphan_requests: captured.orphans.to_h,
42
+ newest_request_written_at: captured.newest_request_written_at,
43
+ newest_session_id: captured.newest_session_id)
44
+ end
45
+
46
+ #: (Models::RequestLogging, Views::RequestLoggingResult, Hash[String, untyped]) -> Hash[String, untyped]
47
+ def removed(logging, result, options)
48
+ result.removed(removed: logging.remove(keep_sessions: options["keep_sessions"]))
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../models/feature"
4
5
  require_relative "../models/meta_principle"
5
6
  require_relative "../models/principles_package"
6
7
  require_relative "../models/principles_on_path"
@@ -35,20 +36,41 @@ module Principles
35
36
  end
36
37
  end
37
38
 
39
+ # What PATH says of this run, as Launch reads it, each read only when a command needs it: other gives the path
40
+ # and printed version of another principles earlier on PATH than this one, and which of the commands it is
41
+ # asked about that copy does not run, or nil, since reading it starts that copy; launched says whether this run
42
+ # was launched as the first principles on PATH, as a RubyGems binstub is, so a bare principles runs this same
43
+ # copy; tool says whether PATH holds a fast standard tool, such as rg, which a feature runs. Nothing is on PATH
44
+ # unless Launch says so, so a feature that needs a tool is off by default.
45
+ class OnPath
46
+ #: (?other: ^(Array[String]) -> [String, String, Array[String]]?, ?launched: ^() -> bool,
47
+ #| ?tool: ^(String) -> bool) -> void
48
+ def initialize(other: ->(_) {}, launched: -> { false }, tool: ->(_) { false })
49
+ @other = other
50
+ @launched = launched
51
+ @tool = tool
52
+ freeze
53
+ end
54
+
55
+ # The feature command runs, on only while PATH holds every fast standard tool it needs.
56
+ #: (String) -> Models::Feature
57
+ def feature(command) = Models::Feature.new(command, on_path: @tool)
58
+
59
+ # Another principles earlier on PATH, asked about the commands of asking, or nil.
60
+ #: (Array[String]) -> [String, String, Array[String]]?
61
+ def other(asking) = @other.call(asking)
62
+
63
+ #: () -> bool
64
+ def launched? = @launched.call
65
+ end
66
+
38
67
  # version gives the version running, read only when a command needs it, since in a checkout reading it
39
- # asks git; other_on_path gives the path and printed version of another principles earlier on PATH than this
40
- # one, and which of the commands it is asked about that copy does not run, or nil, read only when a command
41
- # needs it, since reading it starts that copy; launched_on_path says
42
- # whether this run was launched as the first principles on PATH, as a RubyGems binstub is, so a bare
43
- # principles runs this same copy; folders are the folders the process was given.
44
- #: (executable: String, version: ^() -> String,
45
- #| ?other_on_path: ^(Array[String]) -> [String, String, Array[String]]?, ?launched_on_path: ^() -> bool,
46
- #| folders: Folders) -> void
47
- def initialize(executable:, version:, folders:, other_on_path: ->(_) {}, launched_on_path: -> { false })
68
+ # asks git; on_path is what PATH says of this run; folders are the folders the process was given.
69
+ #: (executable: String, version: ^() -> String, folders: Folders, ?on_path: OnPath) -> void
70
+ def initialize(executable:, version:, folders:, on_path: OnPath.new)
48
71
  @executable = executable
49
72
  @version = version
50
- @other_on_path = other_on_path
51
- @launched_on_path = launched_on_path
73
+ @on_path = on_path
52
74
  @folders = folders
53
75
  freeze
54
76
  end
@@ -63,7 +85,7 @@ module Principles
63
85
 
64
86
  # Whether this run was launched as the first principles on PATH, so a bare principles runs this same copy.
65
87
  #: () -> bool
66
- def launched_on_path? = @launched_on_path.call
88
+ def launched_on_path? = @on_path.launched?
67
89
 
68
90
  # Where this run comes from, by the entry point it was invoked through, whatever its commands are printed as.
69
91
  #: () -> Models::RunsFrom
@@ -72,10 +94,12 @@ module Principles
72
94
  # The executable and project that this run's printed commands name, for the project at root. A command line run
73
95
  # printed as the bare principles, from root itself, leaves out --project, since a command copied from its
74
96
  # output runs there too; any other run names the project, as the plugin's hooks and a checkout's commands may
75
- # be run from elsewhere.
76
- #: (String) -> Views::Invocation
77
- def invocation(root)
78
- Views::Invocation.new(executable: executable, project: root, temp_directory: @folders.temp_directory,
97
+ # be run from elsewhere. answer_folder is the project's own folder for a printed answer, when it has one, which
98
+ # every answer file is saved in rather than the temporary folder.
99
+ #: (String, ?answer_folder: String?) -> Views::Invocation
100
+ def invocation(root, answer_folder: nil)
101
+ Views::Invocation.new(executable: executable, project: root,
102
+ temp_directory: answer_folder || @folders.temp_directory,
79
103
  named: !bare_from_path? || root != @folders.cwd)
80
104
  end
81
105
 
@@ -83,10 +107,14 @@ module Principles
83
107
  # whether it runs each command of asking, or nil.
84
108
  #: (?asking: Array[String]) -> Models::PrinciplesOnPath?
85
109
  def other_on_path(asking: [])
86
- path, version, lacking = @other_on_path.call(asking)
110
+ path, version, lacking = @on_path.other(asking)
87
111
  path && version ? Models::PrinciplesOnPath.new(path, version, lacking: lacking || []) : nil
88
112
  end
89
113
 
114
+ # The feature command runs, on only while PATH holds every fast standard tool it needs.
115
+ #: (String) -> Models::Feature
116
+ def feature(command) = @on_path.feature(command)
117
+
90
118
  # The release of principles this run comes from, as the audit of map's principle keeps it: the version running
91
119
  # and the passage as setup prints it, which only a view holds; nil for a principle whose audit keeps none.
92
120
  #: (Models::Principle) -> Models::PrinciplesPackage?
@@ -0,0 +1,52 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "git_command"
5
+
6
+ module Principles
7
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
8
+ module Data
9
+ # Which local branches would bring paths into the project if they merged, as git reports it for Repository: each
10
+ # path that a branch's commits not on HEAD add or change, and do not then delete, with paths relative to the
11
+ # project. One git log reads only those commits, limited to the paths, so a project with many branches pays only
12
+ # for commits no merge has brought in yet. git names each commit by one branch that reaches it, so of branches
13
+ # sharing the commit that brings a path in, one is named.
14
+ class BranchesBringingIn
15
+ # What starts each commit's record in the log: the branch git reached it by.
16
+ RECORD = "\x01"
17
+
18
+ #: (GitCommand) -> void
19
+ def initialize(git)
20
+ @git = git
21
+ freeze
22
+ end
23
+
24
+ # Each of paths a branch brings in, with the branches that do, sorted; none outside git, or for no paths.
25
+ #: (Array[String]) -> Hash[String, Array[String]]
26
+ def of(paths)
27
+ return {} if paths.empty?
28
+
29
+ output, ok = @git.run(["log", "--branches", "--not", "HEAD", "--source", "--no-renames", "--name-status",
30
+ "--relative", "-z", "--format=%x01%S", "--", *paths])
31
+ return {} unless ok
32
+
33
+ newest(output.force_encoding("UTF-8")).reject { |_, status| status == "D" }.keys
34
+ .group_by(&:last).transform_values { it.map(&:first).sort }
35
+ end
36
+
37
+ private
38
+
39
+ # Each branch and path the log names, with the status of the newest commit of that branch to change the path:
40
+ # the log lists commits newest first, each its branch, then each status and path.
41
+ #: (String) -> Hash[[String, String], String]
42
+ def newest(log)
43
+ found = {} #: Hash[[String, String], String]
44
+ log.split(RECORD).drop(1).each do |record|
45
+ branch, *fields = record.split("\0")
46
+ fields.each_slice(2) { |status, path| found[[branch.to_s, path.to_s]] ||= status.to_s.strip }
47
+ end
48
+ found
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "git_command"
5
+
6
+ module Principles
7
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
8
+ module Data
9
+ # What changed in the project after a commit, as git reports it for Repository, with paths relative to the
10
+ # project: the paths the commits up to HEAD changed, the commits that changed some paths, and the renames git
11
+ # detects up to the working tree. Each commit is a revision Repository has checked, so git cannot read it as an
12
+ # option.
13
+ class ChangesSince
14
+ #: (GitCommand) -> void
15
+ def initialize(git)
16
+ @git = git
17
+ freeze
18
+ end
19
+
20
+ # Each rename git detects between commit and the working tree, as {"from", "to", "similarity"}; none outside
21
+ # git or when commit is not there, as in a shallow clone.
22
+ #: (String) -> Array[Hash[String, untyped]]
23
+ def renames(commit)
24
+ output, ok = @git.run(["diff", "-M", "-z", "--name-status", "--relative", "--diff-filter=R", commit, "--"])
25
+ return [] unless ok
26
+
27
+ output.force_encoding("UTF-8").split("\0").each_slice(3).filter_map do |status, from, to|
28
+ next unless status.to_s.start_with?("R") && from && to
29
+
30
+ { "from" => from, "to" => to, "similarity" => status.to_s.delete_prefix("R").to_i }
31
+ end
32
+ end
33
+
34
+ # Each path the commits after commit changed, up to HEAD, sorted: added, edited or deleted, and a rename by both
35
+ # its names, since git is asked to detect none.
36
+ #: (String) -> Array[String]
37
+ def paths(commit)
38
+ output, ok = @git.run(["diff", "--name-only", "-z", "--relative", "--no-renames", commit, "HEAD", "--"])
39
+ ok ? output.force_encoding("UTF-8").split("\0").sort : []
40
+ end
41
+
42
+ # The commits after commit, up to HEAD, that changed any of paths, newest first, each as its short sha and
43
+ # subject line.
44
+ #: (String, Array[String]) -> Array[Hash[String, String]]
45
+ def commits(commit, paths)
46
+ output, ok = @git.run(["log", "--format=%h%x00%s", "--end-of-options", "#{commit}..HEAD", "--", *paths])
47
+ return [] unless ok
48
+
49
+ output.force_encoding("UTF-8").lines.map do |line|
50
+ sha, subject = line.chomp.split("\0", 2)
51
+ { "commit" => sha.to_s, "subject" => subject.to_s }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,58 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "bounded_file"
5
+ require_relative "plugin_registry"
6
+ require_relative "known_marketplaces"
7
+ require_relative "plugin_folder"
8
+
9
+ module Principles
10
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
11
+ module Data
12
+ # Claude Code's config folder on this machine, where it records the plugins it installed. This tool only reads it,
13
+ # and never runs, installs or fetches a plugin.
14
+ class ClaudeCodeHome
15
+ # The folder Claude Code reads: CLAUDE_CONFIG_DIR when set, or else .claude in the home directory.
16
+ #: (?Hash[String, String], ?home: String) -> ClaudeCodeHome
17
+ def self.from_environment(environment = ENV.to_h, home: Dir.home)
18
+ new(environment["CLAUDE_CONFIG_DIR"] || File.join(home, ".claude"))
19
+ end
20
+
21
+ #: String
22
+ attr_reader :directory
23
+
24
+ #: (String) -> void
25
+ def initialize(directory)
26
+ @directory = directory
27
+ freeze
28
+ end
29
+
30
+ # The registry of installed plugins, or nil while the host has installed none.
31
+ #: () -> PluginRegistry?
32
+ def registry
33
+ text = read("installed_plugins.json", "Claude Code's plugin registry")
34
+ PluginRegistry.new(text) if text
35
+ end
36
+
37
+ # The marketplaces the host knows, or nil while it records none.
38
+ #: () -> KnownMarketplaces?
39
+ def marketplaces
40
+ text = read("known_marketplaces.json", "Claude Code's record of its plugin marketplaces")
41
+ KnownMarketplaces.new(text) if text
42
+ end
43
+
44
+ # The folder the host installed a plugin's copy in, at the path its registry gives.
45
+ #: (String) -> PluginFolder
46
+ def plugin_folder(path) = PluginFolder.new(path)
47
+
48
+ private
49
+
50
+ # The text of a file in the host's plugins folder, or nil when it is absent.
51
+ #: (String, String) -> String?
52
+ def read(name, named)
53
+ path = File.join(@directory, "plugins", name)
54
+ BoundedFile.new(path, named: named).read_text if File.exist?(path)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -8,6 +8,8 @@
8
8
  "writes": "Removes only `.principles/maps/ID.json`, listed under `removed`; `wrote` is empty. Commit the removal if the map was tracked. Retains member files and audit entries." },
9
9
  { "id": "write-guidance-search-paths", "heading": "Write the recorded guidance search paths, which the project commits",
10
10
  "writes": "Writes `.principles/guidance-search-paths.json`; commit it as it changes. Never a map, audit or guidance file." },
11
+ { "id": "write-request-logging", "heading": "Switch request logging; these write only inside `.principles/request-logging/`, which git ignores",
12
+ "writes": "Writes only inside `.principles/request-logging/`, listed under `wrote`, and refuses unless git confirms it ignores that folder. Never commit it: a logged request holds a session's whole context." },
11
13
  { "id": "write-audit-record", "heading": "Audit; these write only the audit record, `.principles/audits/ID.json`, which the project commits",
12
14
  "writes": "Writes `.principles/audits/ID.json`, listed under `wrote` when it does; commit it. Never the map or a member's file." }
13
15
  ],
@@ -16,9 +18,10 @@
16
18
  "read-map": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unknown_principle", "unparseable_map", "invalid_map", "newer_format", "duplicate_member"],
17
19
  "read-audit": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unparseable_audit", "invalid_audit_record"],
18
20
  "rewrite-audit": ["newer_audit_record"],
21
+ "read-plugin-registry": ["unreadable_plugin_registry", "unsupported_plugin_registry"],
19
22
  "locate-text": ["outside_project", "not_a_file", "unreadable_file", "renamed_in_case", "invalid_encoding", "section_needs_markdown", "query_needs_frontmatter", "query_with_other_locators", "unsupported_query", "unsupported_frontmatter", "duplicate_frontmatter_key", "field_not_found", "section_not_found",
20
23
  "ambiguous_heading", "passage_not_found", "ambiguous_passage", "passage_end_not_found",
21
- "broken_members"]
24
+ "broken_members", "plugin_members_unresolved"]
22
25
  },
23
26
  "commands": [
24
27
  {
@@ -84,7 +87,8 @@
84
87
  ]
85
88
  },
86
89
  {
87
- "name": "show-principle", "usage": "show-principle ID", "group": "read", "options": [],
90
+ "name": "show-principle", "usage": "show-principle ID [--loads] [--member MEMBER_ID]", "group": "read",
91
+ "options": ["loads", "member"],
88
92
  "summary": "Each member, where it is and whether it changed.",
89
93
  "help": "learn-what-a-command-does/show-principle",
90
94
  "steps": [
@@ -94,12 +98,12 @@
94
98
  ]
95
99
  },
96
100
  {
97
- "name": "show-audit", "usage": "show-audit ID", "group": "read", "options": [],
101
+ "name": "show-audit", "usage": "show-audit ID [--findings]", "group": "read", "options": ["findings"],
98
102
  "summary": "The record of a principle's last audit.",
99
103
  "help": "learn-what-a-command-does/show-audit",
100
104
  "steps": [
101
105
  { "id": "show-record", "actor": "cli",
102
- "does": "Prints the audit record: its status, base commit, each member's hash and each finding's members and disposition.",
106
+ "does": "Prints the audit record: its status, base commit, each member's hash and each finding's members and disposition; with --findings, its findings alone.",
103
107
  "refuses": ["unknown_principle", "unknown_audit"], "refuses_like": ["read-audit"] }
104
108
  ]
105
109
  },
@@ -109,7 +113,7 @@
109
113
  "help": "learn-what-a-command-does/list-open-findings",
110
114
  "steps": [
111
115
  { "id": "read-open-findings", "actor": "cli",
112
- "does": "Reads the last audit record of principle ID, or of every principle, and lists each deferred or accepted finding with its action, its members, its recorded_at pointer and when the audit was made. Says that an earlier audit's open findings are only in git. With --lines, prints each open finding on a line with its principle, id and waits_on. With --short, prints one line saying how many deferred findings wait on someone named or no one, whom the oldest waits on and git's user.name, and to raise each that waits on the user in the first reply, and nothing when none is open; --session-start clear or compact asks for the next reply, and resume shortens it to the facts, since a resumed conversation holds the whole line already.",
116
+ "does": "Reads the last audit record of principle ID, or of every principle, and lists each deferred or accepted finding with its action, its members, its recorded_at pointer and when the audit was made. Says that an earlier audit's open findings are only in git. With --lines, prints each open finding on a line with its principle, id and waits_on. With --short, prints one line saying first to act on each deferred finding that waits on the agent and to raise in the first reply each that waits on a person or on no one, then how many wait on someone named or no one and how long the oldest has, and nothing when none is open; --session-start clear or compact asks for the next reply, and resume shortens it to the facts, since a resumed conversation holds the whole line already.",
113
117
  "refuses_like": ["read-map", "read-audit"] },
114
118
  { "id": "follow-up-each-finding", "actor": "agent",
115
119
  "does": "Read each finding where its recorded_at points, and decide each one at its principle's next full audit.",
@@ -132,7 +136,7 @@
132
136
  "help": "learn-what-a-command-does/report-at-session-start",
133
137
  "steps": [
134
138
  { "id": "report-at-session-start", "actor": "cli",
135
- "does": "Reads the SessionStart hook's JSON on stdin and always exits 0, since the host adds a SessionStart hook's output to the context only then. Prints nothing in a project with no maps. Otherwise prints, each line marked principles:, for one principle whose members an audit assessed changed since, a line with its count, that its audit no longer covers them, and the list-member-problems ID command to run before the user's task, which offers acknowledging them or auditing again, or for several, one line counting them with the list-member-problems --short command that lists them, then, in git, what gives each principle's members with no baseline one, then each principle whose audit record a later release wrote, whose audits wait on an upgrade, then, while any principle awaits its first full audit, one line counting them that asks for one background subagent to follow show-first-audit-brief, or to offer the audit at the next pause if none can be started, and at resume and compact only the count, asking for no second subagent, then, while any audit finding is left open, the one line list-open-findings --short prints, worded for the session's start. When list-member-problems refuses, prints instead its code and the command that shows its repair; input it cannot read is read as a startup." }
139
+ "does": "Reads the SessionStart hook's JSON on stdin and always exits 0, since the host adds a SessionStart hook's output to the context only then. Prints nothing in a project with no maps. Otherwise prints, each line marked principles:, for one principle whose members an audit assessed changed since, a line with its count, that its audit no longer covers them, and the list-member-problems ID command to run before the user's task, which offers acknowledging them or auditing again, or for several, one line counting them with the list-member-problems --short command that lists them, then, in git, what gives each principle's members with no baseline one, then each principle whose audit record a later release wrote, whose audits wait on an upgrade, then, while any principle awaits its first full audit, one line counting them that asks the agent to start one background subagent to follow show-first-audit-brief, tell the user, and relay its result, and at resume and compact only the count, asking for no second subagent, then, while any audit finding is left open, the one line list-open-findings --short prints, worded for the session's start. When list-member-problems refuses, prints instead its code and the command that shows its repair; input it cannot read is read as a startup." }
136
140
  ]
137
141
  },
138
142
  {
@@ -144,7 +148,7 @@
144
148
  "does": "Runs every check submit-answer would and prints the same refusal, or names the files submitting would write. Writes nothing.",
145
149
  "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request", "stale_request", "stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git", "invalid_removed_members", "empty_correction_map",
146
150
  "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding",
147
- "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes", "git_history_unavailable",
151
+ "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "plugin_member_read_only", "unassessed_changes", "git_history_unavailable",
148
152
  "no_correction_to_fill"],
149
153
  "refuses_like": ["read-map", "read-audit", "locate-text", "rewrite-audit"] },
150
154
  { "id": "submit-the-checked-answer", "actor": "agent",
@@ -202,6 +206,78 @@
202
206
  "cannot_check": "whether the user agrees, or whether the host runs the entries; start a new session to see the report." }
203
207
  ]
204
208
  },
209
+ {
210
+ "name": "show-logged-requests", "usage": "show-logged-requests", "group": "read", "options": [],
211
+ "summary": "Show each session the host captured, with its requests, files and bytes.",
212
+ "help": "learn-what-a-command-does/show-logged-requests",
213
+ "steps": [
214
+ { "id": "tally-captured-sessions", "actor": "cli",
215
+ "does": "Writes nothing. Refuses while the folder exists without its `.gitignore`, or git does not ignore every file there. Otherwise lists, from the host's `requests/index.jsonl`, each session's requests, the files they and their responses fill and those files' bytes, counts the request files no index line names, and names when the newest request file was written and the session of the index's newest line. Never says whether a session is capturing now.",
216
+ "refuses": ["request_logging_unguarded", "request_logging_not_ignored"] },
217
+ { "id": "judge-what-was-captured", "actor": "agent",
218
+ "does": "Judge from the sessions and their sizes whether capture is running as the user meant, and tell the user how much the folder holds.",
219
+ "cannot_check": "whether the session you run in is capturing, since the host's telemetry variables never reach your shell." }
220
+ ]
221
+ },
222
+ {
223
+ "name": "show-carrier-practices", "usage": "show-carrier-practices KIND", "group": "read", "options": [],
224
+ "summary": "Show the practices for judging and editing one kind of carrier, such as a rule file or a skill.",
225
+ "help": "learn-what-a-command-does/show-carrier-practices",
226
+ "steps": [
227
+ { "id": "show-carrier-page", "actor": "cli",
228
+ "does": "Writes nothing. Prints, for carrier kind KIND, the page of its practices under practices, and under source the guide it was distilled from and the plugin version it was reconciled at. Refuses a kind it has no page for, naming each it has.",
229
+ "refuses": ["unknown_carrier_kind"] },
230
+ { "id": "judge-and-edit-by-the-page", "actor": "agent",
231
+ "does": "Judge or edit the member of that kind by the page, and say in your answer which of its points the edit or finding rests on.",
232
+ "cannot_check": "whether the agent read the page or followed it." }
233
+ ]
234
+ },
235
+ {
236
+ "name": "turn-on-request-logging", "usage": "turn-on-request-logging", "group": "write-request-logging", "options": [],
237
+ "summary": "Set up the git-ignored folder where the host can write each request it sends.",
238
+ "help": "learn-what-a-command-does/turn-on-request-logging",
239
+ "steps": [
240
+ { "id": "write-ignored-request-logging-folder", "actor": "cli",
241
+ "does": "Writes `.principles/request-logging/.gitignore`, holding `*`, unless it is there, then asks git whether it ignores the folder, its files and every file already in it. Refuses outside git, or when git tracks a file there, and removes what it wrote. Once git confirms it, writes the launch file `settings.json`, whose `env` asks the host to write each request's body under `requests/` with no telemetry exporter, and prints the launch line.",
242
+ "refuses": ["request_logging_not_ignored"] },
243
+ { "id": "launch-with-the-line", "actor": "agent",
244
+ "does": "Give the user the launch line, and say that capture starts only when they relaunch the host with it and that each logged request holds the session's whole working context.",
245
+ "cannot_check": "whether the user relaunched the host with the line, or whether the host wrote any request." }
246
+ ]
247
+ },
248
+ {
249
+ "name": "show-members-in-logged-requests", "usage": "show-members-in-logged-requests [--short | --places | --member KEY]", "group": "read", "options": ["short", "places", "member"],
250
+ "summary": "Show which members' text logged requests hold.",
251
+ "help": "learn-what-a-command-does/show-members-in-logged-requests",
252
+ "steps": [
253
+ { "id": "scan-captured-requests", "actor": "cli",
254
+ "does": "Writes nothing. Refuses while the request-logging folder exists without its `.gitignore`, or git does not ignore it, and while jq or rg is not on PATH, naming the missing tool and what it does there, and a --member key no map holds. Otherwise prints, for each mapped member, how many captured requests held its lines, its most bytes in one and its segments; with --places or --member, each place its lines were seen, with the share of its lines there and their bytes; and no text from a request.",
255
+ "refuses": ["request_logging_unguarded", "request_logging_not_ignored", "fast_tools_missing", "unknown_member"] }
256
+ ]
257
+ },
258
+ {
259
+ "name": "turn-off-request-logging", "usage": "turn-off-request-logging", "group": "write-request-logging", "options": [],
260
+ "summary": "Stop the host capturing each request it sends, keeping every logged request already captured.",
261
+ "help": "learn-what-a-command-does/turn-off-request-logging",
262
+ "steps": [
263
+ { "id": "empty-launch-file", "actor": "cli",
264
+ "does": "Refuses while the folder exists without its `.gitignore`, or git does not ignore it. Otherwise empties the launch file's `env`, so a host started with it captures nothing, and writes nothing where request logging was never turned on. Deletes no logged request.",
265
+ "refuses": ["request_logging_unguarded", "request_logging_not_ignored"] },
266
+ { "id": "relaunch-the-host", "actor": "agent",
267
+ "does": "Tell the user the host they started with the launch file keeps capturing until they relaunch it.",
268
+ "cannot_check": "whether the host was relaunched." }
269
+ ]
270
+ },
271
+ {
272
+ "name": "remove-logged-requests", "usage": "remove-logged-requests [--keep-sessions N]", "group": "write-request-logging", "options": ["keep-sessions"],
273
+ "summary": "Delete the logged requests of all but the newest captured sessions.",
274
+ "help": "learn-what-a-command-does/remove-logged-requests",
275
+ "steps": [
276
+ { "id": "remove-older-sessions", "actor": "cli",
277
+ "does": "Refuses while the folder exists without its `.gitignore`, or git does not ignore it, and a --keep-sessions that is not a whole number, before deleting anything. Then ranks the sessions by their newest index line and deletes, under `requests/`, each file the index names for a session older than the newest N, keeping any file a kept session also names, and each request file the index does not name that was written before every kept session's file.",
278
+ "refuses": ["request_logging_unguarded", "request_logging_not_ignored", "invalid_keep_sessions"] }
279
+ ]
280
+ },
205
281
  {
206
282
  "name": "create-principle", "usage": "create-principle ID --description TEXT", "group": "write-map", "options": ["description"],
207
283
  "summary": "Map a new principle and say what it is.",
@@ -249,15 +325,15 @@
249
325
  ]
250
326
  },
251
327
  {
252
- "name": "add-member", "usage": "add-member ID PATH [--section HEADING] [--starting-at TEXT [--ending-at TEXT]] [--query QUERY] --role ROLE [--check COMMAND]", "group": "write-map", "options": ["section", "starting-at", "ending-at", "query", "role", "check"],
328
+ "name": "add-member", "usage": "add-member ID PATH [--section HEADING] [--starting-at TEXT [--ending-at TEXT]] [--query QUERY] [--plugin NAME@MARKETPLACE] --role ROLE [--check COMMAND]", "group": "write-map", "options": ["plugin", "section", "starting-at", "ending-at", "query", "role", "check"],
253
329
  "summary": "Add a file, a Markdown section or a passage.",
254
330
  "help": "learn-what-a-command-does/add-member",
255
331
  "steps": [
256
332
  { "id": "locate-new-member", "actor": "cli",
257
- "does": "Loads the map, or starts sticking-to-your-principles only after verifying its map path is absent at committed HEAD, requiring any prior removal to be committed. Then finds the member's text, so a locator that matches nothing is refused now rather than at the audit.",
258
- "refuses": ["invalid_answer", "ending_without_start", "ambiguous_passage_end", "map_removal_not_committed", "git_history_unavailable"], "refuses_like": ["read-map", "locate-text"] },
333
+ "does": "Loads the map, or starts sticking-to-your-principles only after verifying its map path is absent at committed HEAD, requiring any prior removal to be committed. Then finds the member's text, so a locator that matches nothing is refused now rather than at the audit. With --plugin, finds the plugin's install in Claude Code's record instead.",
334
+ "refuses": ["invalid_answer", "ending_without_start", "ambiguous_passage_end", "map_removal_not_committed", "git_history_unavailable", "plugin_component_not_plain", "plugin_member_located", "plugin_not_installed", "plugin_from_directory_marketplace", "plugin_marketplace_unknown", "plugin_component_linked", "plugin_component_not_found"], "refuses_like": ["read-map", "locate-text", "read-plugin-registry"] },
259
335
  { "id": "write-member", "actor": "cli",
260
- "does": "Refuses a member already in the map, then adds it with its role; the first member of sticking-to-your-principles creates its map.",
336
+ "does": "Refuses a member already in the map, then adds it with its role; the first member of sticking-to-your-principles creates its map. Reports, without deciding, other maps holding a whole-file member's file whole, and those whose member set nearly matches this one's.",
261
337
  "refuses": ["member_exists"] },
262
338
  { "id": "add-next-or-audit", "actor": "agent",
263
339
  "does": "Add the next member the same way. Once the map lists every member, commit it: in git, that commit is the members' baseline until their first full audit, which judges them and may come later; outside git, the first full audit gives them one.",
@@ -325,7 +401,7 @@
325
401
  { "to": "start-acknowledgement", "when": "you passed --member" },
326
402
  { "to": "start-deciding-open-findings", "when": "you passed --open-findings" }] },
327
403
  { "id": "assess-every-member", "actor": "agent",
328
- "does": "Assess each member not carried, and any carried one whose sighting is too old to rely on, the set as a whole and one recent decision under it, a finding per problem. Run each check, carried_checks_to_run's too, per shared_check_instructions and check_instructions. Decide each prior finding and listed member to check against the activation.",
404
+ "does": "Assess each member not carried, or carried on too old a sighting, by carrier_checks and page_command, then the set and one recent decision under it: a finding per problem. Run each check and carried_checks_to_run per shared_check_instructions and check_instructions. Decide each prior finding and listed member to check against the activation.",
329
405
  "prompt": "assess-every-member/assess-each-member-and-the-set",
330
406
  "checks": "every member is assessed or carried forward once, a marker only where the request carries the member, and each piece of evidence resolves to project text that has not changed since the request.",
331
407
  "cannot_check": "whether your assessment is true, a member reached your context, or your findings are the right ones.",
@@ -357,7 +433,7 @@
357
433
  { "to": "recheck-members", "when": "the request was an assessment or a correction" }] },
358
434
  { "id": "acknowledge-the-change", "actor": "cli",
359
435
  "does": "For a one-member audit, checks the answer's kept meaning, one-line reason, quotes then and now and any check result, then moves the member's hash and check result in the audit record beside the acknowledgement.",
360
- "refuses": ["stale_request", "cannot_acknowledge", "quote_not_found"] },
436
+ "refuses": ["stale_request", "cannot_acknowledge", "invalid_check_result", "quote_not_found"] },
361
437
  { "id": "commit-the-acknowledgement", "actor": "agent",
362
438
  "does": "Commit the audit record, then check that list-member-problems --short no longer reports the member.",
363
439
  "cannot_check": "that you committed, or that the change keeps the meaning.",
@@ -381,14 +457,14 @@
381
457
  "next": [{ "to": "complete-audit", "when": "there are no findings" },
382
458
  { "to": "dispose-of-each-finding", "when": "there are findings" }] },
383
459
  { "id": "dispose-of-each-finding", "actor": "agent",
384
- "does": "Fix each finding and reassess what you changed, or record why it waits: deferred, accepted or disagreed.",
460
+ "does": "Fix each finding per carrier_checks and reassess it, or record why it waits: deferred, accepted, disagreed.",
385
461
  "prompt": "dispose-of-each-finding/fix-or-record-each-finding",
386
462
  "checks": "each finding has one disposition, and each fixed finding changed the members it names.",
387
463
  "cannot_check": "whether a fix is right or a deferral justified.",
388
464
  "answer_with": "submit-answer" },
389
465
  { "id": "check-dispositions", "actor": "cli",
390
466
  "does": "Checks the original request, basis and hashes and, with a Git base, uninterrupted current-ID map presence on captured HEAD's first-parent line. Refuses unverifiable continuity or undeclared map changes. Checks one disposition per finding, that only fixed members changed since the base, and each recorded_at resolves.",
391
- "refuses": ["stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git", "invalid_removed_members", "empty_correction_map", "stale_request", "git_history_unavailable", "audit_completed_since_request", "incomplete_dispositions", "invalid_disposition", "invalid_answer", "claimed_change_missing", "unassessed_changes"],
467
+ "refuses": ["stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git", "invalid_removed_members", "empty_correction_map", "stale_request", "git_history_unavailable", "audit_completed_since_request", "incomplete_dispositions", "invalid_disposition", "invalid_answer", "claimed_change_missing", "plugin_member_read_only", "unassessed_changes"],
392
468
  "refuses_like": ["locate-text"] },
393
469
  { "id": "complete-audit", "actor": "cli",
394
470
  "does": "Writes the record unless it already says the same, and prints the open and resolved findings and the files to commit, in git only those differing from HEAD, with the commits since the base touching each changed member.",
@@ -0,0 +1,63 @@
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
+ # One string in a captured request, split at reminder tags into segments and each segment into lines: reminder
8
+ # inside a system-reminder tag, plain outside one.
9
+ class DecodedLeaf
10
+ OPENING = "<system-reminder>"
11
+ CLOSING = "</system-reminder>"
12
+ # Splits a string at each tag, keeping the tags as pieces of their own.
13
+ TAGS = /(#{Regexp.escape(OPENING)}|#{Regexp.escape(CLOSING)})/
14
+ # The segment each tag begins.
15
+ SEGMENT_AFTER = { OPENING => "reminder", CLOSING => "plain" }.freeze #: Hash[String, String]
16
+
17
+ #: (String) -> void
18
+ def initialize(text)
19
+ @text = text
20
+ freeze
21
+ end
22
+
23
+ # Each of its lines holding one of patterns, with its segment and the byte offset in the string it starts at, as
24
+ # [segment, line, offset]. Only the patterns it holds are looked for line by line, as a long string holds few of
25
+ # many patterns.
26
+ #: (Array[String]) -> Array[[String, String, Integer]]
27
+ def holding(patterns)
28
+ held = patterns.select { @text.include?(it) }
29
+ held.empty? ? [] : lines.select { |_, line, _| held.any? { line.include?(it) } }
30
+ end
31
+
32
+ private
33
+
34
+ # Each line with its segment and offset, in order.
35
+ #: () -> Array[[String, String, Integer]]
36
+ def lines
37
+ segments.flat_map do |segment, part, at|
38
+ part.split("\n", -1).map do |line|
39
+ placed = [segment, line, at] #: [String, String, Integer]
40
+ at += line.bytesize + 1
41
+ placed
42
+ end
43
+ end
44
+ end
45
+
46
+ # Each segment with the byte offset its text starts at: plain until a reminder tag opens, reminder until one
47
+ # closes, each tag's bytes counted between them.
48
+ #: () -> Array[[String, String, Integer]]
49
+ def segments
50
+ segment = "plain"
51
+ at = 0
52
+ @text.split(TAGS, -1).filter_map do |piece|
53
+ start = at
54
+ at += piece.bytesize
55
+ next [segment, piece, start] unless SEGMENT_AFTER.key?(piece)
56
+
57
+ segment = SEGMENT_AFTER.fetch(piece)
58
+ nil
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -7,8 +7,9 @@ module Principles
7
7
  # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
8
8
  module Data
9
9
  # What git says of HEAD in the repository holding one directory, as report-after-commit asks it after each shell
10
- # call: the repository's root, whether this tool mapped it, when its HEAD reflog was last written and the subject
11
- # of that move, HEAD's committer time, and the full sha of a revision. Each is nil where git cannot say.
10
+ # call: the repository's root and git folder, whether this tool mapped it, when its HEAD reflog was last written
11
+ # and the subject of that move, HEAD's committer time, and the full sha of a revision. Each is nil where git cannot
12
+ # say.
12
13
  class HeadReflog
13
14
  # The folders a mapped project holds its maps in: the folder's name now, and its earlier one.
14
15
  MAPS_FOLDERS = %w[.principles .memeplex].freeze #: Array[String]
@@ -25,6 +26,16 @@ module Principles
25
26
  #: () -> String?
26
27
  def toplevel = read(["rev-parse", "--show-toplevel"])
27
28
 
29
+ # The repository's git folder, which each of its worktrees shares and a clone does not, with every symbolic link
30
+ # resolved, or nil outside git.
31
+ #: () -> String?
32
+ def common_dir
33
+ folder = read(["rev-parse", "--path-format=absolute", "--git-common-dir"]) or return
34
+ File.realpath(folder)
35
+ rescue SystemCallError
36
+ nil
37
+ end
38
+
28
39
  # Whether this tool's folder is at the root.
29
40
  #: () -> bool
30
41
  def mapped?