principles 0.0.6 → 0.0.8

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 (338) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +383 -0
  3. data/LICENSE +202 -0
  4. data/NOTICE +4 -0
  5. data/README.md +111 -0
  6. data/exe/principles +20 -0
  7. data/lib/principles/after_commit_hook_options.rb +2 -2
  8. data/lib/principles/cli.rb +58 -41
  9. data/lib/principles/command_line.rb +37 -14
  10. data/lib/principles/command_routes.rb +21 -7
  11. data/lib/principles/controllers/acknowledgement.rb +50 -118
  12. data/lib/principles/controllers/acknowledgements.rb +154 -0
  13. data/lib/principles/controllers/after_commit_report.rb +44 -0
  14. data/lib/principles/controllers/answer.rb +52 -21
  15. data/lib/principles/controllers/answer_phase.rb +20 -3
  16. data/lib/principles/controllers/assessment.rb +41 -28
  17. data/lib/principles/controllers/audit.rb +59 -15
  18. data/lib/principles/controllers/audit_completion.rb +25 -12
  19. data/lib/principles/controllers/command.rb +13 -12
  20. data/lib/principles/controllers/correction.rb +26 -11
  21. data/lib/principles/controllers/first_audit_brief.rb +40 -0
  22. data/lib/principles/controllers/full_audit_request.rb +47 -83
  23. data/lib/principles/controllers/hook_setup.rb +49 -0
  24. data/lib/principles/controllers/inventory.rb +10 -8
  25. data/lib/principles/controllers/mapping.rb +2 -2
  26. data/lib/principles/controllers/member_acknowledgement.rb +148 -0
  27. data/lib/principles/controllers/member_entries.rb +4 -4
  28. data/lib/principles/controllers/member_problems_report.rb +84 -30
  29. data/lib/principles/controllers/members_a_commit_changed.rb +3 -3
  30. data/lib/principles/controllers/members_to_assess.rb +23 -20
  31. data/lib/principles/controllers/meta_principle_setup.rb +5 -6
  32. data/lib/principles/controllers/open_correction.rb +42 -0
  33. data/lib/principles/controllers/parts_to_read.rb +117 -0
  34. data/lib/principles/controllers/repoint.rb +1 -1
  35. data/lib/principles/controllers/running_tool.rb +56 -6
  36. data/lib/principles/controllers/session_start_report.rb +62 -0
  37. data/lib/principles/controllers/survey.rb +2 -2
  38. data/lib/principles/data/audit_files.rb +7 -7
  39. data/lib/principles/data/bounded_file.rb +1 -1
  40. data/lib/principles/data/candidate_files_found.rb +6 -3
  41. data/lib/principles/data/command-steps.json +67 -12
  42. data/lib/principles/data/expected_type.rb +3 -3
  43. data/lib/principles/data/first_parent_log.rb +1 -1
  44. data/lib/principles/data/head_reflog.rb +74 -0
  45. data/lib/principles/data/hook_input.rb +59 -0
  46. data/lib/principles/data/ignored_by_git.rb +2 -2
  47. data/lib/principles/data/known_fields.rb +1 -1
  48. data/lib/principles/data/linked_path.rb +1 -1
  49. data/lib/principles/data/map_files.rb +2 -2
  50. data/lib/principles/data/principles_on_path.rb +83 -0
  51. data/lib/principles/data/principles_subfolder.rb +1 -1
  52. data/lib/principles/data/project_files.rb +10 -3
  53. data/lib/principles/data/repository.rb +14 -7
  54. data/lib/principles/data/running_version.rb +10 -8
  55. data/lib/principles/data/schema_check.rb +5 -5
  56. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +86 -20
  57. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +95 -0
  58. data/lib/principles/data/schemas/assessment-answer.schema.json +55 -20
  59. data/lib/principles/data/schemas/audit-record.schema.json +29 -20
  60. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  61. data/lib/principles/data/schemas/correction-answer-guide.schema.json +1 -1
  62. data/lib/principles/data/schemas/correction-answer.schema.json +14 -62
  63. data/lib/principles/data/schemas/member-map.schema.json +3 -3
  64. data/lib/principles/data/schemas/repointing-answer.schema.json +1 -1
  65. data/lib/principles/error.rb +4 -4
  66. data/lib/principles/failure_refusal.rb +57 -0
  67. data/lib/principles/invocation_options.rb +7 -6
  68. data/lib/principles/launch.rb +49 -0
  69. data/lib/principles/list_open_findings_options.rb +23 -0
  70. data/lib/principles/models/accepted_loading.rb +2 -2
  71. data/lib/principles/models/acknowledged_check.rb +106 -0
  72. data/lib/principles/models/acknowledgement.rb +51 -53
  73. data/lib/principles/models/acknowledgement_left_as_printed.rb +18 -5
  74. data/lib/principles/models/acknowledgement_refusal.rb +25 -10
  75. data/lib/principles/models/acknowledgements.rb +115 -0
  76. data/lib/principles/models/acknowledgements_across.rb +68 -0
  77. data/lib/principles/models/activation.rb +2 -2
  78. data/lib/principles/models/after_commit_input.rb +115 -0
  79. data/lib/principles/models/agent_loads.rb +1 -1
  80. data/lib/principles/models/answer_fields.rb +2 -2
  81. data/lib/principles/models/answer_place.rb +3 -3
  82. data/lib/principles/models/answer_text.rb +2 -2
  83. data/lib/principles/models/answered_time.rb +12 -3
  84. data/lib/principles/models/assessment_answer.rb +10 -10
  85. data/lib/principles/models/assessment_basis.rb +2 -2
  86. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  87. data/lib/principles/models/assessment_report.rb +14 -15
  88. data/lib/principles/models/audit.rb +46 -34
  89. data/lib/principles/models/audit_record.rb +58 -27
  90. data/lib/principles/models/audit_records.rb +13 -13
  91. data/lib/principles/models/audit_start.rb +3 -3
  92. data/lib/principles/models/audited_member_lines.rb +1 -1
  93. data/lib/principles/models/candidate_files.rb +18 -10
  94. data/lib/principles/models/candidate_inventory.rb +6 -6
  95. data/lib/principles/models/candidate_outline.rb +9 -9
  96. data/lib/principles/models/carried_assessments.rb +18 -3
  97. data/lib/principles/models/carried_member.rb +5 -5
  98. data/lib/principles/models/changed_regions.rb +92 -0
  99. data/lib/principles/models/check_result_guide.rb +50 -0
  100. data/lib/principles/models/check_since_last_audit.rb +5 -4
  101. data/lib/principles/models/cited_files.rb +4 -4
  102. data/lib/principles/models/command_steps.rb +3 -3
  103. data/lib/principles/models/commits_brought_in.rb +1 -1
  104. data/lib/principles/models/commits_since_base.rb +1 -1
  105. data/lib/principles/models/correction_answer.rb +2 -2
  106. data/lib/principles/models/correction_basis.rb +19 -10
  107. data/lib/principles/models/dated_line.rb +1 -2
  108. data/lib/principles/models/decided_prior_findings.rb +6 -6
  109. data/lib/principles/models/declared_map_changes.rb +5 -5
  110. data/lib/principles/models/disposition.rb +21 -21
  111. data/lib/principles/models/entry_file.rb +1 -1
  112. data/lib/principles/models/entry_files.rb +1 -1
  113. data/lib/principles/models/evidence_item.rb +1 -1
  114. data/lib/principles/models/evidence_lines_since.rb +2 -2
  115. data/lib/principles/models/evidence_replacements.rb +3 -3
  116. data/lib/principles/models/finding_write_ups.rb +12 -5
  117. data/lib/principles/models/findings_left_open.rb +4 -4
  118. data/lib/principles/models/first_full_audit.rb +32 -0
  119. data/lib/principles/models/first_raised_claim.rb +1 -1
  120. data/lib/principles/models/fix_only_fields.rb +1 -1
  121. data/lib/principles/models/head_moves.rb +66 -0
  122. data/lib/principles/models/hook_commands.rb +49 -4
  123. data/lib/principles/models/ignored_candidates.rb +1 -1
  124. data/lib/principles/models/instruction_named.rb +2 -3
  125. data/lib/principles/models/json_digest.rb +2 -2
  126. data/lib/principles/models/json_path_query.rb +1 -1
  127. data/lib/principles/models/kept_prior_finding.rb +9 -9
  128. data/lib/principles/models/last_completed_revision.rb +4 -5
  129. data/lib/principles/models/left_as_printed.rb +2 -2
  130. data/lib/principles/models/line_diff.rb +113 -0
  131. data/lib/principles/models/line_span.rb +1 -1
  132. data/lib/principles/models/list_member_problems_check.rb +80 -0
  133. data/lib/principles/models/listed_members.rb +47 -0
  134. data/lib/principles/models/loaded_files.rb +4 -5
  135. data/lib/principles/models/loading_decision.rb +19 -10
  136. data/lib/principles/models/loading_facts.rb +1 -1
  137. data/lib/principles/models/loads_to_check.rb +1 -2
  138. data/lib/principles/models/located_text.rb +1 -1
  139. data/lib/principles/models/mapped_principles.rb +2 -2
  140. data/lib/principles/models/member.rb +31 -4
  141. data/lib/principles/models/member_assessments.rb +17 -8
  142. data/lib/principles/models/member_elsewhere.rb +4 -4
  143. data/lib/principles/models/member_file.rb +4 -4
  144. data/lib/principles/models/member_grounds.rb +1 -1
  145. data/lib/principles/models/member_hashes_as_written.rb +1 -1
  146. data/lib/principles/models/member_lines.rb +29 -61
  147. data/lib/principles/models/member_loads.rb +2 -2
  148. data/lib/principles/models/member_moves.rb +1 -1
  149. data/lib/principles/models/member_problems.rb +21 -18
  150. data/lib/principles/models/member_repair_moves.rb +15 -9
  151. data/lib/principles/models/member_sighting.rb +12 -15
  152. data/lib/principles/models/member_snapshots.rb +1 -1
  153. data/lib/principles/models/member_state.rb +1 -1
  154. data/lib/principles/models/members_across_principles.rb +77 -0
  155. data/lib/principles/models/members_elsewhere.rb +2 -2
  156. data/lib/principles/models/members_sharing_lines.rb +7 -7
  157. data/lib/principles/models/meta_principle.rb +11 -4
  158. data/lib/principles/models/missing_files.rb +3 -3
  159. data/lib/principles/models/new_findings.rb +4 -4
  160. data/lib/principles/models/open_correction.rb +57 -0
  161. data/lib/principles/models/open_finding.rb +36 -31
  162. data/lib/principles/models/open_findings_elsewhere.rb +2 -2
  163. data/lib/principles/models/other_principles.rb +2 -2
  164. data/lib/principles/models/other_templates_placeholders.rb +17 -16
  165. data/lib/principles/models/outline_budget.rb +7 -7
  166. data/lib/principles/models/outline_group.rb +1 -1
  167. data/lib/principles/models/outline_section.rb +2 -2
  168. data/lib/principles/models/part_named.rb +41 -0
  169. data/lib/principles/models/placement.rb +2 -2
  170. data/lib/principles/models/principle.rb +13 -13
  171. data/lib/principles/models/principle_history.rb +8 -8
  172. data/lib/principles/models/principle_members.rb +14 -7
  173. data/lib/principles/models/principles_folder_move.rb +1 -1
  174. data/lib/principles/models/principles_on_path.rb +29 -0
  175. data/lib/principles/models/principles_package.rb +3 -3
  176. data/lib/principles/models/prior_decision_fields.rb +8 -8
  177. data/lib/principles/models/prior_finding_decision.rb +8 -8
  178. data/lib/principles/models/prior_finding_outcomes.rb +1 -1
  179. data/lib/principles/models/prior_findings.rb +5 -5
  180. data/lib/principles/models/problem_report.rb +42 -9
  181. data/lib/principles/models/project.rb +29 -20
  182. data/lib/principles/models/project_history.rb +18 -12
  183. data/lib/principles/models/quoted_change.rb +8 -8
  184. data/lib/principles/models/recent_decision.rb +3 -3
  185. data/lib/principles/models/record_format.rb +16 -10
  186. data/lib/principles/models/record_judged_against.rb +4 -4
  187. data/lib/principles/models/recorded_entry.rb +17 -8
  188. data/lib/principles/models/recorded_finding.rb +9 -9
  189. data/lib/principles/models/recorded_findings.rb +2 -2
  190. data/lib/principles/models/recorded_hashes.rb +2 -2
  191. data/lib/principles/models/recorded_members.rb +13 -13
  192. data/lib/principles/models/refusal_before_shape.rb +2 -2
  193. data/lib/principles/models/repoint.rb +3 -3
  194. data/lib/principles/models/report_hooks.rb +69 -0
  195. data/lib/principles/models/reported_check.rb +42 -36
  196. data/lib/principles/models/request_id.rb +19 -7
  197. data/lib/principles/models/runs_from.rb +7 -2
  198. data/lib/principles/models/sent_answer.rb +38 -16
  199. data/lib/principles/models/sent_prior_decisions.rb +1 -1
  200. data/lib/principles/models/session_start_input.rb +37 -0
  201. data/lib/principles/models/shape_problems_beside.rb +1 -1
  202. data/lib/principles/models/skill_loads.rb +1 -1
  203. data/lib/principles/models/stale_request.rb +59 -0
  204. data/lib/principles/models/still_holds_restatement.rb +6 -6
  205. data/lib/principles/models/submitted_answer.rb +1 -1
  206. data/lib/principles/models/template_placeholders.rb +6 -6
  207. data/lib/principles/models/text_within.rb +1 -1
  208. data/lib/principles/models/tracked_paths.rb +38 -0
  209. data/lib/principles/models/unchecked_members.rb +2 -2
  210. data/lib/principles/models/uncommitted_files.rb +1 -1
  211. data/lib/principles/models/uncommitted_outside_the_map.rb +2 -2
  212. data/lib/principles/models/waits_on.rb +1 -1
  213. data/lib/principles/models/write_up_opening.rb +5 -5
  214. data/lib/principles/models/write_up_pointer.rb +3 -3
  215. data/lib/principles/models/write_up_repoint.rb +2 -3
  216. data/lib/principles/positional_arguments.rb +15 -7
  217. data/lib/principles/prose_list.rb +1 -1
  218. data/lib/principles/session_start_options.rb +3 -3
  219. data/lib/principles/start_audit_options.rb +54 -12
  220. data/lib/principles/supported_ruby.rb +24 -7
  221. data/lib/principles/version.rb +2 -2
  222. data/lib/principles/views/acknowledged_since_last_audit.rb +2 -2
  223. data/lib/principles/views/acknowledgement_result.rb +137 -17
  224. data/lib/principles/views/activation_in_hand.rb +1 -1
  225. data/lib/principles/views/answered_request.rb +6 -2
  226. data/lib/principles/views/assessed_members.rb +68 -38
  227. data/lib/principles/views/assessment_request.rb +43 -21
  228. data/lib/principles/views/audit_changes.rb +4 -4
  229. data/lib/principles/views/audit_commit.rb +5 -4
  230. data/lib/principles/views/audit_result.rb +100 -53
  231. data/lib/principles/views/candidate_files_result.rb +7 -6
  232. data/lib/principles/views/check_notes.rb +29 -6
  233. data/lib/principles/views/check_result_template.rb +51 -39
  234. data/lib/principles/views/completed_audit_next_step.rb +44 -0
  235. data/lib/principles/views/context_parts.rb +112 -0
  236. data/lib/principles/views/correction_request.rb +49 -33
  237. data/lib/principles/views/diff_since_last_audit.rb +8 -6
  238. data/lib/principles/views/findings_result.rb +33 -1
  239. data/lib/principles/views/first_audit_brief.rb +51 -0
  240. data/lib/principles/views/first_audit_line.rb +45 -0
  241. data/lib/principles/views/help.rb +4 -4
  242. data/lib/principles/views/hook_setup_result.rb +91 -0
  243. data/lib/principles/views/instruction.rb +3 -3
  244. data/lib/principles/views/invocation.rb +32 -9
  245. data/lib/principles/views/json_with_entries_on_lines.rb +6 -35
  246. data/lib/principles/views/landed_since_base.rb +1 -1
  247. data/lib/principles/views/line_history_since_last_audit.rb +35 -0
  248. data/lib/principles/views/lines_shared_with_member.rb +6 -6
  249. data/lib/principles/views/loads_to_check_result.rb +11 -7
  250. data/lib/principles/views/map_added_to.rb +3 -3
  251. data/lib/principles/views/map_result.rb +9 -9
  252. data/lib/principles/views/member_change_since_baseline.rb +44 -23
  253. data/lib/principles/views/member_lines_beside_text.rb +43 -0
  254. data/lib/principles/views/member_repairs.rb +3 -2
  255. data/lib/principles/views/member_row.rb +61 -0
  256. data/lib/principles/views/members_a_commit_changed.rb +15 -11
  257. data/lib/principles/views/members_with_no_baseline.rb +10 -3
  258. data/lib/principles/views/meta_principle_passage.rb +1 -1
  259. data/lib/principles/views/meta_principle_result.rb +12 -5
  260. data/lib/principles/views/one_member_check_result_template.rb +24 -12
  261. data/lib/principles/views/open_findings_elsewhere_result.rb +5 -2
  262. data/lib/principles/views/open_findings_line.rb +26 -36
  263. data/lib/principles/views/other_principles_unjudged_result.rb +6 -3
  264. data/lib/principles/views/outside_the_map_result.rb +5 -2
  265. data/lib/principles/views/package_since_last_audit_result.rb +29 -6
  266. data/lib/principles/views/parts_index_result.rb +60 -0
  267. data/lib/principles/views/principle_read_result.rb +5 -6
  268. data/lib/principles/views/principle_with_changed_members.rb +1 -1
  269. data/lib/principles/views/principles_with_no_completed_audit.rb +1 -2
  270. data/lib/principles/views/printed_json.rb +51 -0
  271. data/lib/principles/views/printed_principle.rb +1 -1
  272. data/lib/principles/views/prior_finding_decisions_result.rb +4 -4
  273. data/lib/principles/views/prior_findings_result.rb +17 -14
  274. data/lib/principles/views/problem_lines.rb +70 -45
  275. data/lib/principles/views/problem_result.rb +75 -43
  276. data/lib/principles/views/prompts/acknowledge-a-change/judge-each-member-once-for-every-principle.md +2 -0
  277. data/lib/principles/views/prompts/acknowledge-a-change/read-the-deferred-findings-it-keeps.md +1 -0
  278. data/lib/principles/views/prompts/acknowledge-a-change/report-the-exit-status-its-own-listing-gives.md +3 -0
  279. data/lib/principles/views/prompts/acknowledge-a-change/resolve-them-in-a-full-audit.md +1 -0
  280. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-each-change-keeps-its-meaning.md +8 -0
  281. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +3 -3
  282. data/lib/principles/views/prompts/assess-every-member/confirm-each-write-up-pointer-the-answer-drops.md +2 -0
  283. data/lib/principles/views/prompts/assess-every-member/decide-each-member-loading.md +2 -1
  284. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +1 -1
  285. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  286. data/lib/principles/views/prompts/assess-every-member/judge-a-carried-assessment-citing-a-decided-finding.md +3 -0
  287. data/lib/principles/views/prompts/assess-every-member/judge-a-submitted-carried-assessment-citing-a-decided-finding.md +5 -0
  288. data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-under-the-release-since-the-last-audit.md +1 -1
  289. data/lib/principles/views/prompts/assess-every-member/keep-the-printed-review-basis-or-replace-it.md +1 -0
  290. data/lib/principles/views/prompts/assess-every-member/name-the-commit-that-made-the-check.md +1 -0
  291. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -1
  292. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +1 -0
  293. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  294. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +5 -3
  295. data/lib/principles/views/prompts/assess-every-member/why-each-member-is-judged-again.md +3 -2
  296. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  297. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -0
  298. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -4
  299. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +2 -2
  300. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -2
  301. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +4 -3
  302. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +16 -16
  303. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +65 -61
  304. data/lib/principles/views/prompts/learn-what-a-command-does/report-after-commit.md +14 -0
  305. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +26 -0
  306. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +22 -20
  307. data/lib/principles/views/prompts/learn-what-a-command-does/show-first-audit-brief.md +19 -0
  308. data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +13 -0
  309. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +3 -1
  310. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +12 -0
  311. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -28
  312. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +39 -38
  313. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +2 -2
  314. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +18 -0
  315. data/lib/principles/views/prompts/set-principles-up/offer-the-report-hooks.md +2 -0
  316. data/lib/principles/views/prompts/set-principles-up/wire-the-report-hooks-with-the-user.md +8 -0
  317. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +3 -4
  318. data/lib/principles/views/prompts/start-a-session/every-loaded-line-costs-every-session.md +1 -0
  319. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +3 -0
  320. data/lib/principles/views/prompts/start-a-session/run-each-command-above.md +1 -0
  321. data/lib/principles/views/prompts/start-a-session/start-no-second-first-audit.md +2 -0
  322. data/lib/principles/views/prompts/start-a-session/start-with-the-principles-skill.md +1 -0
  323. data/lib/principles/views/prompts.rb +1 -1
  324. data/lib/principles/views/read_the_change.rb +36 -0
  325. data/lib/principles/views/record_waiting_on_an_upgrade.rb +2 -2
  326. data/lib/principles/views/repoint_result.rb +1 -1
  327. data/lib/principles/views/report_hooks_offer.rb +25 -0
  328. data/lib/principles/views/request_part.rb +5 -5
  329. data/lib/principles/views/request_parts.rb +1 -1
  330. data/lib/principles/views/session_start_report.rb +46 -0
  331. data/lib/principles/views/shell_word.rb +1 -1
  332. data/lib/principles/views/trimmed_instructions_note.rb +30 -0
  333. data/lib/principles/views/visible_text.rb +1 -1
  334. data/lib/principles/views/workflow_diagram.rb +1 -1
  335. data/principles.gemspec +44 -0
  336. metadata +95 -14
  337. data/lib/principles/views/prompts/start-a-session/it-returns-after-each-clear-or-compaction-too.md +0 -1
  338. data/lib/principles/views/prompts/start-a-session/it-returns-at-each-session-start.md +0 -1
@@ -0,0 +1,62 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "member_problems_report"
6
+ require_relative "audit"
7
+ require_relative "../models/session_start_input"
8
+ require_relative "../views/session_start_report"
9
+
10
+ module Principles
11
+ # Each runs one command: reads models, applies their rules and prints through a view.
12
+ # controllers/CLAUDE.md owns the boundary.
13
+ module Controllers
14
+ # report-at-session-start, which a SessionStart hook runs: what the agent should act on as its session starts,
15
+ # read from the hook's JSON on stdin. It exits 0 whatever it finds, since the host adds the hook's stdout to the
16
+ # context only then, and prints nothing when there is nothing to act on.
17
+ class SessionStartReport < Command
18
+ #: (String, String?, Hash[String, untyped]) -> untyped
19
+ def call(command, _id, options)
20
+ naming_the_executable do
21
+ unknown(command) unless command == "report-at-session-start"
22
+
23
+ printed(Models::SessionStartInput.new(options["stdin"].to_s))
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # The lines the session starts with, from the hook's input: from the plugin, any other version on PATH, then
30
+ # what list-member-problems reports of the members, then the open findings; none of those in a project with no
31
+ # maps. A refusal is named by its code, with the command that shows its repair, since a hook exiting 1 shows the
32
+ # user an error and gives the agent nothing.
33
+ #: (Models::SessionStartInput) -> Views::Lines
34
+ def printed(input)
35
+ first = Views::SessionStartReport.new(other_version)
36
+ begin
37
+ first.followed_by(@principles.ids.empty? ? [] : reported(input.source))
38
+ rescue Error => e
39
+ first.refused(e.payload.fetch("code"), invocation.without_project)
40
+ end.printed
41
+ end
42
+
43
+ # From the plugin's bin, the line naming another version of principles earlier on PATH, which a bare principles
44
+ # command runs in place of the plugin's; none from the command line, where the copy on PATH is this one. The
45
+ # running version is read only once another copy is found, since in a checkout reading it asks git.
46
+ #: () -> Array[String]
47
+ def other_version
48
+ return [] unless @tool.runs_from.session_start_hook_in_this_session?
49
+
50
+ other = @tool.other_on_path or return []
51
+ running = @tool.version
52
+ other.shadows?(running) ? [Views::SessionStartReport.other_version(other.path, other.version, running)] : []
53
+ end
54
+
55
+ # Each line the session starts with, source: startup, resume, clear or compact.
56
+ #: (String) -> Array[String]
57
+ def reported(source)
58
+ handed(MemberProblemsReport).session_start_lines(source) + handed(Audit).session_start_open_findings(source)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -12,7 +12,7 @@ module Principles
12
12
  module Controllers
13
13
  # list-candidate-files: the survey of the files that look like agent guidance, with their outlines within the
14
14
  # budget, and the question of which principle they carry. It changes nothing on disk, and changes for the survey's
15
- # reasons alone, apart from the reads of what is already mapped (#1015).
15
+ # reasons alone, apart from the reads of what is already mapped.
16
16
  class Survey < Command
17
17
  #: (String, String?, Hash[String, untyped]) -> untyped
18
18
  def call(command, _id, options)
@@ -34,7 +34,7 @@ module Principles
34
34
  Views::CandidateOutlinesResult.new(found.to_h).result
35
35
  end
36
36
 
37
- # The survey; with a revision, only once it names a commit in git (#1171).
37
+ # The survey; with a revision, only once it names a commit in git.
38
38
  #: (Hash[String, untyped]) -> untyped
39
39
  def list_candidate_files(options)
40
40
  after = options["commits_after"]
@@ -12,9 +12,9 @@ module Principles
12
12
  module Data
13
13
  # The audit records: one JSON file per principle under .principles/audits/, committed in the audited
14
14
  # repository beside its map. A record holds the last audit's base commit, each member's hash and each
15
- # finding's id, members and action, never the agent's prose (D24, D25).
15
+ # finding's id, members and action, never the agent's prose.
16
16
  class AuditFiles
17
- # The key a record named its principle under before the rename to principles (#536).
17
+ # The key a record named its principle under before the rename to principles.
18
18
  EARLIER_ID_KEY = "memeplex_id"
19
19
 
20
20
  #: (PrinciplesSubfolder) -> void
@@ -22,7 +22,7 @@ module Principles
22
22
  @directory = directory
23
23
  end
24
24
 
25
- # Which of the folder and its earlier name hold this subfolder (#536).
25
+ # Which of the folder and its earlier name hold this subfolder.
26
26
  #: () -> Array[String]
27
27
  def held_in
28
28
  @directory.held_in
@@ -37,7 +37,7 @@ module Principles
37
37
  #: (String) -> bool
38
38
  def entry?(id) = @directory.entry?(id, shown_as: relative(id))
39
39
 
40
- # The record of id's last audit, or nil when it has none, checked against its schema (D29), handing the block
40
+ # The record of id's last audit, or nil when it has none, checked against its schema, handing the block
41
41
  # a record the schema refuses, as parse does.
42
42
  #: (String) ?{ (untyped) -> void } -> Hash[String, untyped]?
43
43
  def read(id, &)
@@ -46,9 +46,9 @@ module Principles
46
46
  parse(id, @directory.read(id, shown_as: relative(id)), &)
47
47
  end
48
48
 
49
- # The record of id from its text, with an older version's key upgraded, checked against its schema (D29). A
49
+ # The record of id from its text, with an older version's key upgraded, checked against its schema. A
50
50
  # record the schema refuses is handed to the block first, which may refuse it otherwise, as a model does one a
51
- # later copy wrote (D85).
51
+ # later copy wrote.
52
52
  #: (String, String) ?{ (untyped) -> void } -> Hash[String, untyped]
53
53
  def parse(id, text, &)
54
54
  record = upgraded(JsonText.new(text).parsed)
@@ -74,7 +74,7 @@ module Principles
74
74
  File.join(PrinciplesSubfolder::FOLDER, "audits", "#{id}.json")
75
75
  end
76
76
 
77
- # Where record id was kept before the folder took its name now, so it can be read at earlier commits (#536).
77
+ # Where record id was kept before the folder took its name now, so it can be read at earlier commits.
78
78
  #: (String) -> String
79
79
  def earlier_relative(id)
80
80
  File.join(PrinciplesSubfolder::EARLIER_FOLDER, "audits", "#{id}.json")
@@ -13,7 +13,7 @@ module Principles
13
13
  LIMIT = 4 * 1024 * 1024 #: Integer
14
14
 
15
15
  # shown_as is the path a refusal gives; named is what its message calls the file, such as "The answer" for a
16
- # file the agent named and holds the path of (#1118).
16
+ # file the agent named and holds the path of.
17
17
  #: (String, ?shown_as: String, ?named: String) -> void
18
18
  def initialize(path, shown_as: path, named: shown_as)
19
19
  @path = path
@@ -17,14 +17,17 @@ module Principles
17
17
 
18
18
  # The instruction files an agent host loads by convention, beside any explicitly selected paths.
19
19
  CANDIDATE_NAMES = %w[CLAUDE.md AGENTS.md].freeze
20
- CANDIDATE_PATH = %r{(?:\A|/)\.claude/(?:rules/|skills/|agents/|settings[^/]*\.json\z)}
20
+ # Claude Code's rules, skills, agents and settings, and Codex's skills in .agents/skills, hooks in
21
+ # .codex/hooks.json and custom agents in .codex/agents.
22
+ CANDIDATE_PATH = %r{(?:\A|/)(?:\.claude/(?:rules/|skills/|agents/|settings[^/]*\.json\z)|\.agents/skills/|
23
+ \.codex/(?:hooks\.json\z|agents/))}x
21
24
 
22
25
  # Folder names that often hold test data shaped like guidance, such as a sample CLAUDE.md under
23
26
  # spec/fixtures/. A name is a hint, not a fact: the agent decides, so these files stay listed and are
24
27
  # named here with the folder that matched (alpha 009 friction 1).
25
28
  TEST_DATA_FOLDER = %r{(?:\A|/)(fixtures?|examples?|samples?)/}
26
29
 
27
- # One readable candidate: its path, its length in characters, and for a link the file it leads to (#695).
30
+ # One readable candidate: its path, its length in characters, and for a link the file it leads to.
28
31
  # The stand-in project lists by it too, so the two cannot disagree on the shape.
29
32
  #: (String, text: String, leads_to: String) -> Hash[String, untyped]
30
33
  def self.listed(path, text:, leads_to:)
@@ -100,7 +103,7 @@ module Principles
100
103
  end
101
104
 
102
105
  # A folder below the root holding its own .git, a worktree's file or a clone's folder, is another project,
103
- # as git treats it (#376). The root may hold one too: this tool runs in a worktree.
106
+ # as git treats it. The root may hold one too: this tool runs in a worktree.
104
107
  #: (String) -> bool
105
108
  def nested_repository?(absolute)
106
109
  absolute != @files.root && File.exist?(File.join(absolute, ".git"))
@@ -16,7 +16,7 @@
16
16
  "read-map": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unknown_principle", "unparseable_map", "invalid_map", "newer_format", "duplicate_member"],
17
17
  "read-audit": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unparseable_audit", "invalid_audit_record"],
18
18
  "rewrite-audit": ["newer_audit_record"],
19
- "locate-text": ["outside_project", "not_a_file", "unreadable_file", "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",
19
+ "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
20
  "ambiguous_heading", "passage_not_found", "ambiguous_passage", "passage_end_not_found",
21
21
  "broken_members"]
22
22
  },
@@ -70,12 +70,12 @@
70
70
  ]
71
71
  },
72
72
  {
73
- "name": "list-member-problems", "usage": "list-member-problems [ID] [--short | --commits-after COMMIT --hook-event EVENT]", "group": "read", "options": ["short", "commits-after", "hook-event"],
73
+ "name": "list-member-problems", "usage": "list-member-problems [ID] [--short | --commits-after COMMIT --hook-event EVENT]", "group": "read", "options": ["short", "session-start", "commits-after", "hook-event"],
74
74
  "summary": "Members whose reference is broken, or whose own text changed since their baseline.",
75
75
  "help": "learn-what-a-command-does/list-member-problems",
76
76
  "steps": [
77
77
  { "id": "compare-members-with-their-baselines", "actor": "cli",
78
- "does": "Finds each member of map ID, or of every map, and compares its own text with the last audit's hash for it, or else with its text at the commit that mapped it where it is. Refuses while any member cannot be found or read, or a map cannot be read, so a gate can stop on the exit status; otherwise lists each changed member with what it was compared with, and counts every state. With --short, prints one tab-separated line per changed member and exits 3 when a member an audit assessed changed, and 4 when the only changes are edits to members no audit has assessed.",
78
+ "does": "Finds each member of map ID, or of every map, and compares its own text with the last audit's hash for it, or else with its text at the commit that mapped it where it is. Refuses while any member cannot be found or read, or a map cannot be read, so a gate can stop on the exit status; otherwise lists each changed member with what it was compared with, and counts every state. With --short, prints one tab-separated line per changed member, then one per principle counting its members no audit has assessed, and exits 3 when it prints any line.",
79
79
  "refuses": ["broken_members"], "refuses_like": ["read-map", "read-audit"] },
80
80
  { "id": "repair-or-audit", "actor": "agent",
81
81
  "does": "For a refusal, say whether each listed member moved or is gone, and repair it. For a changed member, audit its principle when the change was meant to alter the principle.",
@@ -104,12 +104,12 @@
104
104
  ]
105
105
  },
106
106
  {
107
- "name": "list-open-findings", "usage": "list-open-findings [ID] [--short [--session-start SOURCE]]", "group": "read", "options": ["short", "session-start"],
107
+ "name": "list-open-findings", "usage": "list-open-findings [ID] [--lines | --short [--session-start SOURCE]]", "group": "read", "options": ["short", "session-start", "lines"],
108
108
  "summary": "The findings the last audit of each principle deferred or accepted, and where each is written up.",
109
109
  "help": "learn-what-a-command-does/list-open-findings",
110
110
  "steps": [
111
111
  { "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 --short, prints one line saying how many are open, how long the oldest has waited and what it waits on, and nothing when none is open; --session-start clear or compact words it for a context just cleared or compacted, and resume shortens it to the facts, since a resumed conversation holds the whole line already.",
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 are open, how long the oldest has waited and what it waits on, and nothing when none is open; --session-start clear or compact words it for a context just cleared or compacted, and resume shortens it to the facts, since a resumed conversation holds the whole line already.",
113
113
  "refuses_like": ["read-map", "read-audit"] },
114
114
  { "id": "follow-up-each-finding", "actor": "agent",
115
115
  "does": "Read each finding where its recorded_at points, and decide each one at its principle's next full audit.",
@@ -118,7 +118,25 @@
118
118
  ]
119
119
  },
120
120
  {
121
- "name": "show-answer-check", "usage": "show-answer-check REQUEST_ID --file FILE|-", "group": "read", "options": ["file"], "requires": ["file"],
121
+ "name": "report-after-commit", "usage": "report-after-commit", "group": "read", "options": [],
122
+ "summary": "The mapped members a commit just changed, for a hook after each shell call to put beside the call's result.",
123
+ "help": "learn-what-a-command-does/report-after-commit",
124
+ "steps": [
125
+ { "id": "report-after-commit", "actor": "cli",
126
+ "does": "Reads the hook's JSON on stdin after a shell call and always exits 0. When the call committed in a mapped repository, its own directory's or one its command changed into with cd or ran git -C in, prints the hook's JSON naming the members those commits changed, for the first such repository; otherwise prints nothing, at the cost of a few git calls." }
127
+ ]
128
+ },
129
+ {
130
+ "name": "report-at-session-start", "usage": "report-at-session-start", "group": "read", "options": [],
131
+ "summary": "What the agent should act on as a session starts, for a SessionStart hook to add to its context.",
132
+ "help": "learn-what-a-command-does/report-at-session-start",
133
+ "steps": [
134
+ { "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:, the line saying every line loaded at session start costs every session, but on resume, then one line for each principle whose members an audit assessed changed since, with its count and the list-member-problems --short command that lists them, then the principles skill as where to start, 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." }
136
+ ]
137
+ },
138
+ {
139
+ "name": "show-answer-check", "usage": "show-answer-check [REQUEST_ID] --file FILE|- [--as template]", "group": "read", "options": ["file", "as"], "requires": ["file"],
122
140
  "summary": "Check an answer without submitting it.",
123
141
  "help": "learn-what-a-command-does/show-answer-check",
124
142
  "steps": [
@@ -126,13 +144,38 @@
126
144
  "does": "Runs every check submit-answer would and prints the same refusal, or names the files submitting would write. Writes nothing.",
127
145
  "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",
128
146
  "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding",
129
- "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes", "git_history_unavailable"],
147
+ "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes", "git_history_unavailable",
148
+ "no_correction_to_fill"],
130
149
  "refuses_like": ["read-map", "read-audit", "locate-text", "rewrite-audit"] },
131
150
  { "id": "submit-the-checked-answer", "actor": "agent",
132
151
  "does": "Fix what a refusal names and check again, or submit the answer unchanged.",
133
152
  "answer_with": "submit-answer" }
134
153
  ]
135
154
  },
155
+ {
156
+ "name": "show-open-correction", "usage": "show-open-correction ID", "group": "read", "options": [],
157
+ "summary": "Print the answer to fill for the correction a full audit's assessment opened, whenever you need it.",
158
+ "help": "learn-what-a-command-does/show-open-correction",
159
+ "steps": [
160
+ { "id": "print-open-correction", "actor": "cli",
161
+ "does": "Writes nothing. Prints the correction's answer alone, which submit-answer names rather than prints, from the open audit record that keeps it, in git and outside it. Refuses while principle ID has no open correction to print: with no audit open, it names the full audit to start; with one open that an earlier release wrote, it says to submit the assessment again, which prints its correction and keeps it.",
162
+ "refuses": ["unknown_principle", "no_open_correction"], "refuses_like": ["read-audit"] }
163
+ ]
164
+ },
165
+ {
166
+ "name": "show-first-audit-brief", "usage": "show-first-audit-brief [ID]", "group": "read", "options": [],
167
+ "summary": "Print the instructions for one background subagent to run a principle's first full audit.",
168
+ "help": "learn-what-a-command-does/show-first-audit-brief",
169
+ "steps": [
170
+ { "id": "print-first-audit-brief", "actor": "cli",
171
+ "does": "Writes nothing. With no ID, lists under awaiting_first_audit the principles list-member-problems names as awaiting a first full audit, and each one's brief command on its own line. With ID, prints the brief a background subagent follows to run its first full audit: stop if a principles command would ask the user's permission, read the request in parts, fill, check and submit its answer, commit nothing and edit no member file, and return at most about 600 bytes. Refuses principle ID once a full audit of it has completed, naming the command that lists those still awaiting one.",
172
+ "refuses": ["unknown_principle", "first_audit_completed"], "refuses_like": ["read-audit"] },
173
+ { "id": "run-the-brief-in-a-subagent", "actor": "agent",
174
+ "does": "Start one background subagent to follow the brief, and carry on with the user's task; relay what it returns at your next pause, and commit the audit record it wrote by its path, or tell the user it is ready to commit.",
175
+ "cannot_check": "whether the subagent ran without asking the user's permission, or whether its return is accurate; check the record with git status --short on its path.",
176
+ "answer_with": "start-audit" }
177
+ ]
178
+ },
136
179
  {
137
180
  "name": "show-meta-principle-passage", "usage": "show-meta-principle-passage", "group": "read", "options": [],
138
181
  "summary": "Set principles up: propose the passage that keeps the others held between audits, and the add-member that maps it.",
@@ -147,6 +190,18 @@
147
190
  "answer_with": "add-member" }
148
191
  ]
149
192
  },
193
+ {
194
+ "name": "show-hook-setup", "usage": "show-hook-setup", "group": "read", "options": [],
195
+ "summary": "Show the hook entries that run the session-start and after-commit reports without the principles plugin.",
196
+ "help": "learn-what-a-command-does/show-hook-setup",
197
+ "steps": [
198
+ { "id": "show-hook-entries", "actor": "cli",
199
+ "does": "Writes nothing. Prints, for Claude Code then Codex, the file a project's own hooks go in and the entries that run report-at-session-start at each session's start and report-after-commit after each shell call, each guarded to say principles failed to start instead of failing the hook, and how to remove them." },
200
+ { "id": "write-the-hook-entries", "actor": "agent",
201
+ "does": "Show the user the entries for this session's host and the file they go in, and write them there only once the user agrees; remove them when the principles plugin is enabled.",
202
+ "cannot_check": "whether the user agrees, or whether the host runs the entries; start a new session to see the report." }
203
+ ]
204
+ },
150
205
  {
151
206
  "name": "create-principle", "usage": "create-principle ID --description TEXT", "group": "write-map", "options": ["description"],
152
207
  "summary": "Map a new principle and say what it is.",
@@ -259,18 +314,18 @@
259
314
  ]
260
315
  },
261
316
  {
262
- "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups] [--as template | --instruction FIELD]", "group": "write-audit-record", "options": ["member", "write-ups", "as", "instruction"],
317
+ "name": "start-audit", "usage": "start-audit ID [ID ...] [--member MEMBER ... | --write-ups] [--as template [--part members/ID] | --instruction FIELD | --part PART]", "group": "write-audit-record", "options": ["member", "write-ups", "as", "instruction", "part"],
263
318
  "summary": "Ask for an assessment of every member and the set.",
264
319
  "help": "learn-what-a-command-does/start-audit",
265
320
  "steps": [
266
321
  { "id": "snapshot-members", "actor": "cli",
267
322
  "does": "Refuses an empty map or, in git, an uncommitted map or member file; bases the audit on HEAD. Fill --as template's output with your own judgement, under $TMPDIR; its left_as_printed_rule says how a field left as printed is read.",
268
- "refuses": ["map_has_no_members", "uncommitted_files", "unknown_instruction"], "refuses_like": ["read-map", "locate-text", "rewrite-audit"],
323
+ "refuses": ["map_has_no_members", "uncommitted_files", "unknown_instruction", "unknown_part"], "refuses_like": ["read-map", "locate-text", "rewrite-audit"],
269
324
  "next": [{ "to": "assess-every-member", "when": "you passed neither --member nor --write-ups" },
270
325
  { "to": "start-acknowledgement", "when": "you passed --member" },
271
326
  { "to": "start-repointing", "when": "you passed --write-ups" }] },
272
327
  { "id": "assess-every-member", "actor": "agent",
273
- "does": "Assess each member not carried forward, and any carried one whose sighting is too old to stand behind, the set as a whole and one decision you made recently under it, with a finding for each problem. Decide each prior finding and member to check against the activation the request lists. The request says how to answer each part.",
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.",
274
329
  "prompt": "assess-every-member/assess-each-member-and-the-set",
275
330
  "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.",
276
331
  "cannot_check": "whether your assessment is true, a member reached your context, or your findings are the right ones.",
@@ -290,12 +345,12 @@
290
345
  ]
291
346
  },
292
347
  {
293
- "name": "submit-answer", "usage": "submit-answer REQUEST_ID --file FILE|-", "group": "write-audit-record", "options": ["file"], "requires": ["file"],
348
+ "name": "submit-answer", "usage": "submit-answer [REQUEST_ID] --file FILE|-", "group": "write-audit-record", "options": ["file"], "requires": ["file"],
294
349
  "summary": "Give the answer a request asked for.",
295
350
  "help": "learn-what-a-command-does/submit-answer",
296
351
  "steps": [
297
352
  { "id": "match-request", "actor": "cli",
298
- "does": "Reads FILE, or stdin for -, and checks that its request_id is REQUEST_ID, an id this tool prints.",
353
+ "does": "Reads FILE, or stdin for -, and takes its request_id, an id this tool prints, as the request; REQUEST_ID, when given, must match.",
299
354
  "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request"], "refuses_like": ["rewrite-audit"],
300
355
  "next": [{ "to": "acknowledge-the-change", "when": "the request was a one-member audit" },
301
356
  { "to": "record-the-repoints", "when": "the request was a repoint of write-ups" },
@@ -7,15 +7,15 @@ 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
  # The type one schema asks for, from its type keyword: whether a value has it, and how a refusal names it,
10
- # with the keys an object takes, so an agent that sent another type learns the shape from the refusal (#737).
10
+ # with the keys an object takes, so an agent that sent another type learns the shape from the refusal.
11
11
  class ExpectedType
12
12
  TYPES = {
13
13
  "object" => Hash, "array" => Array, "string" => String, "integer" => Integer, "boolean" => [true, false],
14
14
  "null" => NilClass
15
15
  }.freeze #: Hash[String, untyped]
16
16
  # This tool's own schema keyword: what a refusal of the value's type adds, such as when to point inside a
17
- # file, which the keys alone do not say (#758), as {"keys", "says"}. The refusal says it after the required
18
- # keys, in place of the optional keys it names, so it names each key once (#765).
17
+ # file, which the keys alone do not say, as {"keys", "says"}. The refusal says it after the required
18
+ # keys, in place of the optional keys it names, so it names each key once.
19
19
  ADVICE = "x-type-refusal-advice"
20
20
 
21
21
  #: (Hash[String, untyped]) -> void
@@ -8,7 +8,7 @@ module Principles
8
8
  module Data
9
9
  # The commits on a first-parent line that changed any of some paths, as git log gives them, newest first, each as
10
10
  # its full and short sha, subject line, author date and whether it is a root commit ("true" or "false"). The list
11
- # and each commit are frozen, and a list asked to be kept is read from git once, a refusal included (#1161).
11
+ # and each commit are frozen, and a list asked to be kept is read from git once, a refusal included.
12
12
  class FirstParentLog
13
13
  #: (GitCommand) -> void
14
14
  def initialize(git)
@@ -0,0 +1,74 @@
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 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.
12
+ class HeadReflog
13
+ # The folders a mapped project holds its maps in: the folder's name now, and its earlier one.
14
+ MAPS_FOLDERS = %w[.principles .memeplex].freeze #: Array[String]
15
+ # How much of a reflog's end holds its last entry: a subject runs to one line, of a commit's first line.
16
+ TAIL_BYTES = 8192
17
+
18
+ #: (String) -> void
19
+ def initialize(directory)
20
+ @git = GitCommand.new(directory) #: GitCommand
21
+ freeze
22
+ end
23
+
24
+ # The root of the work tree holding the directory, or nil outside git.
25
+ #: () -> String?
26
+ def toplevel = read(["rev-parse", "--show-toplevel"])
27
+
28
+ # Whether this tool's folder is at the root.
29
+ #: () -> bool
30
+ def mapped?
31
+ root = toplevel or return false
32
+ MAPS_FOLDERS.any? { File.directory?(File.join(root, it)) }
33
+ end
34
+
35
+ # When this work tree's HEAD reflog was last written, to the second, and the subject of its last entry, or nil
36
+ # when it keeps none.
37
+ #: () -> [Integer, String]?
38
+ def last_move
39
+ path = read(["rev-parse", "--path-format=absolute", "--git-path", "logs/HEAD"])
40
+ return unless path && File.file?(path)
41
+
42
+ [File.mtime(path).to_i, last_line(path).chomp.split("\t", 2)[1].to_s]
43
+ rescue SystemCallError
44
+ nil
45
+ end
46
+
47
+ # HEAD's committer time, in seconds, or nil when there is no HEAD.
48
+ #: () -> Integer?
49
+ def committed_at = read(["log", "-1", "--format=%ct", "HEAD"])&.to_i
50
+
51
+ # The full sha revision names, or nil when it names no commit.
52
+ #: (String) -> String?
53
+ def commit(revision) = read(["rev-parse", "--verify", "--quiet", "--end-of-options", "#{revision}^{commit}"])
54
+
55
+ private
56
+
57
+ # The last line of the file at path, read from its end, since a reflog grows with every move.
58
+ #: (String) -> String
59
+ def last_line(path)
60
+ File.open(path) do |file|
61
+ file.seek([file.size - TAIL_BYTES, 0].max)
62
+ file.read.to_s.lines.last.to_s
63
+ end
64
+ end
65
+
66
+ #: (Array[String]) -> String?
67
+ def read(arguments)
68
+ output, ok = @git.run(arguments)
69
+ text = output.strip
70
+ text if ok && !text.empty?
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,59 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "io/wait"
5
+ require_relative "bounded_file"
6
+
7
+ module Principles
8
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
9
+ module Data
10
+ # The JSON a host passes on stdin to the hook that runs a command, as report-at-session-start and
11
+ # report-after-commit read it. A host writes it and closes stdin, but an agent's shell can run the command with
12
+ # stdin left open and sending nothing, which a plain read waits on for as long as the shell lets it.
13
+ class HookInput
14
+ # How long, in seconds, to wait for each part of the input before reading it as ended.
15
+ WAIT = 1.0 #: Float
16
+
17
+ #: (IO | StringIO, ?wait: Float) -> void
18
+ def initialize(io, wait: WAIT)
19
+ @io = io
20
+ @wait = wait
21
+ freeze
22
+ end
23
+
24
+ # The text on stdin, or nothing when stdin is a terminal, so a person trying the command by hand is not left
25
+ # waiting on it, or cannot be read, since a hook's command exits 0. A pipe is read until it ends, or until
26
+ # nothing more arrives within the wait.
27
+ #: () -> String
28
+ def text
29
+ return "" if @io.tty?
30
+ return @io.read(BoundedFile::LIMIT).to_s unless @io.is_a?(IO)
31
+
32
+ arrived(@io)
33
+ rescue IOError, SystemCallError
34
+ ""
35
+ end
36
+
37
+ private
38
+
39
+ # What arrives on io, within LIMIT, until it ends or a wait passes with nothing more.
40
+ #: (IO) -> String
41
+ def arrived(io)
42
+ read = +""
43
+ while read.bytesize < BoundedFile::LIMIT && io.wait_readable(@wait)
44
+ part = next_part(io, BoundedFile::LIMIT - read.bytesize) or break
45
+ read << part
46
+ end
47
+ read
48
+ end
49
+
50
+ # Up to length bytes that have arrived on io, or nil once it has ended.
51
+ #: (IO, Integer) -> String?
52
+ def next_part(io, length)
53
+ io.readpartial(length)
54
+ rescue EOFError
55
+ nil
56
+ end
57
+ end
58
+ end
59
+ end
@@ -7,8 +7,8 @@ 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 ignores among a project's candidate files: the files, by every ignore file git reads, a global one
10
- # included, so build output and personal settings are named rather than read (#397), and each folder above
11
- # them that git ignores, so a build folder's many copies can be counted once (#406).
10
+ # included, so build output and personal settings are named rather than read, and each folder above
11
+ # them that git ignores, so a build folder's many copies can be counted once.
12
12
  class IgnoredByGit
13
13
  #: (String, Array[String]) -> void
14
14
  def initialize(root, candidates)
@@ -5,7 +5,7 @@ module Principles
5
5
  # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
6
6
  module Data
7
7
  # The fields a schema names, kept from data at every depth. This tool's schemas allow fields they do not
8
- # name, so an older version can read a newer file (D29), but a field a person or agent added must never
8
+ # name, so an older version can read a newer file, but a field a person or agent added must never
9
9
  # be printed back as if this tool had said it.
10
10
  class KnownFields
11
11
  #: (Hash[String, untyped]) -> void
@@ -6,7 +6,7 @@ module Principles
6
6
  module Data
7
7
  # A path in the project, as its symbolic links lead it. A host may load an instruction file through a link, and
8
8
  # git holds a link as the name of its target, so the text at path depends on every link on the way, a linked
9
- # folder's included, and on the file they lead to (#695).
9
+ # folder's included, and on the file they lead to.
10
10
  class LinkedPath
11
11
  # The most links followed, as an operating system caps them, so a cycle ends.
12
12
  MOST_LINKS = 40
@@ -28,7 +28,7 @@ module Principles
28
28
  @directory.ids
29
29
  end
30
30
 
31
- # Which of the folder and its earlier name hold this subfolder (#536).
31
+ # Which of the folder and its earlier name hold this subfolder.
32
32
  #: () -> Array[String]
33
33
  def held_in
34
34
  @directory.held_in
@@ -75,7 +75,7 @@ module Principles
75
75
  File.join(PrinciplesSubfolder::FOLDER, "maps", "#{id}.json")
76
76
  end
77
77
 
78
- # Where map id was kept before the folder took its name now, so history reads it at earlier commits (#536).
78
+ # Where map id was kept before the folder took its name now, so history reads it at earlier commits.
79
79
  #: (String) -> String
80
80
  def earlier_relative(id)
81
81
  File.join(PrinciplesSubfolder::EARLIER_FOLDER, "maps", "#{id}.json")