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,56 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "locate_refusal"
|
|
5
|
+
require_relative "mapped_baseline"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# One member as list-member-problems lists it: its principle, id and state against what this tool last knew of
|
|
11
|
+
# its text, with what a changed member was compared with, or, when it cannot be found, its refusal.
|
|
12
|
+
class MemberEntry
|
|
13
|
+
# now is the member's hash now, or the refusal that says why it cannot be found. source is where a plugin
|
|
14
|
+
# member found now comes from, at the version installed now.
|
|
15
|
+
#: (String, Member, untyped, MemberProblems::Baselines, ?source: Hash[String, untyped]?) -> void
|
|
16
|
+
def initialize(principle_id, member, now, baselines, source: nil)
|
|
17
|
+
@principle_id = principle_id
|
|
18
|
+
@member = member
|
|
19
|
+
@now = now #: untyped
|
|
20
|
+
@baselines = baselines
|
|
21
|
+
@source = source
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#: () -> Hash[String, untyped]
|
|
26
|
+
def to_h
|
|
27
|
+
listed = { "principle" => @principle_id, "id" => @member.id }
|
|
28
|
+
now = @now
|
|
29
|
+
return compared(listed, now.to_s).merge(@source ? { "source" => @source } : {}) unless now.is_a?(Hash)
|
|
30
|
+
# A plugin member found in no installed plugin, for any reason, is one quiet state, not broken, so a teammate
|
|
31
|
+
# without the plugin, or with it in a shape this tool does not read, keeps every other member and map.
|
|
32
|
+
return listed.merge("state" => "plugin_unresolved", "reason" => now.fetch("code")) if @member.plugin_reference
|
|
33
|
+
|
|
34
|
+
listed.merge("state" => LocateRefusal.new(now).member_state).merge(now.except("status"))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
# listed, compared with the last audit's hash for the member, or else with its hash at the commit that mapped
|
|
40
|
+
# it. An unchanged member compared only with the commit that mapped it has never been assessed, so it is
|
|
41
|
+
# counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited.
|
|
42
|
+
#: (Hash[String, untyped], String) -> Hash[String, untyped]
|
|
43
|
+
def compared(listed, sha)
|
|
44
|
+
then_sha, since = @baselines.of(@member.key)
|
|
45
|
+
return listed.merge("state" => "no_baseline") unless since
|
|
46
|
+
unless then_sha == sha
|
|
47
|
+
return listed.merge("state" => "changed", "since" => since,
|
|
48
|
+
**(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
assessed = !MappedBaseline::KINDS.include?(since["baseline"])
|
|
52
|
+
listed.merge("state" => assessed ? "unchanged" : "unchanged_since_mapping")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../prose_list"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# What justifies a new member's place in its principle: a name stating its intent and a reason its carrier puts the
|
|
11
|
+
# principle in context only when its work is in hand. A principle bloats when members are added at will, so a new
|
|
12
|
+
# member needs both.
|
|
13
|
+
class MemberJustification
|
|
14
|
+
# The options that justify a member, as the agent types them.
|
|
15
|
+
OPTIONS = %w[--name --reason].freeze #: Array[String]
|
|
16
|
+
|
|
17
|
+
# One a reason may follow: what it says, ending in what would show it false.
|
|
18
|
+
EXAMPLE = "--name \"Name things for their purpose\" --reason \"CLAUDE.md loads in every session, and naming is " \
|
|
19
|
+
"in hand in every session; false if no turn opening holds it in a reminder, or only " \
|
|
20
|
+
"seen_only_as_read lists it\""
|
|
21
|
+
|
|
22
|
+
# given is the name and reason the agent gave, by field, each absent when not given.
|
|
23
|
+
#: (Hash[String, untyped]) -> void
|
|
24
|
+
def initialize(given)
|
|
25
|
+
@given = given
|
|
26
|
+
freeze
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Refuses unless both a name and a reason are given, naming those missing; one left as its placeholder in a
|
|
30
|
+
# printed command, NAME or REASON, is missing.
|
|
31
|
+
#: () -> void
|
|
32
|
+
def check
|
|
33
|
+
missing = OPTIONS.reject { |option| given?(option.delete_prefix("--")) }
|
|
34
|
+
return if missing.empty?
|
|
35
|
+
|
|
36
|
+
raise Error.new("unjustified_member",
|
|
37
|
+
"A new member needs --name and --reason; #{ProseList.new(missing)} " \
|
|
38
|
+
"#{missing.one? ? "is" : "are"} missing",
|
|
39
|
+
"Give --name, a short name stating what the member makes the agent do, and --reason, why " \
|
|
40
|
+
"its carrier and place put the principle in context when its work is in hand and keep it " \
|
|
41
|
+
"out otherwise, ending in the observation that would show it false, by host channel or " \
|
|
42
|
+
"seen_only_as_read. For example: #{EXAMPLE}")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# Whether field was given as more than the placeholder a printed command leaves for it, NAME or REASON.
|
|
48
|
+
#: (String) -> bool
|
|
49
|
+
def given?(field) = !@given[field].nil? && @given[field] != field.upcase
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -64,6 +64,17 @@ module Principles
|
|
|
64
64
|
{ **regions.shown, "lines" => counts }
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
# Its changed regions with context unchanged lines around each, as a full audit's request shows a whole file
|
|
68
|
+
# whose text changed beside the text it reads apart; left out once both sides' lines pass half the bytes of
|
|
69
|
+
# its text now, since the text, read whole, then costs less than the regions beside it.
|
|
70
|
+
#: (context: Integer) -> Hash[String, untyped]
|
|
71
|
+
def regions(context:)
|
|
72
|
+
found = ChangedRegions.new(@at_baseline, @now, hunks: LineDiff.new(@at_baseline, @now).hunks, context:)
|
|
73
|
+
return { "omitted" => "over_half_the_text" } if 2 * bytes(found.lines) > @now.sum(&:bytesize)
|
|
74
|
+
|
|
75
|
+
found.shown
|
|
76
|
+
end
|
|
77
|
+
|
|
67
78
|
private
|
|
68
79
|
|
|
69
80
|
# How many bytes the sides' lines hold together.
|
|
@@ -7,7 +7,9 @@ require_relative "frontmatter_fields"
|
|
|
7
7
|
require_relative "member_file"
|
|
8
8
|
require_relative "text_size"
|
|
9
9
|
require_relative "agent_loads"
|
|
10
|
+
require_relative "carrier_kind"
|
|
10
11
|
require_relative "hook_commands"
|
|
12
|
+
require_relative "plugin_reference"
|
|
11
13
|
require_relative "skill_loads"
|
|
12
14
|
|
|
13
15
|
module Principles
|
|
@@ -46,6 +48,12 @@ module Principles
|
|
|
46
48
|
"when" => "not_determined", "not_derived" => "a rules folder below the project root"
|
|
47
49
|
}.freeze #: Hash[String, String]
|
|
48
50
|
|
|
51
|
+
# A file of an installed plugin, which reaches a session by the plugin's own means, such as its hooks or
|
|
52
|
+
# skills, which this tool does not derive.
|
|
53
|
+
PLUGIN_FILE = {
|
|
54
|
+
"when" => "not_determined", "not_derived" => "a file of an installed plugin"
|
|
55
|
+
}.freeze #: Hash[String, String]
|
|
56
|
+
|
|
49
57
|
# The member's loads, from its whole file as files hold it and its own lines in it; a file that cannot be
|
|
50
58
|
# read gives no size, a member that cannot be found there no size of its own, and freshness reports why.
|
|
51
59
|
#: (Data::ProjectFiles, Locator, hooks: HookCommands) -> MemberLoads
|
|
@@ -88,6 +96,11 @@ module Principles
|
|
|
88
96
|
{ "claude_code" => named.empty? ? claude_code : claude_code.merge("named_in_hooks" => named) }
|
|
89
97
|
end
|
|
90
98
|
|
|
99
|
+
# The kind of carrier the member's file is, whose practices a request names for judging and editing it; kept out
|
|
100
|
+
# of to_h, so what each assessment was judged on stays as it was.
|
|
101
|
+
#: () -> CarrierKind
|
|
102
|
+
def carrier_kind = CarrierKind.new(@path, named_in_hooks: @hooks.naming(@path).any?)
|
|
103
|
+
|
|
91
104
|
# The moments Claude Code loads the member's file at, as to_h names them.
|
|
92
105
|
#: () -> Array[String]
|
|
93
106
|
def moments
|
|
@@ -109,7 +122,9 @@ module Principles
|
|
|
109
122
|
# When Claude Code loads the file, by its facility, with the size of what loads.
|
|
110
123
|
#: () -> Hash[String, untyped]
|
|
111
124
|
def claude_code
|
|
112
|
-
|
|
125
|
+
return PLUGIN_FILE if PluginReference.in(@path)
|
|
126
|
+
|
|
127
|
+
found = loads_by_path
|
|
113
128
|
return { "when" => "no_known_carrier" } unless found
|
|
114
129
|
|
|
115
130
|
# A skill's description member costs its description at start, not the file, so it has only its own size.
|
|
@@ -157,7 +172,7 @@ module Principles
|
|
|
157
172
|
# When Claude Code loads the file, by the facility its path makes it, or nil for a path it does not load
|
|
158
173
|
# by itself.
|
|
159
174
|
#: () -> Hash[String, untyped]?
|
|
160
|
-
def
|
|
175
|
+
def loads_by_path
|
|
161
176
|
if @path.end_with?(".md")
|
|
162
177
|
facility_loads = facility&.to_h
|
|
163
178
|
return facility_loads if facility_loads
|
|
@@ -9,6 +9,9 @@ require_relative "principle_history"
|
|
|
9
9
|
require_relative "principle_mapping_history"
|
|
10
10
|
require_relative "member_state"
|
|
11
11
|
require_relative "locate_refusal"
|
|
12
|
+
require_relative "mapped_baseline"
|
|
13
|
+
require_relative "member_entry"
|
|
14
|
+
require_relative "member_snapshots"
|
|
12
15
|
|
|
13
16
|
module Principles
|
|
14
17
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -22,20 +25,23 @@ module Principles
|
|
|
22
25
|
# from, and each member's hash and commit at the commit that mapped it where it is.
|
|
23
26
|
class Baselines
|
|
24
27
|
# The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
|
|
25
|
-
# where it is, read with the map as that commit held it
|
|
28
|
+
# where it is, read with the map as that commit held it, none outside git, or for a plugin member, which no
|
|
29
|
+
# commit holds, its version and hash as the map pinned them.
|
|
26
30
|
#: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Baselines
|
|
27
31
|
def self.of(project, members, mapping: nil)
|
|
28
32
|
records = project.audit_records
|
|
29
|
-
mapped
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
new(audit: records.readable(members.principle_id), mapped: mapped(project, members, mapping: mapping),
|
|
34
|
+
in_git: project.history.inside_git?, hashes: records.hashes_to_compare(members.principle_id),
|
|
35
|
+
mapping: mapping)
|
|
32
36
|
end
|
|
33
37
|
|
|
34
|
-
#
|
|
35
|
-
# held it.
|
|
36
|
-
#: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String,
|
|
37
|
-
def self.
|
|
38
|
+
# What this tool knew of each member's text when it was mapped: its hash at the commit that mapped it where it
|
|
39
|
+
# is, read with the map as that commit held it, or a plugin member's pin.
|
|
40
|
+
#: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String, MappedBaseline]
|
|
41
|
+
def self.mapped(project, members, mapping: nil)
|
|
38
42
|
project.principle_history(members.principle_id, mapping: mapping).mapped_baselines(members.keys)
|
|
43
|
+
.transform_values { MappedBaseline.at_commit(it.fetch("sha256"), it.fetch("commit")) }
|
|
44
|
+
.merge(members.pinned.transform_values { MappedBaseline.pinned(it) })
|
|
39
45
|
end
|
|
40
46
|
|
|
41
47
|
# Whether the project is in git, so a member with no baseline is one no commit holds yet.
|
|
@@ -49,7 +55,8 @@ module Principles
|
|
|
49
55
|
# audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
|
|
50
56
|
# completed, so a one-member audit is offered only where one would be accepted. hashes is the member
|
|
51
57
|
# hashes the record holds, which a later copy may have written, so its members are compared read-only.
|
|
52
|
-
|
|
58
|
+
# mapped holds what this tool knew of each member's text when it was mapped, by key.
|
|
59
|
+
#: (audit: AuditRecord?, mapped: Hash[String, MappedBaseline], in_git: bool,
|
|
53
60
|
#| ?hashes: RecordedHashes, ?mapping: PrincipleMappingHistory?) -> void
|
|
54
61
|
def initialize(audit:, mapped:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE, mapping: nil)
|
|
55
62
|
@hashes = hashes
|
|
@@ -66,19 +73,18 @@ module Principles
|
|
|
66
73
|
def mapping_for(key)
|
|
67
74
|
return if @hashes.hash_for(key)
|
|
68
75
|
|
|
69
|
-
@mapping if @mapped
|
|
76
|
+
@mapping if @mapped[key]&.walks_history?
|
|
70
77
|
end
|
|
71
78
|
|
|
72
79
|
# The hash this tool last knew for the member known by key, and what it was: the last audit's, or else its
|
|
73
|
-
# hash
|
|
80
|
+
# hash when it was mapped, with why no audit gave one; neither when it has no baseline.
|
|
74
81
|
#: (String) -> [String?, Hash[String, untyped]?]
|
|
75
82
|
def of(key)
|
|
76
83
|
if (audited = @hashes.hash_for(key))
|
|
77
84
|
[audited, { "baseline" => "audit", "commit" => @audit_base }]
|
|
78
|
-
elsif @mapped
|
|
79
|
-
|
|
80
|
-
[mapped.
|
|
81
|
-
"no_audit_because" => @hashes.empty? ? "no_audit_record" : "not_in_last_audit" }]
|
|
85
|
+
elsif (mapped = @mapped[key])
|
|
86
|
+
because = @hashes.empty? ? "no_audit_record" : "not_in_last_audit"
|
|
87
|
+
[mapped.sha256, { **mapped.since, "no_audit_because" => because }]
|
|
82
88
|
else
|
|
83
89
|
[nil, nil]
|
|
84
90
|
end
|
|
@@ -113,8 +119,9 @@ module Principles
|
|
|
113
119
|
map = project.principles.find(id)
|
|
114
120
|
members = map.members
|
|
115
121
|
mapping = PrincipleMappingHistory.load_if_linked(current: map, project: project)
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
now = MemberSnapshots.hashes_by_key(project, members)
|
|
123
|
+
new(members: members, now: now, baselines: Baselines.of(project, members, mapping: mapping),
|
|
124
|
+
sources: plugin_sources(project, members, now))
|
|
118
125
|
rescue Error => e
|
|
119
126
|
raise unless listing_all
|
|
120
127
|
|
|
@@ -122,15 +129,31 @@ module Principles
|
|
|
122
129
|
new(members: none, now: {}, baselines: Baselines.of(project, none), unreadable: e.payload)
|
|
123
130
|
end
|
|
124
131
|
|
|
132
|
+
# Where each plugin member found now comes from, by key, at the version installed now.
|
|
133
|
+
#: (Project, PrincipleMembers, Hash[String, untyped]) -> Hash[String, Hash[String, untyped]]
|
|
134
|
+
def self.plugin_sources(project, members, now)
|
|
135
|
+
sources = {} #: Hash[String, Hash[String, untyped]]
|
|
136
|
+
members.each do |member|
|
|
137
|
+
reference = member.plugin_reference
|
|
138
|
+
next unless reference && now[member.key].is_a?(String)
|
|
139
|
+
|
|
140
|
+
sources[member.key] = project.installed_plugins.source(reference)
|
|
141
|
+
end
|
|
142
|
+
sources
|
|
143
|
+
end
|
|
144
|
+
private_class_method :plugin_sources
|
|
145
|
+
|
|
125
146
|
# now holds, for each member by key, its hash now or the refusal that says why it cannot be found.
|
|
126
147
|
# unreadable is the refusal for a map this tool could not read, which is listed as one broken entry.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
# sources holds where each plugin member found now comes from, by key.
|
|
149
|
+
#: (members: PrincipleMembers, now: Hash[String, untyped], baselines: Baselines,
|
|
150
|
+
#| ?unreadable: Hash[String, untyped]?, ?sources: Hash[String, Hash[String, untyped]]) -> void
|
|
151
|
+
def initialize(members:, now:, baselines:, unreadable: nil, sources: {})
|
|
130
152
|
@members = members
|
|
131
153
|
@now = now
|
|
132
154
|
@baselines = baselines
|
|
133
155
|
@unreadable = unreadable
|
|
156
|
+
@sources = sources
|
|
134
157
|
freeze
|
|
135
158
|
end
|
|
136
159
|
|
|
@@ -162,7 +185,7 @@ module Principles
|
|
|
162
185
|
# How many members no audit has assessed, compared only with the commit that mapped them, edited or not, which
|
|
163
186
|
# --short counts on stdout; none while the principle's audits wait on an upgrade.
|
|
164
187
|
#: () -> Integer
|
|
165
|
-
def never_assessed = @baselines.waiting? ? 0 : compared_with.fetch(
|
|
188
|
+
def never_assessed = @baselines.waiting? ? 0 : MappedBaseline::KINDS.sum { compared_with.fetch(it, 0) }
|
|
166
189
|
|
|
167
190
|
# The entries whose own text changed since this tool last knew it, those an audit assessed first. Given a
|
|
168
191
|
# block, each gains "history", what the block makes of its member, the hash it was compared with, and its
|
|
@@ -172,7 +195,7 @@ module Principles
|
|
|
172
195
|
def changed(&history)
|
|
173
196
|
assessed, unassessed = changed_members.partition { |member| assessed?(member) }
|
|
174
197
|
(assessed + unassessed).map do |member|
|
|
175
|
-
history ? history_entry(member, history) : entry(member)
|
|
198
|
+
history && !member.plugin_reference ? history_entry(member, history) : entry(member)
|
|
176
199
|
end
|
|
177
200
|
end
|
|
178
201
|
|
|
@@ -281,26 +304,7 @@ module Principles
|
|
|
281
304
|
|
|
282
305
|
#: (Member) -> Hash[String, untyped]
|
|
283
306
|
def entry(member)
|
|
284
|
-
|
|
285
|
-
now = @now[member.key]
|
|
286
|
-
return compared(listed, member.key, now.to_s) unless now.is_a?(Hash)
|
|
287
|
-
|
|
288
|
-
listed.merge("state" => LocateRefusal.new(now).member_state).merge(now.except("status"))
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
# listed, compared with the last audit's hash for key, or else with its hash at the commit that mapped it.
|
|
292
|
-
# An unchanged member compared only with the commit that mapped it has never been assessed, so it is
|
|
293
|
-
# counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited.
|
|
294
|
-
#: (Hash[String, untyped], String, String) -> Hash[String, untyped]
|
|
295
|
-
def compared(listed, key, sha)
|
|
296
|
-
then_sha, since = baseline(key)
|
|
297
|
-
return listed.merge("state" => "no_baseline") unless since
|
|
298
|
-
unless then_sha == sha
|
|
299
|
-
return listed.merge("state" => "changed", "since" => since,
|
|
300
|
-
**(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
listed.merge("state" => since["baseline"] == "mapping_commit" ? "unchanged_since_mapping" : "unchanged")
|
|
307
|
+
MemberEntry.new(principle_id, member, @now[member.key], @baselines, source: @sources[member.key]).to_h
|
|
304
308
|
end
|
|
305
309
|
|
|
306
310
|
#: (String) -> [String?, Hash[String, untyped]?]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "request_channel"
|
|
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 one member's text reached the captured requests, from the places the scan saw it: how many requests
|
|
10
|
+
# held its lines, and the most bytes of them one request held.
|
|
11
|
+
class MemberReach
|
|
12
|
+
# member is one member as the scan reports it, with its status and the places it was seen.
|
|
13
|
+
#: (Hash[String, untyped]) -> void
|
|
14
|
+
def initialize(member)
|
|
15
|
+
@member = member
|
|
16
|
+
freeze
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Its key, its id where it is now once moved, status, the requests seen holding its lines, how many of them held
|
|
20
|
+
# it by each channel it came by, and its most bytes in one.
|
|
21
|
+
#: () -> Hash[String, untyped]
|
|
22
|
+
def to_h
|
|
23
|
+
by_request = seen.group_by { it.fetch("request") }.values
|
|
24
|
+
bytes = by_request.map { |places| places.sum { it.fetch("bytes") } }
|
|
25
|
+
{ **@member.slice("member", "id"),
|
|
26
|
+
"status" => @member.fetch("status"), "seen_in" => bytes.size, "channels" => channels,
|
|
27
|
+
"most_bytes" => bytes.max || 0 }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Its reach as to_h gives it, after its principle, with the segments it was seen in, each once: bounded by the
|
|
31
|
+
# member, however many requests and places hold it.
|
|
32
|
+
#: () -> Hash[String, untyped]
|
|
33
|
+
def listed
|
|
34
|
+
{ "principle" => @member.fetch("principle"), **to_h,
|
|
35
|
+
"segments" => seen.map { it.fetch("segment") }.uniq }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Whether it was seen, but in no channel the host loads by, so only where the agent read, sent or quoted it.
|
|
39
|
+
#: () -> bool
|
|
40
|
+
def seen_only_as_read?
|
|
41
|
+
held = channels.keys
|
|
42
|
+
held.any? && !held.intersect?(RequestChannel::HOST)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
#: () -> Array[Hash[String, untyped]]
|
|
48
|
+
def seen = @member.fetch("seen")
|
|
49
|
+
|
|
50
|
+
# How many requests held its lines by each channel, a request counted once a channel, in RequestChannel's order.
|
|
51
|
+
#: () -> Hash[String, Integer]
|
|
52
|
+
def channels
|
|
53
|
+
requests = seen.group_by { it.fetch("channel") }
|
|
54
|
+
.transform_values { |places| places.map { it.fetch("request") }.uniq.size }
|
|
55
|
+
requests.sort_by { |name, _| RequestChannel::NAMES.index(name).to_i }.to_h
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "audited_member_lines"
|
|
5
5
|
require_relative "located_text"
|
|
6
|
+
require_relative "missing_files"
|
|
7
|
+
require_relative "unresolved_plugin_members"
|
|
6
8
|
|
|
7
9
|
module Principles
|
|
8
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -10,18 +12,46 @@ module Principles
|
|
|
10
12
|
# Each of a map's members by id, where it is in its file now and the hash of what it says there, as
|
|
11
13
|
# the project located them all.
|
|
12
14
|
class MemberSnapshots
|
|
13
|
-
# Locate every member before refusing, so one broken reference never hides another.
|
|
15
|
+
# Locate every member before refusing, so one broken reference never hides another. A plugin member no
|
|
16
|
+
# installed plugin gives is refused apart from the broken ones, since no move or removal in the project fixes it.
|
|
14
17
|
#: (Project, Principle) -> MemberSnapshots
|
|
15
18
|
def self.read(project, map)
|
|
19
|
+
found, broken, unresolved = located(project, map.members)
|
|
20
|
+
raise MissingFiles.new(broken, principle: map.id, history: project.history).refusal_of_map unless broken.empty?
|
|
21
|
+
|
|
22
|
+
unresolved = UnresolvedPluginMembers.new(unresolved, principle: map.id)
|
|
23
|
+
raise unresolved.refusal unless unresolved.empty?
|
|
24
|
+
|
|
25
|
+
new(found)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Each of members' hash now by key, or the refusal that says why its text cannot be found or read, so every
|
|
29
|
+
# member is listed whether or not it can be located.
|
|
30
|
+
#: (Project, PrincipleMembers) -> Hash[String, untyped]
|
|
31
|
+
def self.hashes_by_key(project, members)
|
|
32
|
+
members.to_h do |member|
|
|
33
|
+
[member.key, project.located_text(member.locator).sha256]
|
|
34
|
+
rescue Error => e
|
|
35
|
+
[member.key, e.payload]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Each of members located by id, and the entry of each that cannot be, with its refusal: the project's
|
|
40
|
+
# members apart from the plugin members no installed plugin gives.
|
|
41
|
+
#: (Project, PrincipleMembers)
|
|
42
|
+
#| -> [Hash[String, LocatedText], Array[Hash[String, untyped]], Array[Hash[String, untyped]]]
|
|
43
|
+
def self.located(project, members)
|
|
16
44
|
broken = [] #: Array[Hash[String, untyped]]
|
|
45
|
+
unresolved = [] #: Array[Hash[String, untyped]]
|
|
17
46
|
found = {} #: Hash[String, LocatedText]
|
|
18
|
-
|
|
47
|
+
members.each do |member|
|
|
19
48
|
found[member.id] = project.located_text(member.locator)
|
|
20
49
|
rescue Error => e
|
|
21
|
-
broken << { "id" => member.id }.merge(e.payload.except("status"))
|
|
50
|
+
(member.plugin_reference ? unresolved : broken) << { "id" => member.id }.merge(e.payload.except("status"))
|
|
22
51
|
end
|
|
23
|
-
|
|
52
|
+
[found, broken, unresolved]
|
|
24
53
|
end
|
|
54
|
+
private_class_method :located
|
|
25
55
|
|
|
26
56
|
#: (Hash[String, LocatedText]) -> void
|
|
27
57
|
def initialize(by_id)
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
# A member's text as a host sends it. A host lists a skill by its frontmatter description's value, on one line
|
|
8
|
+
# after the skill's name, so a frontmatter field is that value alone: without its key, a block scalar's indicator
|
|
9
|
+
# or the quotes round it. Its lines are matched one by one, stripped, so a folded value's lines still match the
|
|
10
|
+
# one line the host joins them into.
|
|
11
|
+
class MemberTextAsSent
|
|
12
|
+
# The text of the member locator finds in project, a field when locator queries one.
|
|
13
|
+
#: (Project, Locator) -> MemberTextAsSent
|
|
14
|
+
def self.of(project, locator) = new(project.member_text(locator), field: !locator.query.nil?)
|
|
15
|
+
|
|
16
|
+
#: (String, field: bool) -> void
|
|
17
|
+
def initialize(text, field:)
|
|
18
|
+
@text = text
|
|
19
|
+
@field = field
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#: () -> String
|
|
24
|
+
def to_s
|
|
25
|
+
return @text unless @field
|
|
26
|
+
|
|
27
|
+
@text.sub(/\A[\w-]+:[ \t]*(?:[>|][-+]?[ \t]*\n)?/, "").sub(/\A(["'])(.*)\1\s*\z/m, '\2')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "whole_file_member_read"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# Each member of a map's lines now, by id, without their line endings, which a full audit's request parts print
|
|
10
|
+
# so the agent reads the text each member is judged on, and which members' text prints in a part of its own.
|
|
11
|
+
class MemberTexts
|
|
12
|
+
# listed is each member as the request lists it, which says whether the audit carries or judges it.
|
|
13
|
+
#: (Project, Principle, listed: Array[Hash[String, untyped]]) -> void
|
|
14
|
+
def initialize(project, map, listed:)
|
|
15
|
+
@project = project
|
|
16
|
+
@map = map
|
|
17
|
+
@listed = listed.to_h { [it.fetch("id"), it] } #: Hash[String, Hash[String, untyped]]
|
|
18
|
+
freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Each member's lines now, by id.
|
|
22
|
+
#: () -> Hash[String, Array[String]]
|
|
23
|
+
def lines
|
|
24
|
+
@map.members.to_h { [it.id, @project.member_file(it.path).lines_of(it.locator).map(&:chomp)] }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The id of each member whose text prints in a part of its own, as WholeFileMemberRead decides.
|
|
28
|
+
#: () -> Array[String]
|
|
29
|
+
def apart_ids
|
|
30
|
+
@map.members.select { read(it).text_apart? }.map(&:id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# When the request says to read each member's text part whole, by id, as WholeFileMemberRead#read_whole says.
|
|
34
|
+
#: () -> Hash[String, String]
|
|
35
|
+
def read_whole
|
|
36
|
+
@map.members.filter_map { |member| (when_read = read(member).read_whole) && [member.id, when_read] }.to_h
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
#: (Member) -> WholeFileMemberRead
|
|
42
|
+
def read(member) = WholeFileMemberRead.new(whole_file: member.whole_file?, listed: @listed.fetch(member.id))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
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 bytes of mapped members' text one request sent, by principle and by the part of its context each was sent
|
|
8
|
+
# in, from where MembersInLoggedRequests saw them. Each occurrence costs its bytes, so a member sent twice counts
|
|
9
|
+
# twice in bytes and once among the members. It gives principle ids and counts alone, never text (034).
|
|
10
|
+
class MembersByPart
|
|
11
|
+
# The part of a request's context each host channel sends; any other channel is the conversation's.
|
|
12
|
+
PARTS = { "system" => "system_prompt", "tool_definition" => "tool_definitions", "reminder" => "reminders",
|
|
13
|
+
"system_message" => "system_notices" }.freeze #: Hash[String, String]
|
|
14
|
+
# The parts in the order ContextParts lists them.
|
|
15
|
+
ORDER = %w[system_prompt tool_definitions deferred_tool_definitions reminders system_notices
|
|
16
|
+
conversation].freeze #: Array[String]
|
|
17
|
+
|
|
18
|
+
# Each request's members by part, by request file, from members as MembersInLoggedRequests reports them, each
|
|
19
|
+
# with the places it was seen, and deferred, each tool a request defers loading as [request, path].
|
|
20
|
+
#: (Array[Hash[String, untyped]], ?Array[[String, String]]) -> Hash[String, MembersByPart]
|
|
21
|
+
def self.by_request(members, deferred = [])
|
|
22
|
+
places = members.flat_map { |member| member.fetch("seen").map { [member, it] } }
|
|
23
|
+
places.group_by { |_, place| place.fetch("request").to_s }.to_h do |request, held|
|
|
24
|
+
tools = deferred.filter_map { |at, path| path if at == request }
|
|
25
|
+
[request, new(held.map { |member, place| sent(member, place, tools) })]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Several requests' members by part together, as a session's turn openings sent them.
|
|
30
|
+
#: (Array[MembersByPart]) -> MembersByPart
|
|
31
|
+
def self.together(each) = new(each.flat_map(&:held))
|
|
32
|
+
|
|
33
|
+
# Where member was seen at place, as [principle, member, part, bytes]: a tool among deferred, the paths of
|
|
34
|
+
# those the request defers loading, is its own part.
|
|
35
|
+
#: (Hash[String, untyped], Hash[String, untyped], Array[String]) -> [String, String, String, Integer]
|
|
36
|
+
def self.sent(member, place, deferred)
|
|
37
|
+
path = place.fetch("path").to_s
|
|
38
|
+
part = if deferred.any? { path == it || path.start_with?("#{it}.") } then "deferred_tool_definitions"
|
|
39
|
+
else PARTS.fetch(place.fetch("channel"), "conversation")
|
|
40
|
+
end
|
|
41
|
+
[member.fetch("principle"), member.fetch("member"), part, place.fetch("bytes")]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# held is each place a member was seen, as [principle, member, part, bytes].
|
|
45
|
+
#: (Array[[String, String, String, Integer]]) -> void
|
|
46
|
+
def initialize(held)
|
|
47
|
+
@held = held
|
|
48
|
+
freeze
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#: Array[[String, String, String, Integer]]
|
|
52
|
+
attr_reader :held
|
|
53
|
+
|
|
54
|
+
# Each principle's members seen in each part, how many distinct members and the bytes of every occurrence, by
|
|
55
|
+
# principle and in the parts' order.
|
|
56
|
+
#: () -> Array[Hash[String, untyped]]
|
|
57
|
+
def to_a
|
|
58
|
+
@held.group_by { |principle, _, part| [principle, part] }
|
|
59
|
+
.sort_by { |(principle, part), _| [principle, ORDER.index(part) || ORDER.size] }
|
|
60
|
+
.map do |(principle, part), seen|
|
|
61
|
+
{ "principle" => principle, "part" => part, "members" => seen.map { it[1] }.uniq.size,
|
|
62
|
+
"bytes" => seen.sum(&:last) }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|