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,174 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../prose_list"
|
|
6
|
+
require_relative "../data/claude_code_home"
|
|
7
|
+
require_relative "plugin_install"
|
|
8
|
+
require_relative "plugin_component"
|
|
9
|
+
require_relative "plugin_name"
|
|
10
|
+
require_relative "installed_component"
|
|
11
|
+
require_relative "member_file"
|
|
12
|
+
|
|
13
|
+
module Principles
|
|
14
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
15
|
+
module Models
|
|
16
|
+
# The plugins Claude Code installed that a session in the project loads, as the registry in its home records them;
|
|
17
|
+
# none while it has installed none.
|
|
18
|
+
class InstalledPlugins
|
|
19
|
+
# The most files a refusal names; it counts the rest.
|
|
20
|
+
LISTED = 20 #: Integer
|
|
21
|
+
|
|
22
|
+
# The marketplace kinds whose plugins Claude Code copies into the install folder its registry names, which is
|
|
23
|
+
# where a session reads them.
|
|
24
|
+
COPIED = %w[github git url].freeze #: Array[String]
|
|
25
|
+
|
|
26
|
+
#: (Data::ClaudeCodeHome, main_checkout: String) -> void
|
|
27
|
+
def initialize(claude_code, main_checkout:)
|
|
28
|
+
@claude_code = claude_code
|
|
29
|
+
@main_checkout = main_checkout
|
|
30
|
+
freeze
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The install of the plugin named that a session here loads, refused when there is none, naming those there
|
|
34
|
+
# are; when its marketplace is a local folder, whose session reads the folder rather than the install; and when
|
|
35
|
+
# its marketplace is of no kind COPIED names, since a session may read that from elsewhere too.
|
|
36
|
+
#: (String) -> PluginInstall
|
|
37
|
+
def install(name)
|
|
38
|
+
install = PluginInstall.applying(rows(name), main_checkout: @main_checkout) or refuse_not_installed(name)
|
|
39
|
+
kind = @claude_code.marketplaces&.source_kind(PluginName.new(name).marketplace)
|
|
40
|
+
refuse_directory_marketplace(name) if kind == "directory"
|
|
41
|
+
refuse_unknown_marketplace(name) unless COPIED.include?(kind)
|
|
42
|
+
install.version.to_s.empty? ? refuse_unversioned(name) : install
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# The file component names in the plugin named, with its text, refused when it is reached through a symbolic
|
|
46
|
+
# link, which this tool never follows; when the plugin holds no such file, naming those it does; and when its
|
|
47
|
+
# text is not UTF-8 or larger than this tool reads.
|
|
48
|
+
#: (String, PluginComponent) -> InstalledComponent
|
|
49
|
+
def holding(name, component)
|
|
50
|
+
install = install(name)
|
|
51
|
+
folder = @claude_code.plugin_folder(install.install_path.to_s)
|
|
52
|
+
refuse_linked(name, component) if folder.linked?(component.path)
|
|
53
|
+
refuse_not_held(name, folder.files) unless folder.file?(component.path)
|
|
54
|
+
InstalledComponent.new(PluginReference.new(name, component), install, folder.read(component.path))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Whether the plugin installed now holds the file reference names, as holding finds it.
|
|
58
|
+
#: (PluginReference) -> bool
|
|
59
|
+
def holds?(reference)
|
|
60
|
+
holding(reference.name, reference.component)
|
|
61
|
+
true
|
|
62
|
+
rescue Error
|
|
63
|
+
false
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Where the file reference names comes from, at the version installed now, refused as install refuses.
|
|
67
|
+
#: (PluginReference) -> Hash[String, untyped]
|
|
68
|
+
def source(reference) = reference.source(install(reference.name).version)
|
|
69
|
+
|
|
70
|
+
# Where member comes from when a plugin gives it, as source says; nil for a member in a project file.
|
|
71
|
+
#: (Member) -> Hash[String, untyped]?
|
|
72
|
+
def source_of(member)
|
|
73
|
+
reference = member.plugin_reference or return
|
|
74
|
+
source(reference)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# The file a mapped plugin member's reference names, as the type that finds the member in it, refused as
|
|
78
|
+
# holding refuses it.
|
|
79
|
+
#: (PluginReference) -> MemberFile
|
|
80
|
+
def member_file(reference)
|
|
81
|
+
MemberFile.for(path: reference.to_s, text: holding(reference.name, reference.component).text)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The install names of the plugins a session here loads, sorted.
|
|
85
|
+
#: () -> Array[String]
|
|
86
|
+
def names
|
|
87
|
+
(@claude_code.registry&.names || []).select do |name|
|
|
88
|
+
PluginInstall.applying(rows(name), main_checkout: @main_checkout)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
#: (String) -> Array[Hash[String, String?]]
|
|
95
|
+
def rows(name) = @claude_code.registry&.rows(name) || []
|
|
96
|
+
|
|
97
|
+
#: (String, Array[String]) -> bot
|
|
98
|
+
def refuse_not_held(name, files)
|
|
99
|
+
plain, skipped = files.partition { |path| PluginComponent.plain?(path) }
|
|
100
|
+
listed = plain.first(LISTED) + (plain.size > LISTED ? ["#{plain.size - LISTED} more"] : [])
|
|
101
|
+
repair = if listed.empty?
|
|
102
|
+
"#{name} holds no file this tool can map.#{left_out(skipped, "")} Map the project's own files " \
|
|
103
|
+
"instead."
|
|
104
|
+
else
|
|
105
|
+
"Name one of the files #{name} holds: #{ProseList.new(listed)}.#{left_out(skipped, " more")}"
|
|
106
|
+
end
|
|
107
|
+
raise Error.new("plugin_component_not_found", "#{name} holds no such file", repair)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# A sentence, after a space, counting the files skipped that a refusal leaves out for their paths, as more
|
|
111
|
+
# when it lists others; nothing when there are none.
|
|
112
|
+
#: (Array[String], String) -> String
|
|
113
|
+
def left_out(skipped, more)
|
|
114
|
+
return "" if skipped.empty?
|
|
115
|
+
|
|
116
|
+
" #{skipped.size}#{more} #{skipped.one? ? "is" : "are"} left out, since a member's path takes only plain " \
|
|
117
|
+
"characters."
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
#: (String, PluginComponent) -> bot
|
|
121
|
+
def refuse_linked(name, component)
|
|
122
|
+
raise Error.new("plugin_component_linked",
|
|
123
|
+
"#{component.path} in #{name} is reached through a symbolic link, which this tool does not " \
|
|
124
|
+
"follow, since it could lead out of the plugin",
|
|
125
|
+
"Name the file the link leads to by its own path inside the plugin, or map the project's own " \
|
|
126
|
+
"files instead.")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
#: (String) -> bot
|
|
130
|
+
def refuse_directory_marketplace(name)
|
|
131
|
+
raise Error.new("plugin_from_directory_marketplace", "#{name} comes from a marketplace in a local folder",
|
|
132
|
+
"Map the project's own files instead; a plugin from a marketplace in a local folder is " \
|
|
133
|
+
"not supported yet.")
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# A probe saw the host record a version in every row, a commit's first digits when the plugin names none.
|
|
137
|
+
#: (String) -> bot
|
|
138
|
+
def refuse_unversioned(name)
|
|
139
|
+
raise Error.new("unreadable_plugin_registry", "Claude Code's plugin registry records no version for #{name}",
|
|
140
|
+
"Reinstall the plugin with Claude Code, or map the project's own files instead.")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
#: (String) -> bot
|
|
144
|
+
def refuse_unknown_marketplace(name)
|
|
145
|
+
raise Error.new("plugin_marketplace_unknown",
|
|
146
|
+
"Claude Code records no marketplace kind this tool reads for #{name}",
|
|
147
|
+
"Map the project's own files instead; this tool reads a plugin only from a marketplace " \
|
|
148
|
+
"Claude Code records as #{ProseList.new(COPIED, conjunction: "or")}.")
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
#: (String) -> bot
|
|
152
|
+
def refuse_not_installed(name)
|
|
153
|
+
here = names
|
|
154
|
+
choices = if here.empty?
|
|
155
|
+
"No plugin is installed for this project. Install #{name} with Claude Code first."
|
|
156
|
+
else
|
|
157
|
+
"Installed for this project: #{ProseList.new(here)}. Name one of them with --plugin, or install " \
|
|
158
|
+
"#{name} with Claude Code first."
|
|
159
|
+
end
|
|
160
|
+
repair = elsewhere(name) + choices
|
|
161
|
+
raise Error.new("plugin_not_installed", "#{name} is not installed for this project", repair)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Why name's rows, when it has some, do not apply here: each installs it for another project.
|
|
165
|
+
#: (String) -> String
|
|
166
|
+
def elsewhere(name)
|
|
167
|
+
return "" if rows(name).empty?
|
|
168
|
+
|
|
169
|
+
"#{name} is installed only for another project, and only a user-scope install is read outside its own " \
|
|
170
|
+
"project. "
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# How many of the newest captured sessions remove-logged-requests keeps, as --keep-sessions gives it: a whole
|
|
10
|
+
# number, 0 keeping none, or 5 when it is not given.
|
|
11
|
+
class KeptSessions
|
|
12
|
+
DEFAULT = 5
|
|
13
|
+
|
|
14
|
+
#: Integer
|
|
15
|
+
attr_reader :count
|
|
16
|
+
|
|
17
|
+
#: (String?) -> void
|
|
18
|
+
def initialize(given)
|
|
19
|
+
@count = given ? whole(given) : DEFAULT #: Integer
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
#: (String) -> Integer
|
|
26
|
+
def whole(given)
|
|
27
|
+
return given.to_i if given.match?(/\A\d+\z/)
|
|
28
|
+
|
|
29
|
+
raise Error.new("invalid_keep_sessions", "--keep-sessions takes a whole number, not #{given.inspect}",
|
|
30
|
+
"Give how many of the newest sessions to keep, such as --keep-sessions 5; 0 keeps none.")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -50,6 +50,14 @@ module Principles
|
|
|
50
50
|
!heading.nil? && starting_at.nil? && ending_at.nil? && query.nil?
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
# This locator with its passage's opening quoted without its leading whitespace; nil when the opening has none.
|
|
54
|
+
#: () -> Locator?
|
|
55
|
+
def with_opening_unindented
|
|
56
|
+
opening = starting_at or return nil
|
|
57
|
+
unindented = opening.lstrip
|
|
58
|
+
Locator.new(@fields.merge("starting_at" => unindented)) unless unindented == opening
|
|
59
|
+
end
|
|
60
|
+
|
|
53
61
|
# The locator as it was given.
|
|
54
62
|
#: () -> Hash[String, untyped]
|
|
55
63
|
def to_h = @fields
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "member_reach"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# How far each member's text reached, compactly, from where the scan of the captured requests saw it: how many of
|
|
10
|
+
# the scanned requests held its lines, and the most bytes of them one request held. A full audit's request prints
|
|
11
|
+
# it, so the agent judging a member weighs whether it reaches the agent and what it costs there.
|
|
12
|
+
class LoggedRequestReach
|
|
13
|
+
# members is each member as the scan reports it, with its status and the places it was seen; scanned is how many
|
|
14
|
+
# requests the scan read whole, and unreadable how many it could not, since what they held is unknown; carried
|
|
15
|
+
# names each member a full audit carries forward, which is listed too, marked, since one that never loads still
|
|
16
|
+
# fails its principle; model_turns counts the model turns at each turn position, in all and by query_source,
|
|
17
|
+
# by the name each prints under.
|
|
18
|
+
#: (Array[Hash[String, untyped]], scanned: Integer,
|
|
19
|
+
#| model_turns: { model_turns_by_position: Hash[String, Integer],
|
|
20
|
+
#| model_turns_by_query_source: Hash[String, Hash[String, Integer]] },
|
|
21
|
+
#| ?unreadable: Integer, ?carried: Array[String]) -> void
|
|
22
|
+
def initialize(members, scanned:, model_turns:, unreadable: 0, carried: [])
|
|
23
|
+
@members = members
|
|
24
|
+
@carried = carried
|
|
25
|
+
@model_turns = model_turns
|
|
26
|
+
@scanned = scanned
|
|
27
|
+
@unreadable = unreadable
|
|
28
|
+
freeze
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The requests scanned, any it could not read, the model turns by turn position, each member's status, the
|
|
32
|
+
# requests seen holding its lines and its most bytes in one, and whether the audit carries it forward, and, while
|
|
33
|
+
# any is, the key of each member seen only where the agent read, sent or quoted it.
|
|
34
|
+
#: () -> Hash[String, untyped]
|
|
35
|
+
def to_h
|
|
36
|
+
reaches = @members.map { [it.fetch("member"), MemberReach.new(it)] }
|
|
37
|
+
read = reaches.select { |_, reach| reach.seen_only_as_read? }.map(&:first)
|
|
38
|
+
{ "requests" => @scanned, **({ "unreadable" => @unreadable } if @unreadable.positive?),
|
|
39
|
+
**@model_turns.transform_keys(&:to_s), "members" => reaches.map { |key, reach| shown(key, reach) },
|
|
40
|
+
**({ "seen_only_as_read" => read } unless read.empty?) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
# The reach of the member keyed key, marked when the audit carries it forward.
|
|
46
|
+
#: (String, MemberReach) -> Hash[String, untyped]
|
|
47
|
+
def shown(key, reach)
|
|
48
|
+
@carried.include?(key) ? reach.to_h.merge("carried_forward" => true) : reach.to_h
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/logged_request_scan"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# How much of the captured requests one scan read: how many there were, how many strings it decoded, and whether
|
|
10
|
+
# it read every one through. A member reported absent is proven absent only when it did, so each request it did
|
|
11
|
+
# not decode to its end is named, beside those it could not read at all.
|
|
12
|
+
class LoggedRequestScanCompleteness
|
|
13
|
+
# What scan read in its run matched.
|
|
14
|
+
#: (Data::LoggedRequestScan, Data::LoggedRequestMatches) -> LoggedRequestScanCompleteness
|
|
15
|
+
def self.of(scan, matched)
|
|
16
|
+
new(requests: scan.requests.map { it.fetch("file").to_s }, unreadable: scan.unreadable, matched:)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
#: (requests: Array[String], unreadable: Array[Hash[String, String]],
|
|
20
|
+
#| matched: Data::LoggedRequestMatches) -> void
|
|
21
|
+
def initialize(requests:, unreadable:, matched:)
|
|
22
|
+
@requests = requests
|
|
23
|
+
@matched = matched
|
|
24
|
+
undecoded = requests - unreadable.map { it.fetch("request") } - matched.leaves.keys
|
|
25
|
+
named = undecoded.map { { "request" => it, "reason" => "not_decoded" } }
|
|
26
|
+
@unreadable = [*unreadable, *named].freeze #: Array[Hash[String, String]]
|
|
27
|
+
freeze
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Each request the scan could not read through, by its request and reason.
|
|
31
|
+
#: Array[Hash[String, String]]
|
|
32
|
+
attr_reader :unreadable
|
|
33
|
+
|
|
34
|
+
# The requests captured, those it could not read too, the strings decoded in them, and whether the scan read
|
|
35
|
+
# every one through.
|
|
36
|
+
#: () -> Hash[String, untyped]
|
|
37
|
+
def to_h
|
|
38
|
+
{ "captured" => @requests.size, "leaves" => @matched.leaves.values.sum,
|
|
39
|
+
"complete" => @unreadable.empty? && @matched.whole }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
module Models
|
|
6
|
+
# What saving a map does to its format, against the map as stored, and the first release of principles that
|
|
7
|
+
# reads the new format where an earlier release cannot, so a write locking out older copies can say so.
|
|
8
|
+
class MapFormatRaise
|
|
9
|
+
# The first release that reads each map format some earlier release cannot: every release reads formats 1 and
|
|
10
|
+
# 2, 0.1.3 reads up to 2 and 0.1.4 up to 4, as each tag's Data::MapFiles::NEWEST_FORMAT says (checked
|
|
11
|
+
# 2026-11-30 with git grep on v0.0.1, v0.1.3 and v0.1.4).
|
|
12
|
+
FIRST_READ_IN = { 4 => "0.1.4", 5 => "0.1.5" }.freeze #: Hash[Integer, String]
|
|
13
|
+
|
|
14
|
+
# principles are the project's mapped principles, holding map as stored, if it is; map is it as it will be saved.
|
|
15
|
+
#: (MappedPrinciples, Principle) -> void
|
|
16
|
+
def initialize(principles, map)
|
|
17
|
+
@from = principles.mapped?(map.id) ? principles.find(map.id).format : 1 #: Integer
|
|
18
|
+
@to = map.format #: Integer
|
|
19
|
+
freeze
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# The format it was, the format it will be, and the release that first reads it where it rose to a format an
|
|
23
|
+
# earlier release cannot read, else nil.
|
|
24
|
+
#: () -> { from: Integer, to: Integer, release: String? }
|
|
25
|
+
def to_h = { from: @from, to: @to, release: (FIRST_READ_IN[@to] if @to > @from) }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
# What this tool knew of a member's text when it was mapped, which no audit has assessed: its hash at the commit
|
|
8
|
+
# that mapped it where it is, or, for a plugin member, which no commit holds, the hash its map pinned.
|
|
9
|
+
class MappedBaseline
|
|
10
|
+
# What "since" names each kind as, every one a baseline no audit gave, so a member compared with one alone has
|
|
11
|
+
# never been assessed.
|
|
12
|
+
KINDS = %w[mapping_commit pinned].freeze #: Array[String]
|
|
13
|
+
|
|
14
|
+
# The member's hash at the commit that mapped it where it is, from which its automatic history walks.
|
|
15
|
+
#: (String, String) -> MappedBaseline
|
|
16
|
+
def self.at_commit(sha256, commit)
|
|
17
|
+
new(sha256, { "baseline" => "mapping_commit", "commit" => commit }, walks_history: true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A plugin member's pin, its version and hash when add-member read it, which git holds no history of.
|
|
21
|
+
#: (Hash[String, String]) -> MappedBaseline
|
|
22
|
+
def self.pinned(pin)
|
|
23
|
+
new(pin.fetch("sha256"), { "baseline" => "pinned", "version" => pin.fetch("version") }, walks_history: false)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#: String
|
|
27
|
+
attr_reader :sha256
|
|
28
|
+
|
|
29
|
+
# What the baseline was, as a changed member's "since" says.
|
|
30
|
+
#: Hash[String, String]
|
|
31
|
+
attr_reader :since
|
|
32
|
+
|
|
33
|
+
#: (String, Hash[String, String], walks_history: bool) -> void
|
|
34
|
+
def initialize(sha256, since, walks_history:)
|
|
35
|
+
@sha256 = sha256
|
|
36
|
+
@since = since.freeze #: Hash[String, String]
|
|
37
|
+
@walks_history = walks_history
|
|
38
|
+
freeze
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Whether the member's history in git walks back to it.
|
|
42
|
+
#: () -> bool
|
|
43
|
+
def walks_history? = @walks_history
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -121,7 +121,8 @@ module Principles
|
|
|
121
121
|
return map unless map.members.empty?
|
|
122
122
|
|
|
123
123
|
raise Error.new("map_has_no_members", "#{id} has no members to audit",
|
|
124
|
-
"Add its members: #{Error::EXECUTABLE} add-member #{id} PATH --role ROLE"
|
|
124
|
+
"Add its members: #{Error::EXECUTABLE} add-member #{id} PATH --role ROLE " \
|
|
125
|
+
"--name NAME --reason REASON", file(id))
|
|
125
126
|
end
|
|
126
127
|
|
|
127
128
|
# Writes map's file and names it, relative to the project.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "member"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The other maps holding a new whole-file member's file whole too, by its own path or through a link, so a hub
|
|
11
|
+
# file mapped whole into several principles is seen as it is mapped.
|
|
12
|
+
class MapsHoldingFileWhole
|
|
13
|
+
#: (Project, Member) -> void
|
|
14
|
+
def initialize(project, member)
|
|
15
|
+
@project = project
|
|
16
|
+
@member = member
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The ids of the maps other than except holding the file whole; none when the member is a passage. A map that
|
|
21
|
+
# cannot be read is left out, since list-member-problems reports it.
|
|
22
|
+
#: (except: String) -> Array[String]
|
|
23
|
+
def elsewhere(except:)
|
|
24
|
+
return [] unless @member.whole_file?
|
|
25
|
+
|
|
26
|
+
maps = @project.principles
|
|
27
|
+
(maps.ids - [except]).select { |id| holds_whole?(maps, id) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
#: (MappedPrinciples, String) -> bool
|
|
33
|
+
def holds_whole?(maps, id)
|
|
34
|
+
maps.find(id).members.to_a.any? do |member|
|
|
35
|
+
member.whole_file? && @project.same_file?(member.path, @member.path)
|
|
36
|
+
end
|
|
37
|
+
rescue Error
|
|
38
|
+
false
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "frontmatter_fields"
|
|
6
|
+
require_relative "outline_section"
|
|
7
|
+
require_relative "text_within"
|
|
8
|
+
|
|
9
|
+
module Principles
|
|
10
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
11
|
+
module Models
|
|
12
|
+
# A Markdown file's text as its outline reads it: its sections, each a heading and the top-level list items under
|
|
13
|
+
# it, its frontmatter description and its opening line. One user scripted a heading grep over 45 files to survey
|
|
14
|
+
# them, and missed a principles section written as one numbered list, so the outline reads both.
|
|
15
|
+
class MarkdownText
|
|
16
|
+
HEADING = /\A#+\s/
|
|
17
|
+
FENCE = /\A\s*(?:```|~~~)/
|
|
18
|
+
# A top-level list item, its marker and its text; an indented one is nested, and left out.
|
|
19
|
+
ITEM = /\A(\d+\.|[-*])\s+(.*)/
|
|
20
|
+
# A horizontal rule, such as `* * *` or `- - -`, which is no item.
|
|
21
|
+
RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
|
|
22
|
+
LINK = /\[([^\]]*)\]\([^)]*\)/
|
|
23
|
+
BOLD_LEAD = /\A\*\*[^*]+\*\*/
|
|
24
|
+
# The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
|
|
25
|
+
# mid-clause left 30 of one user's 45 opening lines a fragment. The line is short only when
|
|
26
|
+
# its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
|
|
27
|
+
# accepted, since the file's path and outline still say what it holds.
|
|
28
|
+
OPENING_CHARACTERS = 160
|
|
29
|
+
# The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
|
|
30
|
+
# one user's descriptions printed 12,537 B uncut, and suggested about 300.
|
|
31
|
+
DESCRIPTION_CHARACTERS = 300
|
|
32
|
+
|
|
33
|
+
# A description's key and any block scalar indicator, which its text starts after.
|
|
34
|
+
DESCRIPTION_KEY = /\Adescription:\s*(?:[>|][-+]?\s)?/
|
|
35
|
+
# A value inside a matching pair of quotes, printed without them; its escapes are left as written.
|
|
36
|
+
QUOTED = /\A(["'])(.*)\1\z/
|
|
37
|
+
|
|
38
|
+
#: (String) -> void
|
|
39
|
+
def initialize(text)
|
|
40
|
+
@lines = text.lines #: Array[String]
|
|
41
|
+
@frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
|
|
42
|
+
freeze
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Each heading with the items under it, and the items before the first heading when there are any, each with
|
|
46
|
+
# the lines of the file it spans.
|
|
47
|
+
#: () -> Array[OutlineSection]
|
|
48
|
+
def sections
|
|
49
|
+
body = unfenced
|
|
50
|
+
starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
|
|
51
|
+
starts.zip(starts.drop(1)).filter_map do |first, after|
|
|
52
|
+
section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
|
|
57
|
+
#: () -> String?
|
|
58
|
+
def description
|
|
59
|
+
written = @frontmatter.field_lines("$.description") or return nil
|
|
60
|
+
text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
|
|
61
|
+
text[QUOTED, 2] || text
|
|
62
|
+
rescue Error
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
|
|
67
|
+
# characters it holds and the lines of the file that hold it, so the agent reads just those back.
|
|
68
|
+
#: () -> String?
|
|
69
|
+
def cut_description
|
|
70
|
+
text = description or return nil
|
|
71
|
+
within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
|
|
72
|
+
return text unless within.cut?
|
|
73
|
+
|
|
74
|
+
kept = within.kept
|
|
75
|
+
first, last = @frontmatter.field("$.description")
|
|
76
|
+
"#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
|
|
80
|
+
# joined, with links as their text. The first physical line was a fragment in a hard-wrapped file.
|
|
81
|
+
#: () -> String?
|
|
82
|
+
def opening_line
|
|
83
|
+
body = unfenced
|
|
84
|
+
first = body.index { |line| prose?(line) } or return nil
|
|
85
|
+
paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
|
|
86
|
+
TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
# The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
|
|
92
|
+
# heading nor an item.
|
|
93
|
+
#: (Array[String], first_line: Integer) -> OutlineSection?
|
|
94
|
+
def section(lines, first_line:)
|
|
95
|
+
heading = lines.first if lines.first&.match?(HEADING)
|
|
96
|
+
items = outline_items(lines, first_line:)
|
|
97
|
+
return nil unless heading || items.any?
|
|
98
|
+
|
|
99
|
+
OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# The top-level list items among these body lines, each on its line of the file, the first of them first_line.
|
|
103
|
+
#: (Array[String], first_line: Integer) -> Array[OutlineItem]
|
|
104
|
+
def outline_items(lines, first_line:)
|
|
105
|
+
lines.each_index.select { |index| item?(lines.fetch(index)) }
|
|
106
|
+
.map { |index| OutlineItem.new(item(lines.fetch(index)), line: first_line + index) }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# A top-level list item, not a horizontal rule written with the same marks.
|
|
110
|
+
#: (String) -> bool
|
|
111
|
+
def item?(line) = line.match?(ITEM) && !line.match?(RULE)
|
|
112
|
+
|
|
113
|
+
# The index in the file of the body's first line, after any frontmatter.
|
|
114
|
+
#: () -> Integer
|
|
115
|
+
def body_start = (@frontmatter.closing_line || -1) + 1
|
|
116
|
+
|
|
117
|
+
#: (String) -> bool
|
|
118
|
+
def prose?(line)
|
|
119
|
+
text = line.strip
|
|
120
|
+
!text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
|
|
124
|
+
#: () -> Array[String]
|
|
125
|
+
def unfenced
|
|
126
|
+
fenced = false #: bool
|
|
127
|
+
body = @lines.drop(body_start).map(&:chomp)
|
|
128
|
+
body.map do |line|
|
|
129
|
+
fenced = !fenced if line.match?(FENCE)
|
|
130
|
+
fenced || line.match?(FENCE) ? "" : line
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# An item by its marker and its bold lead, or its opening words, with links as their text.
|
|
135
|
+
#: (String) -> String
|
|
136
|
+
def item(line)
|
|
137
|
+
marker, text = line.match(ITEM)&.captures
|
|
138
|
+
text = text.to_s.gsub(LINK, '\1')
|
|
139
|
+
"#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: OutlineSection::ITEM_CHARACTERS).by_words}"
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "locator"
|
|
6
6
|
require_relative "meta_principle"
|
|
7
|
+
require_relative "plugin_reference"
|
|
7
8
|
require_relative "report_hooks"
|
|
8
9
|
|
|
9
10
|
module Principles
|
|
@@ -31,7 +32,8 @@ module Principles
|
|
|
31
32
|
# A new member field that changes what an audit asks or records gets the next format, and
|
|
32
33
|
# Data::MapFiles::NEWEST_FORMAT moves with it.
|
|
33
34
|
FIELD_FORMATS = { "path" => 1, "section" => 1, "starting_at" => 1, "ending_at" => 1, "role" => 1,
|
|
34
|
-
"key" => 1, "check" => 2, "query" => 2
|
|
35
|
+
"key" => 1, "check" => 2, "query" => 2, "name" => 5, "reason" => 5,
|
|
36
|
+
"pinned" => 4 }.freeze #: Hash[String, Integer]
|
|
35
37
|
|
|
36
38
|
# The fields that say where a member's text is; a move replaces them whole.
|
|
37
39
|
LOCATORS = %w[path section starting_at ending_at query].freeze #: [String, String, String, String, String]
|
|
@@ -111,6 +113,22 @@ module Principles
|
|
|
111
113
|
@fields["role"]
|
|
112
114
|
end
|
|
113
115
|
|
|
116
|
+
# The short name stating its intent, which output leads with, as {"name" => NAME}; empty for a member with none.
|
|
117
|
+
# Display only: no command finds a member by it.
|
|
118
|
+
#: () -> Hash[String, String]
|
|
119
|
+
def named = @fields.slice("name")
|
|
120
|
+
|
|
121
|
+
# What add-member read of a plugin's file when it mapped it, its version and the hash of its text, which no
|
|
122
|
+
# commit holds; nil for a project file.
|
|
123
|
+
#: () -> Hash[String, String]?
|
|
124
|
+
def pinned
|
|
125
|
+
@fields["pinned"]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# The installed plugin's file the member is in, which git holds no history of; nil for a project file.
|
|
129
|
+
#: () -> PluginReference?
|
|
130
|
+
def plugin_reference = PluginReference.in(path)
|
|
131
|
+
|
|
114
132
|
# The command that enforces the member, which an audit asks the agent to run; nil when it has none.
|
|
115
133
|
#: () -> String?
|
|
116
134
|
def check
|