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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +151 -1
- data/README.md +10 -6
- data/exe/principles +1 -1
- data/lib/principles/cli.rb +9 -10
- data/lib/principles/command_line.rb +15 -6
- data/lib/principles/command_routes.rb +18 -2
- data/lib/principles/controllers/acknowledgement.rb +19 -4
- data/lib/principles/controllers/acknowledgements.rb +43 -12
- data/lib/principles/controllers/after_commit_report.rb +15 -2
- data/lib/principles/controllers/assessment.rb +7 -3
- data/lib/principles/controllers/audit.rb +17 -8
- data/lib/principles/controllers/audit_completion.rb +34 -9
- data/lib/principles/controllers/carrier_edit_report.rb +40 -0
- data/lib/principles/controllers/carrier_practices.rb +26 -0
- data/lib/principles/controllers/command.rb +36 -5
- data/lib/principles/controllers/context_budget.rb +61 -0
- data/lib/principles/controllers/correction.rb +15 -5
- data/lib/principles/controllers/full_audit_request.rb +38 -42
- data/lib/principles/controllers/inventory.rb +78 -71
- data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
- data/lib/principles/controllers/member_addition.rb +20 -5
- data/lib/principles/controllers/member_entries.rb +50 -39
- data/lib/principles/controllers/member_entry_changes.rb +71 -0
- data/lib/principles/controllers/member_problems_report.rb +26 -6
- data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
- data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
- data/lib/principles/controllers/members_to_assess.rb +35 -8
- data/lib/principles/controllers/meta_principle_setup.rb +12 -4
- data/lib/principles/controllers/open_correction.rb +3 -2
- data/lib/principles/controllers/parts_to_read.rb +48 -6
- data/lib/principles/controllers/plugin_member_addition.rb +48 -0
- data/lib/principles/controllers/principle_listing.rb +84 -0
- data/lib/principles/controllers/request_logging.rb +65 -0
- data/lib/principles/controllers/running_tool.rb +55 -15
- data/lib/principles/controllers/session_start_report.rb +26 -2
- data/lib/principles/data/branches_bringing_in.rb +52 -0
- data/lib/principles/data/captured_requests.rb +118 -0
- data/lib/principles/data/carrier_page_markers.rb +38 -0
- data/lib/principles/data/changes_since.rb +56 -0
- data/lib/principles/data/claude_code_home.rb +75 -0
- data/lib/principles/data/command-steps.json +139 -23
- data/lib/principles/data/decoded_leaf.rb +63 -0
- data/lib/principles/data/head_reflog.rb +13 -2
- data/lib/principles/data/kept_line.rb +39 -0
- data/lib/principles/data/known_marketplaces.rb +50 -0
- data/lib/principles/data/logged_request_matches.rb +144 -0
- data/lib/principles/data/logged_request_scan.rb +188 -0
- data/lib/principles/data/map_files.rb +18 -4
- data/lib/principles/data/plugin_folder.rb +85 -0
- data/lib/principles/data/plugin_registry.rb +73 -0
- data/lib/principles/data/principles_store.rb +49 -0
- data/lib/principles/data/project_files.rb +15 -0
- data/lib/principles/data/ran.rb +25 -0
- data/lib/principles/data/raw_request_filter.rb +61 -0
- data/lib/principles/data/repository.rb +29 -27
- data/lib/principles/data/request_logging_folder.rb +135 -0
- data/lib/principles/data/request_shape.rb +33 -0
- data/lib/principles/data/running_version.rb +1 -1
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
- data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
- data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
- data/lib/principles/data/schemas/member-map.schema.json +12 -1
- data/lib/principles/data/settings_env_keys.rb +26 -0
- data/lib/principles/data/string_counts.rb +39 -0
- data/lib/principles/data/tools_on_path.rb +25 -0
- data/lib/principles/data/user_request_logging_folder.rb +73 -0
- data/lib/principles/invocation_options.rb +5 -3
- data/lib/principles/launch.rb +29 -10
- data/lib/principles/models/acknowledged_check.rb +11 -1
- data/lib/principles/models/acknowledgement.rb +5 -0
- data/lib/principles/models/acknowledgement_refusal.rb +20 -11
- data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
- data/lib/principles/models/after_commit_input.rb +5 -0
- data/lib/principles/models/answer_fields.rb +3 -0
- data/lib/principles/models/assessment_basis.rb +10 -3
- data/lib/principles/models/audit.rb +10 -10
- data/lib/principles/models/audit_record.rb +10 -0
- data/lib/principles/models/audit_records.rb +4 -3
- data/lib/principles/models/audit_start.rb +9 -0
- data/lib/principles/models/authored_locator.rb +33 -0
- data/lib/principles/models/candidate_files.rb +23 -3
- data/lib/principles/models/candidate_outline.rb +18 -125
- data/lib/principles/models/captured_sessions.rb +166 -0
- data/lib/principles/models/carrier_edit_input.rb +56 -0
- data/lib/principles/models/carrier_kind.rb +79 -0
- data/lib/principles/models/carrier_pages_shown.rb +28 -0
- data/lib/principles/models/carved_message_bytes.rb +115 -0
- data/lib/principles/models/cited_files.rb +12 -3
- data/lib/principles/models/context_parts.rb +59 -0
- data/lib/principles/models/decided_prior_findings.rb +5 -0
- data/lib/principles/models/declared_map_changes.rb +22 -13
- data/lib/principles/models/disposition.rb +37 -6
- data/lib/principles/models/disposition_placeholders.rb +12 -0
- data/lib/principles/models/disposition_text_field.rb +4 -0
- data/lib/principles/models/dropped_thinking.rb +73 -0
- data/lib/principles/models/feature.rb +54 -0
- data/lib/principles/models/finding_outcomes.rb +55 -0
- data/lib/principles/models/findings_left_open.rb +9 -11
- data/lib/principles/models/head_moves.rb +27 -10
- data/lib/principles/models/installed_component.rb +55 -0
- data/lib/principles/models/installed_plugins.rb +174 -0
- data/lib/principles/models/kept_sessions.rb +34 -0
- data/lib/principles/models/locator.rb +8 -0
- data/lib/principles/models/logged_request_reach.rb +52 -0
- data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
- data/lib/principles/models/map_format_raise.rb +28 -0
- data/lib/principles/models/mapped_baseline.rb +46 -0
- data/lib/principles/models/mapped_principles.rb +2 -1
- data/lib/principles/models/maps_holding_file_whole.rb +42 -0
- data/lib/principles/models/markdown_text.rb +143 -0
- data/lib/principles/models/member.rb +19 -1
- data/lib/principles/models/member_entry.rb +56 -0
- data/lib/principles/models/member_justification.rb +52 -0
- data/lib/principles/models/member_lines.rb +11 -0
- data/lib/principles/models/member_loads.rb +17 -2
- data/lib/principles/models/member_problems.rb +46 -42
- data/lib/principles/models/member_reach.rb +59 -0
- data/lib/principles/models/member_snapshots.rb +34 -4
- data/lib/principles/models/member_text_as_sent.rb +31 -0
- data/lib/principles/models/member_texts.rb +45 -0
- data/lib/principles/models/members_by_part.rb +67 -0
- data/lib/principles/models/members_in_logged_requests.rb +279 -0
- data/lib/principles/models/meta_principle.rb +4 -4
- data/lib/principles/models/missing_files.rb +41 -16
- data/lib/principles/models/nearly_matching_maps.rb +56 -0
- data/lib/principles/models/open_correction.rb +5 -0
- data/lib/principles/models/open_finding.rb +4 -3
- data/lib/principles/models/outline_budget.rb +10 -1
- data/lib/principles/models/outline_item.rb +25 -0
- data/lib/principles/models/outline_section.rb +15 -4
- data/lib/principles/models/part_named.rb +16 -2
- data/lib/principles/models/part_token_estimates.rb +60 -0
- data/lib/principles/models/plugin_component.rb +37 -0
- data/lib/principles/models/plugin_enabled_in_project_settings.rb +61 -0
- data/lib/principles/models/plugin_install.rb +33 -0
- data/lib/principles/models/plugin_name.rb +23 -0
- data/lib/principles/models/plugin_reference.rb +53 -0
- data/lib/principles/models/principle.rb +7 -4
- data/lib/principles/models/principle_members.rb +22 -0
- data/lib/principles/models/prior_finding_decision.rb +1 -1
- data/lib/principles/models/prior_finding_outcomes.rb +12 -1
- data/lib/principles/models/problem_report.rb +14 -25
- data/lib/principles/models/project.rb +51 -56
- data/lib/principles/models/project_harness.rb +48 -0
- data/lib/principles/models/project_history.rb +19 -5
- data/lib/principles/models/recorded_members.rb +7 -0
- data/lib/principles/models/report_hooks.rb +9 -4
- data/lib/principles/models/request_channel.rb +62 -0
- data/lib/principles/models/request_kind.rb +62 -0
- data/lib/principles/models/request_logging.rb +231 -0
- data/lib/principles/models/request_logging_guard.rb +84 -0
- data/lib/principles/models/request_time.rb +46 -0
- data/lib/principles/models/runs_from.rb +0 -5
- data/lib/principles/models/script_comments.rb +58 -0
- data/lib/principles/models/session_registry.rb +61 -0
- data/lib/principles/models/session_start_input.rb +11 -2
- data/lib/principles/models/session_trend.rb +36 -0
- data/lib/principles/models/stale_request.rb +9 -0
- data/lib/principles/models/turn_opening.rb +83 -0
- data/lib/principles/models/turn_position.rb +43 -0
- data/lib/principles/models/unfixed_part.rb +82 -0
- data/lib/principles/models/unresolved_plugin_members.rb +35 -0
- data/lib/principles/models/user_logged_requests.rb +90 -0
- data/lib/principles/models/user_settings_entries.rb +49 -0
- data/lib/principles/models/whole_file_member_read.rb +48 -0
- data/lib/principles/models/without_prose.rb +20 -0
- data/lib/principles/models/workflow_jobs.rb +92 -0
- data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
- data/lib/principles/show_principle_options.rb +32 -0
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledged_result.rb +31 -12
- data/lib/principles/views/acknowledgement_result.rb +18 -13
- data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
- data/lib/principles/views/acknowledgements_offered.rb +54 -0
- data/lib/principles/views/added_member.rb +22 -6
- data/lib/principles/views/answer_in_a_file.rb +15 -15
- data/lib/principles/views/assessed_members.rb +19 -8
- data/lib/principles/views/assessment_request.rb +14 -6
- data/lib/principles/views/audit_changes.rb +14 -8
- data/lib/principles/views/audit_findings.rb +34 -0
- data/lib/principles/views/audit_result.rb +26 -24
- data/lib/principles/views/candidate_files_result.rb +1 -1
- data/lib/principles/views/carrier_checks.rb +40 -0
- data/lib/principles/views/carrier_edit_denial.rb +36 -0
- data/lib/principles/views/carrier_practices_page.rb +49 -0
- data/lib/principles/views/completed_audit_findings.rb +33 -0
- data/lib/principles/views/completed_audit_next_step.rb +12 -4
- data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
- data/lib/principles/views/context_budget_result.rb +99 -0
- data/lib/principles/views/context_parts.rb +129 -25
- data/lib/principles/views/correction_request.rb +32 -17
- data/lib/principles/views/disposition_template.rb +35 -0
- data/lib/principles/views/first_audit.rb +29 -15
- data/lib/principles/views/first_audit_line.rb +4 -5
- data/lib/principles/views/hook_setup_result.rb +3 -1
- data/lib/principles/views/invocation.rb +14 -5
- data/lib/principles/views/last_record_notice.rb +41 -0
- data/lib/principles/views/lines_shared_with_member.rb +16 -22
- data/lib/principles/views/logged_request_status_meanings.rb +29 -0
- data/lib/principles/views/logged_requests_evidence.rb +84 -0
- data/lib/principles/views/map_added_to.rb +14 -12
- data/lib/principles/views/map_format_raised.rb +28 -0
- data/lib/principles/views/map_result.rb +41 -18
- data/lib/principles/views/maps_needing_members_or_audit.rb +1 -1
- data/lib/principles/views/member_change_since_baseline.rb +4 -0
- data/lib/principles/views/member_row.rb +13 -4
- data/lib/principles/views/member_sets_overlap.rb +31 -0
- data/lib/principles/views/members_a_commit_changed.rb +42 -25
- data/lib/principles/views/members_changed_during_audit.rb +27 -0
- data/lib/principles/views/members_in_logged_requests_result.rb +123 -0
- data/lib/principles/views/members_too_short_to_scan.rb +45 -0
- data/lib/principles/views/members_with_no_baseline.rb +6 -6
- data/lib/principles/views/meta_principle_result.rb +52 -15
- data/lib/principles/views/open_findings_line.rb +31 -92
- data/lib/principles/views/parts_index_result.rb +9 -5
- data/lib/principles/views/principle_read_result.rb +52 -11
- data/lib/principles/views/prior_findings_result.rb +9 -1
- data/lib/principles/views/problem_facts.rb +5 -3
- data/lib/principles/views/problem_lines.rb +54 -6
- data/lib/principles/views/problem_result.rb +7 -15
- data/lib/principles/views/prompts/assess-every-member/ask-whether-a-member-seen-only-as-read-is-loaded.md +3 -0
- data/lib/principles/views/prompts/assess-every-member/ask-whether-each-reason-holds.md +2 -0
- data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
- data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-against-the-other-principles.md +2 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
- data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
- data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
- data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +6 -1
- data/lib/principles/views/prompts/dispose-of-each-finding/read-the-carrier-page-before-fixing.md +1 -0
- data/lib/principles/views/prompts/edit-a-carrier/read-the-page-before-the-first-edit.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +49 -51
- data/lib/principles/views/prompts/learn-what-a-command-does/change-member-name.md +12 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/change-member-reason.md +12 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
- data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +22 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +8 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/report-before-carrier-edit.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-context-budget.md +69 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +4 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +22 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +62 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +13 -10
- data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +16 -16
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +17 -17
- data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +18 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +44 -0
- data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
- data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/explain-user-request-logging-to-the-user.md +10 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-a-thread-continuation-holds.md +3 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-each-context-budget-line-says.md +4 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-each-member-line-says.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
- data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-audit-asks-to-acknowledge-or-audit-again.md +1 -0
- data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-mapping-commit-asks-for-an-audit.md +1 -0
- data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-pinned-asks-for-an-audit.md +1 -0
- data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
- data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
- data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
- data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
- data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -0
- data/lib/principles/views/prompts/set-principles-up/ask-to-set-principles-up-after-an-audit.md +1 -0
- data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
- data/lib/principles/views/prompts/set-principles-up/map-the-enabling-line-at-no-edit.md +3 -0
- data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -2
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +4 -2
- data/lib/principles/views/prompts/set-principles-up/what-the-passage-presumes.md +1 -1
- data/lib/principles/views/prompts/set-principles-up/why-set-principles-up.md +1 -0
- data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
- data/lib/principles/views/prompts/start-a-session/ask-to-set-principles-up.md +2 -0
- data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
- data/lib/principles/views/prompts/start-a-session/name-the-principles-nothing-checks.md +1 -0
- data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
- data/lib/principles/views/request_logging_result.rb +108 -0
- data/lib/principles/views/request_part.rb +10 -4
- data/lib/principles/views/request_parts.rb +9 -0
- data/lib/principles/views/set_up_offer_line.rb +43 -0
- data/lib/principles/views/whole_file_elsewhere.rb +30 -0
- metadata +154 -5
- data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
- data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
- data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +0 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/project_files"
|
|
5
|
+
require_relative "hook_commands"
|
|
6
|
+
require_relative "loaded_files"
|
|
7
|
+
require_relative "member_loads"
|
|
8
|
+
require_relative "plugin_enabled_in_project_settings"
|
|
9
|
+
|
|
10
|
+
module Principles
|
|
11
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
12
|
+
module Models
|
|
13
|
+
# What a host's harness reads from the project's files: the hooks its settings name, when each member loads,
|
|
14
|
+
# the files members load, the settings line that enables the principles plugin, and where a file a hook names
|
|
15
|
+
# sits in the project.
|
|
16
|
+
class ProjectHarness
|
|
17
|
+
#: (Data::ProjectFiles) -> void
|
|
18
|
+
def initialize(files)
|
|
19
|
+
@files = files
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Each member's MemberLoads by id: when each host loads it into context, with the size of what loads, and
|
|
24
|
+
# the project hooks whose commands name its file, read once for them all unless the caller already read them.
|
|
25
|
+
#: (PrincipleMembers, ?HookCommands) -> Hash[String, MemberLoads]
|
|
26
|
+
def member_loads(members, hooks = hook_commands)
|
|
27
|
+
members.to_h { |member| [member.id, MemberLoads.read(@files, member.locator, hooks: hooks)] }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The files members load, each read whole once, with the project's hooks as hooks read them.
|
|
31
|
+
#: (PrincipleMembers, HookCommands) -> LoadedFiles
|
|
32
|
+
def loaded_files(members, hooks) = LoadedFiles.read(@files, members, hooks: hooks)
|
|
33
|
+
|
|
34
|
+
# The command hooks in each of paths present, the project settings files unless others are given.
|
|
35
|
+
#: (?Array[String]) -> HookCommands
|
|
36
|
+
def hook_commands(paths = HookCommands::SETTINGS) = HookCommands.read(@files, paths)
|
|
37
|
+
|
|
38
|
+
# The project settings line that enables the principles plugin for the team, or nil.
|
|
39
|
+
#: () -> PluginEnabledInProjectSettings?
|
|
40
|
+
def plugin_enabled_in_project_settings = PluginEnabledInProjectSettings.read(@files)
|
|
41
|
+
|
|
42
|
+
# absolute's path inside the project, as a hook names the file a call edits, or nil when it is not a full path
|
|
43
|
+
# into it.
|
|
44
|
+
#: (String) -> String?
|
|
45
|
+
def path_in_project(absolute) = @files.path_in_project(absolute)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -49,13 +49,17 @@ module Principles
|
|
|
49
49
|
#: (String) -> bool
|
|
50
50
|
def tracks?(path) = !@repository.inside? || @repository.untracked_including_ignored(through_links([path])).empty?
|
|
51
51
|
|
|
52
|
-
# The project's tmp/ folder, by its full path, when it is there and git ignores
|
|
53
|
-
# never committed; nil otherwise, outside git too.
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
# The project's tmp/ folder, by its full path, when it is there and git ignores a file named answer_name in it,
|
|
53
|
+
# so an answer saved there is never committed; nil otherwise, outside git too. Git is asked about the file, not
|
|
54
|
+
# the folder: a project that ignores tmp/'s contents but tracks a file there, as "/tmp/*" does, has git ignore
|
|
55
|
+
# the file but not tmp/. Asked once for the command, and kept for any later answer_name, since an ignore rule
|
|
56
|
+
# for tmp/ does not turn on one answer file's name.
|
|
57
|
+
#: (String) -> String?
|
|
58
|
+
def ignored_tmp_folder(answer_name)
|
|
56
59
|
return @ignored_tmp_folder if defined?(@ignored_tmp_folder)
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
ignored = @files.folder?("tmp") && @repository.ignores?("tmp/#{answer_name}")
|
|
62
|
+
@ignored_tmp_folder = ("#{@files.root}/tmp" if ignored) #: String?
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
# Whether the project is in git, so it has a history at all.
|
|
@@ -112,6 +116,11 @@ module Principles
|
|
|
112
116
|
#: (String) -> ProjectAtCommit
|
|
113
117
|
def at(commit) = ProjectAtCommit.new(@repository, @files, commit)
|
|
114
118
|
|
|
119
|
+
# Each of paths that a local branch's commits not on HEAD bring in, with the branches that do: where a member's
|
|
120
|
+
# file may be waiting to merge. None outside git.
|
|
121
|
+
#: (Array[String]) -> Hash[String, Array[String]]
|
|
122
|
+
def branches_bringing_in(paths) = @repository.inside? ? @repository.branches_bringing_in(paths) : {}
|
|
123
|
+
|
|
115
124
|
# The rename git detects for path, a file absent from the working tree, as {"to", "similarity",
|
|
116
125
|
# "deleted_in"}: the last commit that touched path, or nil while the move is not yet committed. It is
|
|
117
126
|
# git's similarity match, which can pair a deleted file with an unrelated similar one, so the agent checks
|
|
@@ -160,6 +169,11 @@ module Principles
|
|
|
160
169
|
@repository.commits_touching(through_links(paths), since: since, up_to: head || "HEAD")
|
|
161
170
|
end
|
|
162
171
|
|
|
172
|
+
# The newest commit on at's first-parent line that changed any of paths, a link on the way to one or the file they
|
|
173
|
+
# lead to; nil when none did.
|
|
174
|
+
#: (Array[String], at: String) -> String?
|
|
175
|
+
def last_change(paths, at:) = @repository.last_change(through_links(paths), at: at)
|
|
176
|
+
|
|
163
177
|
# Reads the commits on head's first-parent line touching each of path_sets, and the links and files they lead
|
|
164
178
|
# through, in one git log, so commits_touching asks git no more for any of them. Nothing outside git.
|
|
165
179
|
#: (Array[Array[String]]) -> void
|
|
@@ -51,6 +51,13 @@ module Principles
|
|
|
51
51
|
waiting:)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
# The hash the record assessed for each plugin member of members, by id, which no commit holds; a member it
|
|
55
|
+
# assessed no hash for is left out.
|
|
56
|
+
#: (PrincipleMembers) -> Hash[String, String]
|
|
57
|
+
def plugin_hashes(members)
|
|
58
|
+
members.select(&:plugin_reference).to_h { [it.id, hash_for(it.key)] }.compact
|
|
59
|
+
end
|
|
60
|
+
|
|
54
61
|
# The hash the record assessed for the member known by key, or nil when it assessed no such member.
|
|
55
62
|
#: (String) -> String?
|
|
56
63
|
def hash_for(key)
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
module Principles
|
|
5
5
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
6
|
module Models
|
|
7
|
-
# The hooks that run this tool's
|
|
7
|
+
# The hooks that run this tool's hook commands for a project without the principles plugin, on each host: the
|
|
8
8
|
# file the project's own hooks go in, and the command each event runs. Claude Code runs a hook after a failed shell
|
|
9
|
-
# call under an event of its own; Codex has none, its PostToolUse running after every call.
|
|
9
|
+
# call under an event of its own; Codex has none, its PostToolUse running after every call. Codex has no Edit or
|
|
10
|
+
# Write tool either, which the hook before a carrier edit matches, so that hook is Claude Code's alone.
|
|
10
11
|
class ReportHooks
|
|
11
12
|
# One hook: the event that runs it, the matcher that picks which of the event's runs, and its command.
|
|
12
13
|
class Hook
|
|
@@ -52,14 +53,18 @@ module Principles
|
|
|
52
53
|
SESSION_START = Hook.new("SessionStart", "startup|resume|clear|compact", "report-at-session-start") #: Hook
|
|
53
54
|
AFTER_A_CALL = Hook.new("PostToolUse", "Bash", "report-after-commit") #: Hook
|
|
54
55
|
|
|
56
|
+
# The hook before each file edit, which points the first edit of each carrier kind at its practices page.
|
|
57
|
+
BEFORE_AN_EDIT = Hook.new("PreToolUse", "Edit|Write", "report-before-carrier-edit") #: Hook
|
|
58
|
+
|
|
55
59
|
# The commands the hooks run, once each.
|
|
56
|
-
COMMANDS = [SESSION_START.command, AFTER_A_CALL.command].freeze #: Array[String]
|
|
60
|
+
COMMANDS = [SESSION_START.command, BEFORE_AN_EDIT.command, AFTER_A_CALL.command].freeze #: Array[String]
|
|
57
61
|
|
|
58
62
|
# Claude Code first, its file the gitignored local one, since a committed one would run for a teammate without
|
|
59
63
|
# this tool and fail every session start of theirs.
|
|
60
64
|
HOSTS = [
|
|
61
65
|
Host.new("Claude Code", ".claude/settings.local.json",
|
|
62
|
-
[SESSION_START,
|
|
66
|
+
[SESSION_START, BEFORE_AN_EDIT, AFTER_A_CALL,
|
|
67
|
+
Hook.new("PostToolUseFailure", "Bash", "report-after-commit")],
|
|
63
68
|
offered: "always, as the host this tool serves first"),
|
|
64
69
|
Host.new("Codex", ".codex/hooks.json", [SESSION_START, AFTER_A_CALL],
|
|
65
70
|
offered: "always, since this command does not tell which host runs this project's sessions",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# The channel by which a string reached a captured request, from its JSON path, segment and the role of the
|
|
8
|
+
# message it sits in, so the agent tells the host's own load from the agent reading or quoting a file. The system
|
|
9
|
+
# prompt and the tool definitions are the host's; within a message, a tool's input is what the agent sent, a
|
|
10
|
+
# reminder tag is the host's, wherever it sits, and a tool's result is what came back. Plain text in a message
|
|
11
|
+
# whose role is system is the host's too, as its skill listing is; plain text in any other message is
|
|
12
|
+
# message_text, since neither says whose it is. Printed output has no channel of its own: it arrives as a tool
|
|
13
|
+
# result or a reminder.
|
|
14
|
+
class RequestChannel
|
|
15
|
+
# The channel each top-level key of a request names by itself.
|
|
16
|
+
TOP_LEVEL = { "system" => "system", "tools" => "tool_definition" }.freeze #: Hash[String, String]
|
|
17
|
+
# Every channel, in the order counts of them print: the host's own first, then what the agent sent and got back.
|
|
18
|
+
NAMES = %w[system system_message tool_definition reminder tool_input tool_result message_text other]
|
|
19
|
+
.freeze #: Array[String]
|
|
20
|
+
# The channels by which the host itself loads text; any other is the agent reading, sending or quoting it.
|
|
21
|
+
HOST = %w[system system_message tool_definition reminder].freeze #: Array[String]
|
|
22
|
+
|
|
23
|
+
# path is the string's JSON path, its keys joined by dots, such as messages.2.content.0.content; segment is
|
|
24
|
+
# reminder or plain; role is that of the message it sits in, or nil outside one.
|
|
25
|
+
#: (String, String, role: String?) -> void
|
|
26
|
+
def initialize(path, segment, role:)
|
|
27
|
+
@keys = path.split(".").freeze #: Array[String]
|
|
28
|
+
@segment = segment
|
|
29
|
+
@role = role
|
|
30
|
+
freeze
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Its channel's name.
|
|
34
|
+
#: () -> String
|
|
35
|
+
def to_s
|
|
36
|
+
top = @keys.first.to_s
|
|
37
|
+
return TOP_LEVEL.fetch(top) if TOP_LEVEL.key?(top)
|
|
38
|
+
return "other" unless top == "messages"
|
|
39
|
+
|
|
40
|
+
in_message
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
# The channel of a string inside a message: what the agent sent a tool, a reminder, what a tool gave back, or
|
|
46
|
+
# plain text, the host's in a system message.
|
|
47
|
+
#: () -> String
|
|
48
|
+
def in_message
|
|
49
|
+
return "tool_input" if block_key == "input"
|
|
50
|
+
return "reminder" if @segment == "reminder"
|
|
51
|
+
return "tool_result" if block_key == "content"
|
|
52
|
+
|
|
53
|
+
@role == "system" ? "system_message" : "message_text"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# The key under a message's content block, such as input, content or text, or nil for a message whose content
|
|
57
|
+
# is one string.
|
|
58
|
+
#: () -> String?
|
|
59
|
+
def block_key = @keys[4]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/logged_request_scan"
|
|
5
|
+
require_relative "../data/request_shape"
|
|
6
|
+
require_relative "turn_position"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# Whether a captured request was a model turn of a thread or a side call made on its behalf, such as a summary
|
|
12
|
+
# or a permission check, which the host sends under the same query_source. The host does not say. A request
|
|
13
|
+
# continuing a thread is a model turn. Any other request under one of the host's side-call sources is a side call,
|
|
14
|
+
# since it can carry the thread's whole context and tools. Any other request still is told by a heuristic from its
|
|
15
|
+
# shape alone: a model turn lists tools, and a side call lists none and holds one or two messages. A request that
|
|
16
|
+
# is neither is unclassified rather than guessed at.
|
|
17
|
+
class RequestKind
|
|
18
|
+
# Every kind, in the order counts of them print.
|
|
19
|
+
NAMES = %w[model_turn side_call unclassified].freeze #: Array[String]
|
|
20
|
+
# The most messages a side call holds.
|
|
21
|
+
SIDE_CALL_MESSAGES = 2
|
|
22
|
+
# The query_sources whose requests that continue no thread are the host's side calls, a label-based exception to
|
|
23
|
+
# the shape rule from one log: on 2026-11-28 this project's held 21, 10, 9 and 1 of them, each with tools, none
|
|
24
|
+
# in a thread and none continued. sdk is left out, since a headless run's own model turns go under it.
|
|
25
|
+
SIDE_CALL_SOURCES = %w[away_summary compact prompt_suggestion web_search_tool].freeze #: Array[String]
|
|
26
|
+
|
|
27
|
+
# Each of scan's requests with its kind, from its shape, and a model turn with its
|
|
28
|
+
# TurnPosition too; one the scan read no shape of, as it could not read it through, is left without.
|
|
29
|
+
#: (Data::LoggedRequestScan) -> Array[Hash[String, String?]]
|
|
30
|
+
def self.labelled(scan)
|
|
31
|
+
shapes = scan.request_shapes
|
|
32
|
+
scan.requests.map do |request|
|
|
33
|
+
shape = shapes[request.fetch("file").to_s]
|
|
34
|
+
next request unless shape
|
|
35
|
+
|
|
36
|
+
kind = new(shape, query_source: request["query_source"]).to_s
|
|
37
|
+
next request.merge("kind" => kind) unless kind == "model_turn"
|
|
38
|
+
|
|
39
|
+
request.merge("kind" => kind, "turn_position" => TurnPosition.new(shape).to_s)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# shape is the request's, as Data::RequestShape gives it, and query_source the one its index line gives, if any.
|
|
44
|
+
#: (Data::RequestShape, ?query_source: String?) -> void
|
|
45
|
+
def initialize(shape, query_source: nil)
|
|
46
|
+
@shape = shape
|
|
47
|
+
@query_source = query_source
|
|
48
|
+
freeze
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Its kind's name.
|
|
52
|
+
#: () -> String
|
|
53
|
+
def to_s
|
|
54
|
+
return "model_turn" if @shape.continues_thread?
|
|
55
|
+
return "side_call" if SIDE_CALL_SOURCES.include?(@query_source)
|
|
56
|
+
return "model_turn" if @shape.tools.positive?
|
|
57
|
+
|
|
58
|
+
(1..SIDE_CALL_MESSAGES).cover?(@shape.messages) ? "side_call" : "unclassified"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "request_logging_guard"
|
|
6
|
+
require_relative "user_logged_requests"
|
|
7
|
+
require_relative "../data/request_logging_folder"
|
|
8
|
+
require_relative "../data/project_files"
|
|
9
|
+
require_relative "../data/user_request_logging_folder"
|
|
10
|
+
require_relative "captured_sessions"
|
|
11
|
+
require_relative "logged_request_scan_completeness"
|
|
12
|
+
require_relative "logged_request_reach"
|
|
13
|
+
require_relative "member_reach"
|
|
14
|
+
require_relative "request_kind"
|
|
15
|
+
require_relative "kept_sessions"
|
|
16
|
+
require_relative "members_in_logged_requests"
|
|
17
|
+
require_relative "turn_opening"
|
|
18
|
+
|
|
19
|
+
module Principles
|
|
20
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
21
|
+
module Models
|
|
22
|
+
# The project's logged requests: each request the host sends, written into a folder git must ignore, since a
|
|
23
|
+
# request holds the session's whole working context. Each command here checks first that git ignores the folder
|
|
24
|
+
# and every file in it, and refuses otherwise; this is the one guard they share.
|
|
25
|
+
class RequestLogging
|
|
26
|
+
# What a scan reports: how many members have each status, each member with where it was seen, the requests
|
|
27
|
+
# with no query_source, those quoting a logged request, the requests by kind, the model turns by turn
|
|
28
|
+
# position, the requests it could not read, and how complete it was.
|
|
29
|
+
#: type report = { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]],
|
|
30
|
+
#| orphans: Integer, quoting_requests: Array[String], requests_by_kind: Hash[String, Integer],
|
|
31
|
+
#| model_turns_by_position: Hash[String, Integer],
|
|
32
|
+
#| model_turns_by_query_source: Hash[String, Hash[String, Integer]],
|
|
33
|
+
#| unreadable: Array[Hash[String, String]], completeness: Hash[String, untyped] }
|
|
34
|
+
|
|
35
|
+
FOLDER = Data::RequestLoggingFolder
|
|
36
|
+
IGNORE_EVERYTHING = "*\n"
|
|
37
|
+
|
|
38
|
+
# registry is the sessions registered here while request logging is on in the user's own settings, which have
|
|
39
|
+
# the host write every project's requests to user_folder.
|
|
40
|
+
#: (Data::RequestLoggingFolder, Data::ProjectFiles, ?registry: SessionRegistry?,
|
|
41
|
+
#| ?user_folder: Data::UserRequestLoggingFolder?) -> void
|
|
42
|
+
def initialize(folder, files, registry: nil, user_folder: nil)
|
|
43
|
+
@folder = folder
|
|
44
|
+
@guard = RequestLoggingGuard.new(folder, files) #: RequestLoggingGuard
|
|
45
|
+
@registry = registry
|
|
46
|
+
@user_folder = user_folder
|
|
47
|
+
freeze
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Writes the .gitignore that has git ignore the folder, and once git confirms it does, the launch file that
|
|
51
|
+
# switches capture on, and gives the paths it wrote; when git does not ignore it, removes what it wrote and
|
|
52
|
+
# refuses.
|
|
53
|
+
#: () -> Array[String]
|
|
54
|
+
def turn_on
|
|
55
|
+
created = !@folder.exist?
|
|
56
|
+
written = @folder.files.include?(FOLDER::IGNORE) ? [] : [FOLDER::IGNORE]
|
|
57
|
+
written.each { |name| @folder.write(name, IGNORE_EVERYTHING) }
|
|
58
|
+
@guard.refuse_unignored(written, created)
|
|
59
|
+
@folder.write_settings("env" => capturing)
|
|
60
|
+
[*written, FOLDER::SETTINGS].map { |name| @folder.relative(name) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# The launch file, by its absolute path, as the host is started with it.
|
|
64
|
+
#: () -> String
|
|
65
|
+
def launch_file = @folder.absolute(FOLDER::SETTINGS)
|
|
66
|
+
|
|
67
|
+
# Empties the launch file's env, so a launch with it captures nothing, and gives the paths it wrote: none where
|
|
68
|
+
# request logging was never turned on. Every logged request stays.
|
|
69
|
+
#: () -> Array[String]
|
|
70
|
+
def turn_off
|
|
71
|
+
refuse_while_unguarded
|
|
72
|
+
return [] unless @folder.files.include?(FOLDER::SETTINGS)
|
|
73
|
+
|
|
74
|
+
@folder.write_settings("env" => {})
|
|
75
|
+
[@folder.relative(FOLDER::SETTINGS)]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Whether no request is captured, so nothing shows which members reach the context: the folder is not there, or
|
|
79
|
+
# holds no request yet. Refuses while the folder is unguarded.
|
|
80
|
+
#: () -> bool
|
|
81
|
+
def none_captured? = !@folder.exist? || captured.none?
|
|
82
|
+
|
|
83
|
+
# Whether request logging is in use here: its folder is, turned on or holding requests kept from before.
|
|
84
|
+
#: () -> bool
|
|
85
|
+
def in_use? = @folder.exist?
|
|
86
|
+
|
|
87
|
+
# What the host captured, once the guard passes.
|
|
88
|
+
#: () -> CapturedSessions
|
|
89
|
+
def captured
|
|
90
|
+
refuse_while_unguarded
|
|
91
|
+
requests, kept = read
|
|
92
|
+
everything = CapturedSessions.new(requests.captured_files, requests.index_lines)
|
|
93
|
+
kept ? everything.of(kept) : everything
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Removes the host's files of every session but the newest keep_sessions, 5 unless given, and gives the paths it
|
|
97
|
+
# removed. Refuses while the folder is unguarded, and a count that is not a whole number, before removing any.
|
|
98
|
+
#: (keep_sessions: String?) -> Array[String]
|
|
99
|
+
def remove(keep_sessions:)
|
|
100
|
+
refuse_while_unguarded
|
|
101
|
+
names = captured.older_than_newest(KeptSessions.new(keep_sessions).count)
|
|
102
|
+
requests, = read
|
|
103
|
+
names.each { |name| requests.remove_request(name) }
|
|
104
|
+
names.map { |name| requests.shown(name) }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Makes the user-level folder the host writes every project's requests to, readable only by the user, and gives
|
|
108
|
+
# it when it was new; none while there is no user-level folder to make.
|
|
109
|
+
#: () -> Array[String]
|
|
110
|
+
def make_user_folder
|
|
111
|
+
user = @user_folder or return []
|
|
112
|
+
user.create ? [user.path] : []
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Registers session_id, started in cwd, to the project while request logging is on in the user's own settings,
|
|
116
|
+
# as SessionRegistry says.
|
|
117
|
+
#: (session_id: String?, cwd: String?) -> void
|
|
118
|
+
def register_session(session_id:, cwd:) = @registry&.register(session_id: session_id, cwd: cwd)
|
|
119
|
+
|
|
120
|
+
# Removes the user-level folder's sessions no listed project registered, as UserLoggedRequests says; none while
|
|
121
|
+
# there is no user-level folder to read.
|
|
122
|
+
#: () -> UserLoggedRequests::Pruned
|
|
123
|
+
def prune_unregistered
|
|
124
|
+
user = @user_folder
|
|
125
|
+
user ? UserLoggedRequests.new(user).prune : UserLoggedRequests::NONE
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Refuses while the folder exists unguarded, as RequestLoggingGuard says.
|
|
129
|
+
#: () -> void
|
|
130
|
+
def refuse_while_unguarded = @guard.refuse_while_unguarded
|
|
131
|
+
|
|
132
|
+
# The refusal a read gives while the folder exists unguarded, or nil, as RequestLoggingGuard says.
|
|
133
|
+
#: () -> Error?
|
|
134
|
+
def unguarded_refusal = @guard.unguarded_refusal
|
|
135
|
+
|
|
136
|
+
# Where each of members' text was seen in the captured requests, scanned by jq and rg, once the folder is
|
|
137
|
+
# guarded.
|
|
138
|
+
# Each request that is not whole JSON is named under unreadable, with its reason, since what it held is unknown,
|
|
139
|
+
# and completeness says how many requests and strings the scan read, and whether it read every request through.
|
|
140
|
+
#: (MembersInLoggedRequests)
|
|
141
|
+
#| -> report
|
|
142
|
+
def members_seen(members) = scanned(members).first
|
|
143
|
+
|
|
144
|
+
# The report members_seen gives, but each member's reach in place of its places, as MemberReach lists it, so
|
|
145
|
+
# the report is bounded by the members mapped rather than growing with every request that holds them.
|
|
146
|
+
#: (MembersInLoggedRequests)
|
|
147
|
+
#| -> report
|
|
148
|
+
def members_reached(members)
|
|
149
|
+
seen = members_seen(members)
|
|
150
|
+
seen.merge(members: seen[:members].map { MemberReach.new(it).listed })
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# How far each of members' text reached the captured requests, compactly, from one scan, once the folder is
|
|
154
|
+
# guarded; carried names the members an audit carries forward.
|
|
155
|
+
#: (MembersInLoggedRequests, ?carried: Array[String]) -> LoggedRequestReach
|
|
156
|
+
def reach(members, carried: [])
|
|
157
|
+
seen, read_whole = scanned(members)
|
|
158
|
+
turns = { model_turns_by_position: seen[:model_turns_by_position],
|
|
159
|
+
model_turns_by_query_source: seen[:model_turns_by_query_source] }
|
|
160
|
+
LoggedRequestReach.new(seen[:members], scanned: read_whole, unreadable: seen[:unreadable].size, carried:,
|
|
161
|
+
model_turns: turns)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Each captured turn opening, by session, as TurnOpening gives them, with the bytes of members' text each sent,
|
|
165
|
+
# from one scan, once the folder is guarded.
|
|
166
|
+
#: (MembersInLoggedRequests) -> Array[[String?, Array[TurnOpening]]]
|
|
167
|
+
def turn_openings(members)
|
|
168
|
+
scan = captured_scan
|
|
169
|
+
requests = RequestKind.labelled(scan)
|
|
170
|
+
seen, deferred = members_opening(requests, members)
|
|
171
|
+
TurnOpening.by_session(requests, scan, MembersByPart.by_request(seen, deferred))
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
private
|
|
175
|
+
|
|
176
|
+
# The scan of the requests read, those of the kept sessions alone when the folder holds other sessions', once
|
|
177
|
+
# the guard passes.
|
|
178
|
+
#: () -> Data::LoggedRequestScan
|
|
179
|
+
def captured_scan
|
|
180
|
+
refuse_while_unguarded
|
|
181
|
+
requests, kept = read
|
|
182
|
+
return requests.scan unless kept
|
|
183
|
+
|
|
184
|
+
requests.scan(only: CapturedSessions.new(requests.captured_files, requests.index_lines).of(kept).file_names)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Where each of members' text was seen in the turn openings among requests, as members_seen gives it, and each
|
|
188
|
+
# tool they defer loading, from a scan of those requests alone, since the rest are not measured and scanning
|
|
189
|
+
# them took most of the read's time.
|
|
190
|
+
#: (Array[Hash[String, String?]], MembersInLoggedRequests)
|
|
191
|
+
#| -> [Array[Hash[String, untyped]], Array[[String, String]]]
|
|
192
|
+
def members_opening(requests, members)
|
|
193
|
+
opened = requests.select { it["turn_position"] == "turn_opening" }
|
|
194
|
+
scan = read.first.scan(only: opened.map { it.fetch("file").to_s })
|
|
195
|
+
deferred = scan.deferred_tools
|
|
196
|
+
[members.report(opened, scan.matches(members.patterns).found, deferred).fetch(:members), deferred]
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# The requests the commands here read, and the sessions they keep: the user-level folder's, kept to the
|
|
200
|
+
# sessions registered here, once the registry names one; this project's own folder's, all kept, otherwise.
|
|
201
|
+
#: () -> [Data::CapturedRequests, Array[String]?]
|
|
202
|
+
def read
|
|
203
|
+
user = @user_folder
|
|
204
|
+
registered = user&.exist? ? @registry&.session_ids || [] : []
|
|
205
|
+
return [@folder.requests, nil] if user.nil? || registered.empty?
|
|
206
|
+
|
|
207
|
+
[user.requests, registered]
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# Where each of members' text was seen, as members_seen gives it, and how many requests the scan read whole.
|
|
211
|
+
#: (MembersInLoggedRequests)
|
|
212
|
+
#| -> [report, Integer]
|
|
213
|
+
def scanned(members)
|
|
214
|
+
scan = captured_scan
|
|
215
|
+
requests = RequestKind.labelled(scan)
|
|
216
|
+
matched = scan.matches(members.patterns)
|
|
217
|
+
read = LoggedRequestScanCompleteness.of(scan, matched)
|
|
218
|
+
report = members.report(requests, matched.found, scan.deferred_tools)
|
|
219
|
+
[{ **report, unreadable: read.unreadable, completeness: read.to_h }, requests.size - read.unreadable.size]
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# What has the host write each request's body to the folder: telemetry on, so it logs request bodies, with no
|
|
223
|
+
# exporter, so nothing leaves the machine.
|
|
224
|
+
#: () -> Hash[String, String]
|
|
225
|
+
def capturing
|
|
226
|
+
{ "CLAUDE_CODE_ENABLE_TELEMETRY" => "1", "OTEL_METRICS_EXPORTER" => "none", "OTEL_LOGS_EXPORTER" => "none",
|
|
227
|
+
"OTEL_TRACES_EXPORTER" => "none", "OTEL_LOG_RAW_API_BODIES" => "file:#{@folder.absolute(FOLDER::REQUESTS)}" }
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../data/request_logging_folder"
|
|
6
|
+
require_relative "../data/project_files"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# The one guard every request-logging command shares: git must confirm it ignores the folder and every file in it,
|
|
12
|
+
# since a logged request holds the session's whole working context and must never be committed.
|
|
13
|
+
class RequestLoggingGuard
|
|
14
|
+
FOLDER = Data::RequestLoggingFolder
|
|
15
|
+
# The paths each command checks git ignores, beside every file already in the folder.
|
|
16
|
+
GUARDED = [FOLDER::IGNORE, FOLDER::SETTINGS, "#{FOLDER::REQUESTS}/"].freeze #: Array[String]
|
|
17
|
+
|
|
18
|
+
#: (Data::RequestLoggingFolder, Data::ProjectFiles) -> void
|
|
19
|
+
def initialize(folder, files)
|
|
20
|
+
@folder = folder
|
|
21
|
+
@files = files
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Refuses while the folder exists unguarded: its .gitignore gone, or git not ignoring every path there. Every
|
|
26
|
+
# read of the folder asks this first, since a logged request git does not ignore can be committed.
|
|
27
|
+
#: () -> void
|
|
28
|
+
def refuse_while_unguarded
|
|
29
|
+
refusal = unguarded_refusal
|
|
30
|
+
raise refusal if refusal
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The refusal every read of the folder gives while it exists unguarded, or nil while git ignores it or it is
|
|
34
|
+
# not there; for a read that carries on without the logged requests, such as a full audit's request.
|
|
35
|
+
#: () -> Error?
|
|
36
|
+
def unguarded_refusal
|
|
37
|
+
return unless @folder.exist?
|
|
38
|
+
return unguarded unless @folder.files.include?(FOLDER::IGNORE)
|
|
39
|
+
|
|
40
|
+
not_ignored unless ignored?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Removes what turning logging on wrote, and the folder when it made it, then refuses, unless git confirms it
|
|
44
|
+
# ignores the folder.
|
|
45
|
+
#: (Array[String], bool) -> void
|
|
46
|
+
def refuse_unignored(written, created)
|
|
47
|
+
return if ignored?
|
|
48
|
+
|
|
49
|
+
written.each { |name| @folder.remove(name) }
|
|
50
|
+
@folder.remove_if_empty if created
|
|
51
|
+
raise not_ignored
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
# Whether git confirms it ignores the folder's own paths and every file already in it.
|
|
57
|
+
#: () -> bool
|
|
58
|
+
def ignored?
|
|
59
|
+
paths = (GUARDED | @folder.files).map { |name| @folder.relative(name) }
|
|
60
|
+
ignored = @files.ignored_paths(paths)
|
|
61
|
+
!ignored.nil? && (paths - ignored).empty?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#: () -> Error
|
|
65
|
+
def unguarded
|
|
66
|
+
Error.new("request_logging_unguarded",
|
|
67
|
+
"#{@folder.relative(FOLDER::IGNORE)} is missing, so git may not ignore the logged requests beside it",
|
|
68
|
+
"A logged request holds the session's whole working context, so it must never reach git. Restore " \
|
|
69
|
+
"#{@folder.relative(FOLDER::IGNORE)} holding the one line *, then run this again.")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#: () -> Error
|
|
73
|
+
def not_ignored
|
|
74
|
+
Error.new("request_logging_not_ignored",
|
|
75
|
+
"git does not confirm that it ignores #{FOLDER::FOLDER}/, so logged requests there could be " \
|
|
76
|
+
"committed",
|
|
77
|
+
"A logged request holds the session's whole working context, so it must never reach git. Make this " \
|
|
78
|
+
"project a git repository with git init if it is not one. If git tracks a file under " \
|
|
79
|
+
"#{FOLDER::FOLDER}/, stop tracking it with git rm -r --cached #{FOLDER::FOLDER}. Then run this " \
|
|
80
|
+
"command again.")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "time"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# When a captured request was sent, as its index line gives it, in ISO 8601 UTC to the millisecond, the form the
|
|
10
|
+
# host writes, so a time written with an offset sorts beside the rest as text. A timestamp that is not ISO 8601
|
|
11
|
+
# gives none rather than a guess. Times compare as they were sent, one with none after every one with a time.
|
|
12
|
+
class RequestTime
|
|
13
|
+
include Comparable
|
|
14
|
+
|
|
15
|
+
#: (String?) -> void
|
|
16
|
+
def initialize(timestamp)
|
|
17
|
+
@timestamp = timestamp
|
|
18
|
+
freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The time in ISO 8601 UTC, or nil for none or one that does not parse.
|
|
22
|
+
#: () -> String?
|
|
23
|
+
def utc
|
|
24
|
+
timestamp = @timestamp
|
|
25
|
+
return unless timestamp
|
|
26
|
+
|
|
27
|
+
Time.iso8601(timestamp).utc.iso8601(3)
|
|
28
|
+
rescue ArgumentError
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Earlier first, and none after every time.
|
|
33
|
+
#: (RequestTime) -> Integer
|
|
34
|
+
def <=>(other) = sort_key <=> other.sort_key
|
|
35
|
+
|
|
36
|
+
protected
|
|
37
|
+
|
|
38
|
+
# A time with one, as its UTC text sorts, before one without.
|
|
39
|
+
#: () -> [Integer, String]
|
|
40
|
+
def sort_key
|
|
41
|
+
sent = utc
|
|
42
|
+
sent ? [0, sent] : [1, ""]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -27,11 +27,6 @@ module Principles
|
|
|
27
27
|
#: () -> bool
|
|
28
28
|
def session_start_hook_in_this_session? = plugin?
|
|
29
29
|
|
|
30
|
-
# Whether the principles skill, /principles, is installed for the session this run is part of, which only the
|
|
31
|
-
# plugin installs; an installed gem or a checkout has none.
|
|
32
|
-
#: () -> bool
|
|
33
|
-
def principles_skill_in_this_session? = plugin?
|
|
34
|
-
|
|
35
30
|
private
|
|
36
31
|
|
|
37
32
|
#: () -> bool
|