principles 0.1.3 → 0.1.5

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 (312) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +151 -1
  3. data/README.md +10 -6
  4. data/exe/principles +1 -1
  5. data/lib/principles/cli.rb +9 -10
  6. data/lib/principles/command_line.rb +15 -6
  7. data/lib/principles/command_routes.rb +18 -2
  8. data/lib/principles/controllers/acknowledgement.rb +19 -4
  9. data/lib/principles/controllers/acknowledgements.rb +43 -12
  10. data/lib/principles/controllers/after_commit_report.rb +15 -2
  11. data/lib/principles/controllers/assessment.rb +7 -3
  12. data/lib/principles/controllers/audit.rb +17 -8
  13. data/lib/principles/controllers/audit_completion.rb +34 -9
  14. data/lib/principles/controllers/carrier_edit_report.rb +40 -0
  15. data/lib/principles/controllers/carrier_practices.rb +26 -0
  16. data/lib/principles/controllers/command.rb +36 -5
  17. data/lib/principles/controllers/context_budget.rb +61 -0
  18. data/lib/principles/controllers/correction.rb +15 -5
  19. data/lib/principles/controllers/full_audit_request.rb +38 -42
  20. data/lib/principles/controllers/inventory.rb +78 -71
  21. data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
  22. data/lib/principles/controllers/member_addition.rb +20 -5
  23. data/lib/principles/controllers/member_entries.rb +50 -39
  24. data/lib/principles/controllers/member_entry_changes.rb +71 -0
  25. data/lib/principles/controllers/member_problems_report.rb +26 -6
  26. data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
  27. data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
  28. data/lib/principles/controllers/members_to_assess.rb +35 -8
  29. data/lib/principles/controllers/meta_principle_setup.rb +12 -4
  30. data/lib/principles/controllers/open_correction.rb +3 -2
  31. data/lib/principles/controllers/parts_to_read.rb +48 -6
  32. data/lib/principles/controllers/plugin_member_addition.rb +48 -0
  33. data/lib/principles/controllers/principle_listing.rb +84 -0
  34. data/lib/principles/controllers/request_logging.rb +65 -0
  35. data/lib/principles/controllers/running_tool.rb +55 -15
  36. data/lib/principles/controllers/session_start_report.rb +26 -2
  37. data/lib/principles/data/branches_bringing_in.rb +52 -0
  38. data/lib/principles/data/captured_requests.rb +118 -0
  39. data/lib/principles/data/carrier_page_markers.rb +38 -0
  40. data/lib/principles/data/changes_since.rb +56 -0
  41. data/lib/principles/data/claude_code_home.rb +75 -0
  42. data/lib/principles/data/command-steps.json +139 -23
  43. data/lib/principles/data/decoded_leaf.rb +63 -0
  44. data/lib/principles/data/head_reflog.rb +13 -2
  45. data/lib/principles/data/kept_line.rb +39 -0
  46. data/lib/principles/data/known_marketplaces.rb +50 -0
  47. data/lib/principles/data/logged_request_matches.rb +144 -0
  48. data/lib/principles/data/logged_request_scan.rb +188 -0
  49. data/lib/principles/data/map_files.rb +18 -4
  50. data/lib/principles/data/plugin_folder.rb +85 -0
  51. data/lib/principles/data/plugin_registry.rb +73 -0
  52. data/lib/principles/data/principles_store.rb +49 -0
  53. data/lib/principles/data/project_files.rb +15 -0
  54. data/lib/principles/data/ran.rb +25 -0
  55. data/lib/principles/data/raw_request_filter.rb +61 -0
  56. data/lib/principles/data/repository.rb +29 -27
  57. data/lib/principles/data/request_logging_folder.rb +135 -0
  58. data/lib/principles/data/request_shape.rb +33 -0
  59. data/lib/principles/data/running_version.rb +1 -1
  60. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
  61. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
  62. data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
  63. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  64. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  65. data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
  66. data/lib/principles/data/schemas/member-map.schema.json +12 -1
  67. data/lib/principles/data/settings_env_keys.rb +26 -0
  68. data/lib/principles/data/string_counts.rb +39 -0
  69. data/lib/principles/data/tools_on_path.rb +25 -0
  70. data/lib/principles/data/user_request_logging_folder.rb +73 -0
  71. data/lib/principles/invocation_options.rb +5 -3
  72. data/lib/principles/launch.rb +29 -10
  73. data/lib/principles/models/acknowledged_check.rb +11 -1
  74. data/lib/principles/models/acknowledgement.rb +5 -0
  75. data/lib/principles/models/acknowledgement_refusal.rb +20 -11
  76. data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
  77. data/lib/principles/models/after_commit_input.rb +5 -0
  78. data/lib/principles/models/answer_fields.rb +3 -0
  79. data/lib/principles/models/assessment_basis.rb +10 -3
  80. data/lib/principles/models/audit.rb +10 -10
  81. data/lib/principles/models/audit_record.rb +10 -0
  82. data/lib/principles/models/audit_records.rb +4 -3
  83. data/lib/principles/models/audit_start.rb +9 -0
  84. data/lib/principles/models/authored_locator.rb +33 -0
  85. data/lib/principles/models/candidate_files.rb +23 -3
  86. data/lib/principles/models/candidate_outline.rb +18 -125
  87. data/lib/principles/models/captured_sessions.rb +166 -0
  88. data/lib/principles/models/carrier_edit_input.rb +56 -0
  89. data/lib/principles/models/carrier_kind.rb +79 -0
  90. data/lib/principles/models/carrier_pages_shown.rb +28 -0
  91. data/lib/principles/models/carved_message_bytes.rb +115 -0
  92. data/lib/principles/models/cited_files.rb +12 -3
  93. data/lib/principles/models/context_parts.rb +59 -0
  94. data/lib/principles/models/decided_prior_findings.rb +5 -0
  95. data/lib/principles/models/declared_map_changes.rb +22 -13
  96. data/lib/principles/models/disposition.rb +37 -6
  97. data/lib/principles/models/disposition_placeholders.rb +12 -0
  98. data/lib/principles/models/disposition_text_field.rb +4 -0
  99. data/lib/principles/models/dropped_thinking.rb +73 -0
  100. data/lib/principles/models/feature.rb +54 -0
  101. data/lib/principles/models/finding_outcomes.rb +55 -0
  102. data/lib/principles/models/findings_left_open.rb +9 -11
  103. data/lib/principles/models/head_moves.rb +27 -10
  104. data/lib/principles/models/installed_component.rb +55 -0
  105. data/lib/principles/models/installed_plugins.rb +174 -0
  106. data/lib/principles/models/kept_sessions.rb +34 -0
  107. data/lib/principles/models/locator.rb +8 -0
  108. data/lib/principles/models/logged_request_reach.rb +52 -0
  109. data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
  110. data/lib/principles/models/map_format_raise.rb +28 -0
  111. data/lib/principles/models/mapped_baseline.rb +46 -0
  112. data/lib/principles/models/mapped_principles.rb +2 -1
  113. data/lib/principles/models/maps_holding_file_whole.rb +42 -0
  114. data/lib/principles/models/markdown_text.rb +143 -0
  115. data/lib/principles/models/member.rb +19 -1
  116. data/lib/principles/models/member_entry.rb +56 -0
  117. data/lib/principles/models/member_justification.rb +52 -0
  118. data/lib/principles/models/member_lines.rb +11 -0
  119. data/lib/principles/models/member_loads.rb +17 -2
  120. data/lib/principles/models/member_problems.rb +46 -42
  121. data/lib/principles/models/member_reach.rb +59 -0
  122. data/lib/principles/models/member_snapshots.rb +34 -4
  123. data/lib/principles/models/member_text_as_sent.rb +31 -0
  124. data/lib/principles/models/member_texts.rb +45 -0
  125. data/lib/principles/models/members_by_part.rb +67 -0
  126. data/lib/principles/models/members_in_logged_requests.rb +279 -0
  127. data/lib/principles/models/meta_principle.rb +4 -4
  128. data/lib/principles/models/missing_files.rb +41 -16
  129. data/lib/principles/models/nearly_matching_maps.rb +56 -0
  130. data/lib/principles/models/open_correction.rb +5 -0
  131. data/lib/principles/models/open_finding.rb +4 -3
  132. data/lib/principles/models/outline_budget.rb +10 -1
  133. data/lib/principles/models/outline_item.rb +25 -0
  134. data/lib/principles/models/outline_section.rb +15 -4
  135. data/lib/principles/models/part_named.rb +16 -2
  136. data/lib/principles/models/part_token_estimates.rb +60 -0
  137. data/lib/principles/models/plugin_component.rb +37 -0
  138. data/lib/principles/models/plugin_enabled_in_project_settings.rb +61 -0
  139. data/lib/principles/models/plugin_install.rb +33 -0
  140. data/lib/principles/models/plugin_name.rb +23 -0
  141. data/lib/principles/models/plugin_reference.rb +53 -0
  142. data/lib/principles/models/principle.rb +7 -4
  143. data/lib/principles/models/principle_members.rb +22 -0
  144. data/lib/principles/models/prior_finding_decision.rb +1 -1
  145. data/lib/principles/models/prior_finding_outcomes.rb +12 -1
  146. data/lib/principles/models/problem_report.rb +14 -25
  147. data/lib/principles/models/project.rb +51 -56
  148. data/lib/principles/models/project_harness.rb +48 -0
  149. data/lib/principles/models/project_history.rb +19 -5
  150. data/lib/principles/models/recorded_members.rb +7 -0
  151. data/lib/principles/models/report_hooks.rb +9 -4
  152. data/lib/principles/models/request_channel.rb +62 -0
  153. data/lib/principles/models/request_kind.rb +62 -0
  154. data/lib/principles/models/request_logging.rb +231 -0
  155. data/lib/principles/models/request_logging_guard.rb +84 -0
  156. data/lib/principles/models/request_time.rb +46 -0
  157. data/lib/principles/models/runs_from.rb +0 -5
  158. data/lib/principles/models/script_comments.rb +58 -0
  159. data/lib/principles/models/session_registry.rb +61 -0
  160. data/lib/principles/models/session_start_input.rb +11 -2
  161. data/lib/principles/models/session_trend.rb +36 -0
  162. data/lib/principles/models/stale_request.rb +9 -0
  163. data/lib/principles/models/turn_opening.rb +83 -0
  164. data/lib/principles/models/turn_position.rb +43 -0
  165. data/lib/principles/models/unfixed_part.rb +82 -0
  166. data/lib/principles/models/unresolved_plugin_members.rb +35 -0
  167. data/lib/principles/models/user_logged_requests.rb +90 -0
  168. data/lib/principles/models/user_settings_entries.rb +49 -0
  169. data/lib/principles/models/whole_file_member_read.rb +48 -0
  170. data/lib/principles/models/without_prose.rb +20 -0
  171. data/lib/principles/models/workflow_jobs.rb +92 -0
  172. data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
  173. data/lib/principles/show_principle_options.rb +32 -0
  174. data/lib/principles/version.rb +2 -2
  175. data/lib/principles/views/acknowledged_result.rb +31 -12
  176. data/lib/principles/views/acknowledgement_result.rb +18 -13
  177. data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
  178. data/lib/principles/views/acknowledgements_offered.rb +54 -0
  179. data/lib/principles/views/added_member.rb +22 -6
  180. data/lib/principles/views/answer_in_a_file.rb +15 -15
  181. data/lib/principles/views/assessed_members.rb +19 -8
  182. data/lib/principles/views/assessment_request.rb +14 -6
  183. data/lib/principles/views/audit_changes.rb +14 -8
  184. data/lib/principles/views/audit_findings.rb +34 -0
  185. data/lib/principles/views/audit_result.rb +26 -24
  186. data/lib/principles/views/candidate_files_result.rb +1 -1
  187. data/lib/principles/views/carrier_checks.rb +40 -0
  188. data/lib/principles/views/carrier_edit_denial.rb +36 -0
  189. data/lib/principles/views/carrier_practices_page.rb +49 -0
  190. data/lib/principles/views/completed_audit_findings.rb +33 -0
  191. data/lib/principles/views/completed_audit_next_step.rb +12 -4
  192. data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
  193. data/lib/principles/views/context_budget_result.rb +99 -0
  194. data/lib/principles/views/context_parts.rb +129 -25
  195. data/lib/principles/views/correction_request.rb +32 -17
  196. data/lib/principles/views/disposition_template.rb +35 -0
  197. data/lib/principles/views/first_audit.rb +29 -15
  198. data/lib/principles/views/first_audit_line.rb +4 -5
  199. data/lib/principles/views/hook_setup_result.rb +3 -1
  200. data/lib/principles/views/invocation.rb +14 -5
  201. data/lib/principles/views/last_record_notice.rb +41 -0
  202. data/lib/principles/views/lines_shared_with_member.rb +16 -22
  203. data/lib/principles/views/logged_request_status_meanings.rb +29 -0
  204. data/lib/principles/views/logged_requests_evidence.rb +84 -0
  205. data/lib/principles/views/map_added_to.rb +14 -12
  206. data/lib/principles/views/map_format_raised.rb +28 -0
  207. data/lib/principles/views/map_result.rb +41 -18
  208. data/lib/principles/views/maps_needing_members_or_audit.rb +1 -1
  209. data/lib/principles/views/member_change_since_baseline.rb +4 -0
  210. data/lib/principles/views/member_row.rb +13 -4
  211. data/lib/principles/views/member_sets_overlap.rb +31 -0
  212. data/lib/principles/views/members_a_commit_changed.rb +42 -25
  213. data/lib/principles/views/members_changed_during_audit.rb +27 -0
  214. data/lib/principles/views/members_in_logged_requests_result.rb +123 -0
  215. data/lib/principles/views/members_too_short_to_scan.rb +45 -0
  216. data/lib/principles/views/members_with_no_baseline.rb +6 -6
  217. data/lib/principles/views/meta_principle_result.rb +52 -15
  218. data/lib/principles/views/open_findings_line.rb +31 -92
  219. data/lib/principles/views/parts_index_result.rb +9 -5
  220. data/lib/principles/views/principle_read_result.rb +52 -11
  221. data/lib/principles/views/prior_findings_result.rb +9 -1
  222. data/lib/principles/views/problem_facts.rb +5 -3
  223. data/lib/principles/views/problem_lines.rb +54 -6
  224. data/lib/principles/views/problem_result.rb +7 -15
  225. data/lib/principles/views/prompts/assess-every-member/ask-whether-a-member-seen-only-as-read-is-loaded.md +3 -0
  226. data/lib/principles/views/prompts/assess-every-member/ask-whether-each-reason-holds.md +2 -0
  227. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
  228. data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-against-the-other-principles.md +2 -0
  229. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
  230. data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
  231. data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
  232. data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
  233. data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
  234. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  235. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +6 -1
  236. data/lib/principles/views/prompts/dispose-of-each-finding/read-the-carrier-page-before-fixing.md +1 -0
  237. data/lib/principles/views/prompts/edit-a-carrier/read-the-page-before-the-first-edit.md +2 -0
  238. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
  239. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
  240. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
  241. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
  242. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
  243. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
  244. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
  245. data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
  246. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +49 -51
  247. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-name.md +12 -0
  248. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-reason.md +12 -0
  249. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
  250. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -1
  251. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
  252. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
  253. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  254. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
  255. data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +22 -0
  256. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
  257. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +8 -4
  258. data/lib/principles/views/prompts/learn-what-a-command-does/report-before-carrier-edit.md +13 -0
  259. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
  260. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
  261. data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
  262. data/lib/principles/views/prompts/learn-what-a-command-does/show-context-budget.md +69 -0
  263. data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +4 -4
  264. data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +22 -0
  265. data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +62 -0
  266. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +13 -10
  267. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +16 -16
  268. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
  269. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +17 -17
  270. data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +18 -0
  271. data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +44 -0
  272. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
  273. data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
  274. data/lib/principles/views/prompts/read-what-reached-the-context/explain-user-request-logging-to-the-user.md +10 -0
  275. data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
  276. data/lib/principles/views/prompts/read-what-reached-the-context/what-a-thread-continuation-holds.md +3 -0
  277. data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
  278. data/lib/principles/views/prompts/read-what-reached-the-context/what-each-context-budget-line-says.md +4 -0
  279. data/lib/principles/views/prompts/read-what-reached-the-context/what-each-member-line-says.md +2 -0
  280. data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
  281. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
  282. data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
  283. data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
  284. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-audit-asks-to-acknowledge-or-audit-again.md +1 -0
  285. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-mapping-commit-asks-for-an-audit.md +1 -0
  286. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-pinned-asks-for-an-audit.md +1 -0
  287. data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
  288. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
  289. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
  290. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
  291. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -0
  292. data/lib/principles/views/prompts/set-principles-up/ask-to-set-principles-up-after-an-audit.md +1 -0
  293. data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
  294. data/lib/principles/views/prompts/set-principles-up/map-the-enabling-line-at-no-edit.md +3 -0
  295. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -2
  296. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +4 -2
  297. data/lib/principles/views/prompts/set-principles-up/what-the-passage-presumes.md +1 -1
  298. data/lib/principles/views/prompts/set-principles-up/why-set-principles-up.md +1 -0
  299. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
  300. data/lib/principles/views/prompts/start-a-session/ask-to-set-principles-up.md +2 -0
  301. data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
  302. data/lib/principles/views/prompts/start-a-session/name-the-principles-nothing-checks.md +1 -0
  303. data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
  304. data/lib/principles/views/request_logging_result.rb +108 -0
  305. data/lib/principles/views/request_part.rb +10 -4
  306. data/lib/principles/views/request_parts.rb +9 -0
  307. data/lib/principles/views/set_up_offer_line.rb +43 -0
  308. data/lib/principles/views/whole_file_elsewhere.rb +30 -0
  309. metadata +154 -5
  310. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
  311. data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
  312. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +0 -2
@@ -62,7 +62,8 @@ module Principles
62
62
  # What the agent assesses, its other parts, the question and a guide to the answer's shapes.
63
63
  #: () -> Hash[String, untyped]
64
64
  def context
65
- listed = @principle.merge("members" => @members.shown, **@members.shared_check_instructions)
65
+ listed = @principle.merge("members" => @members.shown, **@members.shared_check_instructions,
66
+ **@members.carrier_checks)
66
67
  @parts.shown_after(listed).merge(asked)
67
68
  end
68
69
 
@@ -74,11 +75,15 @@ module Principles
74
75
  # The parts of the context start-audit --part prints alone, each member's with its lines now, by id, from texts,
75
76
  # and each instruction field and the answer to fill as the request prints them; optional names each part the
76
77
  # context lists only when it holds something.
77
- #: (?texts: Hash[String, Array[String]], ?optional: Array[String]) -> ContextParts
78
- def context_parts(texts: {}, optional: [])
78
+ #: (?texts: ContextParts::MemberTexts, ?optional: Array[String]) -> ContextParts
79
+ def context_parts(texts: ContextParts::MemberTexts.new({}), optional: [])
79
80
  ContextParts.new(context, instruction_fields:, template:, texts:, optional:)
80
81
  end
81
82
 
83
+ # Why the index gives no bytes, by the name of each part this read left unfilled.
84
+ #: () -> Hash[String, String]
85
+ def bytes_unknown = @parts.bytes_unknown
86
+
82
87
  # The principle the request audits.
83
88
  #: () -> String
84
89
  def principle_id = @principle.fetch("principle_id")
@@ -148,13 +153,16 @@ module Principles
148
153
  end
149
154
 
150
155
  # The question, defining observed only when a member is judged afresh, whose delivery it guides, then whether
151
- # each rule is enforced, which the set's assessment answers afresh at every audit. A record digests the question
152
- # without it, so asking it still carries forward each member's last assessment, which never answered it.
156
+ # each member's reason holds, and each rule is enforced, which the set's assessment answers afresh at every
157
+ # audit. A record digests the question without those two, so asking them still carries forward each member's
158
+ # last assessment, which never answered them, rather than judging every member of every principle again.
153
159
  #: () -> Instruction
154
160
  def question
155
161
  assess, observed = AssessmentRequest.question_paragraphs
162
+ reasons = Prompts.text("assess-every-member/ask-whether-each-reason-holds")
156
163
  enforced = Prompts.text("assess-every-member/ask-whether-each-rule-is-enforced")
157
- Instruction.new("question", [[assess, true], [observed, @members.judged_afresh?], [enforced, true]])
164
+ Instruction.new("question", [[assess, true], [observed, @members.judged_afresh?], [reasons, true],
165
+ [enforced, true]])
158
166
  end
159
167
 
160
168
  # Why each member with judge_because is judged afresh, explaining only the values the members carry, so the
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "audit_commit"
5
5
  require_relative "landed_since_base"
6
+ require_relative "members_changed_during_audit"
6
7
  require_relative "principle_with_changed_members"
7
8
  require_relative "shell_word"
8
9
 
@@ -11,15 +12,16 @@ module Principles
11
12
  module Views
12
13
  # What a completed audit changed in the project, as its result prints it: the files to commit, in git what
13
14
  # landed since the base commit, as LandedSinceBase prints it, each other principle whose members its fixes changed,
14
- # each file the record cites that no longer exists, and each member added to the map during the
15
- # audit, which no assessment read, so the next full audit assesses it (T69).
15
+ # each file the record cites that no longer exists, and the audited principle's members that changed during the
16
+ # audit, as MembersChangedDuringAudit prints them.
16
17
  class AuditChanges
17
18
  #: (files_to_commit: Array[String], ?landed: LandedSinceBase?,
18
19
  #| ?other_changed: Array[PrincipleWithChangedMembers], ?cited_files_missing: Array[String],
19
- #| ?added: Array[String]) -> void
20
- def initialize(files_to_commit:, landed: nil, other_changed: [], cited_files_missing: [], added: [])
20
+ #| ?members_changed: MembersChangedDuringAudit) -> void
21
+ def initialize(files_to_commit:, landed: nil, other_changed: [], cited_files_missing: [],
22
+ members_changed: MembersChangedDuringAudit.new)
21
23
  @files_to_commit = files_to_commit
22
- @added = added
24
+ @members_changed = members_changed
23
25
  @landed = landed
24
26
  @other_changed = other_changed
25
27
  @cited_files_missing = cited_files_missing
@@ -33,12 +35,16 @@ module Principles
33
35
  #: Array[PrincipleWithChangedMembers]
34
36
  attr_reader :other_changed
35
37
 
36
- # The fields as printed; the members added and the cited files missing, what landed since the base only in
37
- # git, where it is given, and the other principles, each only when there are some.
38
+ # The audited principle's members that changed during the audit, which the next step asks to audit again.
39
+ #: MembersChangedDuringAudit
40
+ attr_reader :members_changed
41
+
42
+ # The fields as printed; the members changed during the audit and the cited files missing, what landed since
43
+ # the base only in git, where it is given, and the other principles, each only when there are some.
38
44
  #: () -> Hash[String, untyped]
39
45
  def to_h
40
46
  printed = { "files_to_commit" => @files_to_commit } #: Hash[String, untyped]
41
- printed = printed.merge("members_added_awaiting_assessment" => @added) unless @added.empty?
47
+ printed = printed.merge(@members_changed.to_h)
42
48
  printed = printed.merge("cited_files_missing" => @cited_files_missing) unless @cited_files_missing.empty?
43
49
  printed = printed.merge(@landed.to_h) if @landed
44
50
  others = @other_changed.map(&:to_h)
@@ -0,0 +1,34 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # show-audit --findings: only the findings of an audit record, and of the last completed record an open one
8
+ # keeps, each placed by its status, base_commit and audited_at, for an agent that needs what the last audit found
9
+ # without every member it judged.
10
+ class AuditFindings
11
+ # record is the record as show-audit prints it whole; kept, the last completed record an open one keeps, as
12
+ # printed whole, or nil.
13
+ #: (Hash[String, untyped], Hash[String, untyped]?) -> void
14
+ def initialize(record, kept)
15
+ @record = record
16
+ @kept = kept
17
+ freeze
18
+ end
19
+
20
+ #: () -> Hash[String, untyped]
21
+ def to_h
22
+ shown = { "principle_id" => @record.fetch("principle_id"), **placing(@record) }
23
+ @kept ? shown.merge("last_completed" => placing(@kept)) : shown
24
+ end
25
+
26
+ private
27
+
28
+ # record's findings, with its status, the commit it began from, whose text its evidence was read in, and
29
+ # audited_at, which place them.
30
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
31
+ def placing(record) = record.slice("status", "base_commit", "audited_at", "findings")
32
+ end
33
+ end
34
+ end
@@ -5,6 +5,7 @@ require_relative "assessment_request"
5
5
  require_relative "answer_in_a_file"
6
6
  require_relative "answered_request"
7
7
  require_relative "audit_changes"
8
+ require_relative "completed_audit_findings"
8
9
  require_relative "completed_audit_next_step"
9
10
  require_relative "correction_request"
10
11
  require_relative "invocation"
@@ -121,18 +122,17 @@ module Principles
121
122
  "next_action" => request.to_fill_by_hand(@invocation))
122
123
  end
123
124
 
124
- # A completed audit: its resolved and open findings, the files to commit and, in git, each changed
125
+ # A completed audit: its findings by what became of them, the files to commit and, in git, each changed
125
126
  # member's commits since the base commit and the command that commits those files alone, each prior
126
127
  # finding's decision, and the next step. The command's subject states only what the audit did, which the
127
128
  # agent rewords to its project's convention.
128
- #: (principle_id: String, resolved: Array[untyped], open: Array[untyped], changes: AuditChanges,
129
+ #: (principle_id: String, findings: CompletedAuditFindings, changes: AuditChanges,
129
130
  #| decisions: PriorFindingDecisionsResult) -> Hash[String, untyped]
130
- def completion(principle_id:, resolved:, open:, changes:, decisions:)
131
+ def completion(principle_id:, findings:, changes:, decisions:)
131
132
  changed = changes.to_h
132
- commit = changes.commit("Audit #{principle_id}: #{resolved.length} resolved, #{open.length} open",
133
- @invocation.project)
134
- output = { "status" => "audit_completed", "principle_id" => principle_id, "resolved_findings" => resolved,
135
- "open_findings" => open, "files_to_commit" => changes.files_to_commit,
133
+ commit = changes.commit(findings.subject(principle_id), @invocation.project)
134
+ output = { "status" => "audit_completed", "principle_id" => principle_id, **findings.to_h,
135
+ "files_to_commit" => changes.files_to_commit,
136
136
  "limits" => Prompts.text("report-the-completed-audit/what-completion-means"),
137
137
  **changed.except("files_to_commit"), **commit.fields }
138
138
  next_action = CompletedAuditNextStep.new(@invocation).to_s(principle_id, changes, commit)
@@ -140,28 +140,30 @@ module Principles
140
140
  "full_record" => @invocation.in_project("show-audit", principle_id))
141
141
  end
142
142
 
143
- # completed, a completed audit's result, offering to set principles up after its next_action, as it does
144
- # while nothing keeps them held between audits, and with hooks, the hook entries that report between them.
143
+ # completed, a completed audit's result, as it is while nothing in the project has every session check the
144
+ # principles: with set_up_offer, the question the agent puts to its user and the command a yes runs, in a field
145
+ # of its own, since a line among next_action's went unasked (019 F6), and with hooks, the hook entries that
146
+ # report between audits after its next_action. The offer holds no state, so each later audit asks the same
147
+ # (019 F7).
145
148
  #: (Hash[String, untyped], hooks: bool) -> Hash[String, untyped]
146
149
  def offering_set_up(completed, hooks:)
147
- offers = [Prompts.text("set-principles-up/keep-them-held-between-audits",
148
- command: @invocation.in_project("show-meta-principle-passage"))]
149
- offers << ReportHooksOffer.new(@invocation).to_s if hooks
150
- completed.merge("next_action" => [completed.fetch("next_action"), *offers].join("\n"))
151
- end
150
+ why = Prompts.text("set-principles-up/why-set-principles-up")
151
+ offer = { "ask_the_user" => Prompts.text("set-principles-up/ask-to-set-principles-up-after-an-audit", why:),
152
+ "on_yes" => @invocation.in_project("show-meta-principle-passage") }
153
+ offered = completed.merge("set_up_offer" => offer)
154
+ return offered unless hooks
152
155
 
153
- # The notice start-audit adds when the last audit's record is not committed.
154
- #: (String) -> String
155
- def uncommitted_record_notice(file)
156
- "The last audit's record, #{file}, is not committed. Commit it, so the project keeps it."
156
+ hooks_offer = ReportHooksOffer.new(@invocation).to_s
157
+ offered.merge("next_action" => [completed.fetch("next_action"), hooks_offer].join("\n"))
157
158
  end
158
159
 
159
- # The notice start-audit adds, in git, when the last audit's record is open: its correction completes it, so it
160
- # is never committed.
161
- #: (String) -> String
162
- def open_record_notice(file)
163
- "The last audit's record, #{file}, holds an open audit, waiting on its correction. Do not commit it: submit " \
164
- "that correction, or answer this request, which replaces it, or discard it with `git restore #{file}`."
160
+ # completed, a completed first full audit's result, with the line after its next_action that names the command
161
+ # turning request logging on.
162
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
163
+ def offering_request_logging(completed)
164
+ line = Prompts.text("read-what-reached-the-context/see-whether-members-reach-the-agent",
165
+ command: @invocation.in_project("turn-on-request-logging"))
166
+ completed.merge("next_action" => [completed.fetch("next_action"), line].join("\n"))
165
167
  end
166
168
 
167
169
  # Wraps a known judgement request with this run's project and answer command.
@@ -107,7 +107,7 @@ module Principles
107
107
  create = @invocation.in_project("create-principle", usage: CREATE_PRINCIPLE_USAGE)
108
108
  return create if existing_maps.empty?
109
109
 
110
- add = @invocation.in_project("add-member", usage: "ID PATH --role ROLE")
110
+ add = @invocation.in_project("add-member", usage: "ID PATH --role ROLE --name NAME --reason REASON")
111
111
  "To add a member to an existing principle: #{add}\nTo map a distinct principle: #{create}"
112
112
  end
113
113
 
@@ -0,0 +1,40 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "carrier_practices_page"
5
+ require_relative "invocation"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # The checks a request prints where the agent judges or edits members: one for each carrier kind the members are
11
+ # in, once, with the ids of the members it is for and its page's size, then once for them all the command that
12
+ # prints a kind's page, which differs between kinds only in its last word.
13
+ class CarrierChecks
14
+ # kinds is each member's carrier kind by its id, in the order the request lists the members.
15
+ #: (Hash[String, String], Invocation) -> void
16
+ def initialize(kinds, invocation)
17
+ @kinds = kinds
18
+ @invocation = invocation
19
+ freeze
20
+ end
21
+
22
+ # One check per kind, in the order its first member is listed, and the page command; nothing for no members.
23
+ #: () -> Hash[String, untyped]
24
+ def to_h
25
+ return {} if @kinds.empty?
26
+
27
+ { "checks" => @kinds.group_by { _2 }.map { |kind, members| check(kind, members.map(&:first)) },
28
+ "page_command" => @invocation.in_project("show-carrier-practices", usage: "CARRIER") }
29
+ end
30
+
31
+ private
32
+
33
+ #: (String, Array[String]) -> Hash[String, untyped]
34
+ def check(kind, member_ids)
35
+ page = CarrierPracticesPage.of(kind)
36
+ { "carrier" => kind, "member_ids" => member_ids, "check" => page.check, "page_bytes" => page.body.bytesize }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "invocation"
6
+ require_relative "prompts"
7
+ require_relative "problem_lines"
8
+
9
+ module Principles
10
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
11
+ module Views
12
+ # report-before-carrier-edit's output: the PreToolUse hook's JSON denying an edit once, its reason naming the
13
+ # kind's practices page and asking for the same edit again, since a denial's reason reaches the model before it
14
+ # retries, where added context arrives only after the tool ran; or nothing, which lets the edit through.
15
+ class CarrierEditDenial
16
+ # Nothing on stdout, exit 0: the edit goes ahead.
17
+ NOTHING = Lines.new(stdout: "", stderr: "", status: 0).freeze #: Lines
18
+
19
+ #: (Invocation) -> void
20
+ def initialize(invocation)
21
+ @invocation = invocation
22
+ freeze
23
+ end
24
+
25
+ # The denial of an edit of a file of kind.
26
+ #: (String) -> Lines
27
+ def denied(kind)
28
+ reason = Prompts.text("edit-a-carrier/read-the-page-before-the-first-edit",
29
+ kind:, command: @invocation.in_project("show-carrier-practices", kind))
30
+ output = { "hookSpecificOutput" => { "hookEventName" => "PreToolUse", "permissionDecision" => "deny",
31
+ "permissionDecisionReason" => reason } }
32
+ Lines.new(stdout: "#{JSON.generate(output)}\n", stderr: "", status: 0)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,49 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "prompts"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # One carrier kind's practices page: a title, then the kind's check, the one paragraph a request prints where the
10
+ # agent judges or edits a member of the kind, then the depth show-carrier-practices prints. The check opens the
11
+ # page, so the two have one owner.
12
+ class CarrierPracticesPage
13
+ # Each kind's page, as CarrierKind names the kinds.
14
+ PAGES = {
15
+ "instructions" =>
16
+ -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-instruction-files") },
17
+ "rule" => -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-rule-files") },
18
+ "skill" => -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-skills") },
19
+ "subagent" => -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-subagent-definitions") },
20
+ "hook_configuration" =>
21
+ -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-hook-configuration") },
22
+ "hook_script" => -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-hook-scripts") },
23
+ "none" => -> { Prompts.markdown("follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads") }
24
+ }.freeze #: Hash[String, ^() -> String]
25
+
26
+ # The page of kind, one of PAGES' keys.
27
+ #: (String) -> CarrierPracticesPage
28
+ def self.of(kind) = new(PAGES.fetch(kind).call)
29
+
30
+ #: (String) -> void
31
+ def initialize(markdown)
32
+ @body = markdown.strip #: String
33
+ freeze
34
+ end
35
+
36
+ # The page, as show-carrier-practices prints it.
37
+ #: String
38
+ attr_reader :body
39
+
40
+ # show-carrier-practices' result for kind, this page's.
41
+ #: (String) -> Hash[String, untyped]
42
+ def result(kind) = { "carrier" => kind, "practices" => body, "wrote" => [] }
43
+
44
+ # The page's opening paragraph after its title, its lines joined, as a request prints it.
45
+ #: () -> String
46
+ def check = body.split(/\n{2,}/).fetch(1).gsub(/\s*\n\s*/, " ")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # A completed audit's findings by what became of them, as the record it writes holds them: the ids it resolved
8
+ # and those it leaves open, deferred or accepted. Its fields and its default commit subject count the same ids,
9
+ # so they cannot disagree.
10
+ class CompletedAuditFindings
11
+ #: (resolved: Array[String], deferred: Array[String], accepted: Array[String]) -> void
12
+ def initialize(resolved:, deferred:, accepted:)
13
+ @resolved = resolved
14
+ @deferred = deferred
15
+ @accepted = accepted
16
+ freeze
17
+ end
18
+
19
+ # The fields as printed.
20
+ #: () -> Hash[String, Array[String]]
21
+ def to_h
22
+ { "resolved_findings" => @resolved, "deferred_findings" => @deferred, "accepted_findings" => @accepted }
23
+ end
24
+
25
+ # The default commit subject for principle_id's audit, counting each kind.
26
+ #: (String) -> String
27
+ def subject(principle_id)
28
+ "Audit #{principle_id}: #{@resolved.length} resolved, #{@deferred.length} deferred, " \
29
+ "#{@accepted.length} accepted"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -10,7 +10,7 @@ module Principles
10
10
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
11
11
  module Views
12
12
  # A completed audit's next step, from what it changed and how to commit it: commit and report, re-audit each other
13
- # principle its fixes changed, and audit this principle again after its members change.
13
+ # principle its fixes changed, and, when its members changed during the audit, audit this principle again.
14
14
  class CompletedAuditNextStep
15
15
  #: (Invocation) -> void
16
16
  def initialize(invocation)
@@ -21,13 +21,21 @@ module Principles
21
21
  # The next step after principle id's audit completed with changes, committed as commit says.
22
22
  #: (String, AuditChanges, AuditCommit | AuditCommit::ByHand) -> String
23
23
  def to_s(id, changes, commit)
24
- "#{commit.next_step} report the outcome to the project's owner.\n" \
25
- "#{others_changed(changes.other_changed)}" \
26
- "After members change, audit this principle again: #{@invocation.in_project("start-audit", id)}"
24
+ ["#{commit.next_step} report the outcome to the project's owner.\n",
25
+ others_changed(changes.other_changed), again(id, changes.members_changed)].join.chomp
27
26
  end
28
27
 
29
28
  private
30
29
 
30
+ # The line asking for principle id's audit again when its members changed during the audit; nothing when none
31
+ # did, since nothing then needs a second audit.
32
+ #: (String, MembersChangedDuringAudit) -> String
33
+ def again(id, members_changed)
34
+ return "" unless members_changed.any?
35
+
36
+ "After members change, audit this principle again: #{@invocation.in_project("start-audit", id)}"
37
+ end
38
+
31
39
  # The other principles whose members this audit's fixes changed, each to re-audit, or one member's edit
32
40
  # to acknowledge; the agent judges which. Nothing when there are none.
33
41
  #: (Array[PrincipleWithChangedMembers]) -> String
@@ -22,6 +22,10 @@ module Principles
22
22
  "(consecutive_sections_elsewhere). These maps have no completed full audit. " \
23
23
  "Do they carry one rule or distinct principles? Location alone does not decide. "
24
24
  end
25
+
26
+ # Its own question asks whether they carry one rule, so it does not ask AddedMember's scope-or-join question.
27
+ #: () -> bool
28
+ def asks_scope_or_join? = false
25
29
  end
26
30
  end
27
31
  end
@@ -0,0 +1,99 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "problem_lines"
5
+ require_relative "prompts"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # Each session's turn openings, each with its context's bytes and the host's count of its input tokens, its
11
+ # trend, and the files the read wrote: none; or, with --short, a line a session.
12
+ class ContextBudgetResult
13
+ # How many principles a --short line names by their members' bytes, the largest first.
14
+ LARGEST = 3 #: Integer
15
+
16
+ # Each session as plain values: its id, its trend, its last turn opening with the members it sent, the members
17
+ # its turn openings sent all told, and, under --session, each turn opening.
18
+ #: type session = [String?, Hash[String, untyped], Hash[String, untyped], Array[Hash[String, untyped]],
19
+ #| Array[Hash[String, untyped]]?]
20
+
21
+ # The bare command's form, bounded by sessions rather than turns, or with the session's turn openings listed.
22
+ #: (Array[session]) -> Hash[String, untyped]
23
+ def result(sessions)
24
+ listed = sessions.map do |id, trend, last, members, openings|
25
+ { "session_id" => id, "trend" => trend, "last_turn_opening" => last,
26
+ "members_across_turn_openings" => members,
27
+ **({ "turn_openings" => openings } if openings) }
28
+ end
29
+ { "status" => "context_budget_shown", "sessions" => listed, "wrote" => [] }
30
+ end
31
+
32
+ # The same facts as a line a session, with a line first saying what each line holds.
33
+ #: (Array[session]) -> Lines
34
+ def short(sessions)
35
+ lines = [Prompts.text("read-what-reached-the-context/what-each-context-budget-line-says"),
36
+ *sessions.map { |id, trend, last, _, _| session_line(id, trend, last) }]
37
+ Lines.new(stdout: lines.map { "#{it}\n" }.join, stderr: "", status: 0)
38
+ end
39
+
40
+ private
41
+
42
+ #: (String?, Hash[String, untyped], Hash[String, untyped]) -> String
43
+ def session_line(id, trend, last)
44
+ count = trend.fetch("turn_openings")
45
+ openings = "#{count} turn opening#{"s" unless count == 1}"
46
+ members = "members by principle: #{by_principle(last.fetch("members"))}"
47
+ return "#{unindexed(openings)}; one of them by part: #{by_part(last)}; #{members}" unless id
48
+
49
+ "#{id}: #{openings}, #{trend.fetch("from")} to #{trend.fetch("to")}; " \
50
+ "bytes #{moved(trend.fetch("bytes"))}; input tokens #{moved(trend.fetch("input_tokens"))}; " \
51
+ "last by part: #{by_part(last)}; #{members}"
52
+ end
53
+
54
+ # The turn openings no index line names: with no index line they have no session, send time or response, so
55
+ # no order or tokens. "no session" holds a space, which no session id does, so it is never taken for one.
56
+ #: (String) -> String
57
+ def unindexed(openings)
58
+ "no session: #{openings} that no index line names, so with no send time, order or input tokens"
59
+ end
60
+
61
+ # A count's first and last, and its change, signed.
62
+ #: (Hash[String, Integer?]) -> String
63
+ def moved(counts)
64
+ change = counts["change"]
65
+ signed = change&.positive? ? "+#{change}" : shown(change)
66
+ "#{shown(counts["first"])} -> #{shown(counts["last"])} (#{signed})"
67
+ end
68
+
69
+ # opening's bytes by part, a part's kinds together, in the order its parts are listed.
70
+ #: (Hash[String, untyped]) -> String
71
+ def by_part(opening)
72
+ parts = opening.fetch("parts").group_by { it.fetch("part") }
73
+ parts.map { |part, kinds| "#{part} #{kinds.sum { it.fetch("bytes") }}" }.join(", ")
74
+ end
75
+
76
+ # The bytes of mapped members' text sent, by principle, the largest first, and how many more.
77
+ #: (Array[Hash[String, untyped]]) -> String
78
+ def by_principle(members)
79
+ totals = principle_totals(members)
80
+ return "none" if totals.empty?
81
+
82
+ named = totals.first(LARGEST)
83
+ more = totals.size - named.size
84
+ [*named.map { |principle, bytes| "#{principle} #{bytes}" }, *("#{more} more" if more.positive?)].join(", ")
85
+ end
86
+
87
+ # Each principle among members, with their bytes, the largest first and a tie by id.
88
+ #: (Array[Hash[String, untyped]]) -> Array[[String, Integer]]
89
+ def principle_totals(members)
90
+ totals = members.group_by { it.fetch("principle") }
91
+ .map { |principle, parts| [principle, parts.sum { it.fetch("bytes") }] }
92
+ totals.sort_by { |principle, bytes| [-bytes, principle] }
93
+ end
94
+
95
+ #: (untyped) -> String
96
+ def shown(value) = value.nil? ? "null" : value.to_s
97
+ end
98
+ end
99
+ end