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,59 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
require_relative "carved_message_bytes"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# A turn opening's context split into parts by bytes, each counted as the request writes it in JSON, so the parts
|
|
11
|
+
# sum to its bytes: the system prompt, the tool definitions, those of the tools the host defers loading, the host's
|
|
12
|
+
# reminders and system notices, and the conversation, every message so far but what the host added. It gives part
|
|
13
|
+
# names and counts alone, never text.
|
|
14
|
+
class ContextParts
|
|
15
|
+
# The keys of a request holding its context.
|
|
16
|
+
KEYS = %w[system tools messages].freeze #: Array[String]
|
|
17
|
+
|
|
18
|
+
# body is the request as the host sent it.
|
|
19
|
+
#: (Hash[String, untyped]) -> void
|
|
20
|
+
def initialize(body)
|
|
21
|
+
@body = body
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Each part with its bytes, in the order a request holds them.
|
|
26
|
+
#: () -> Array[Hash[String, untyped]]
|
|
27
|
+
def to_a
|
|
28
|
+
deferred = deferred_bytes
|
|
29
|
+
carved = CarvedMessageBytes.new(Array(@body["messages"])).to_a
|
|
30
|
+
conversation = written("messages") - carved.sum { it.fetch("bytes") }
|
|
31
|
+
[{ "part" => "system_prompt", "bytes" => written("system") },
|
|
32
|
+
{ "part" => "tool_definitions", "bytes" => written("tools") - deferred },
|
|
33
|
+
{ "part" => "deferred_tool_definitions", "bytes" => deferred },
|
|
34
|
+
*carved, { "part" => "conversation", "bytes" => conversation }]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Every part's bytes together: the request's system prompt, tools and messages, each written as compact JSON.
|
|
38
|
+
#: () -> Integer
|
|
39
|
+
def bytes = KEYS.sum { written(it) }
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# The bytes of the tools the host defers loading, each as JSON writes it with the comma that parts it from
|
|
44
|
+
# another, while the request lists more than one tool.
|
|
45
|
+
#: () -> Integer
|
|
46
|
+
def deferred_bytes
|
|
47
|
+
tools = @body["tools"]
|
|
48
|
+
return 0 unless tools.is_a?(Array)
|
|
49
|
+
|
|
50
|
+
deferred = tools.select { it.is_a?(Hash) && it["defer_loading"] == true }
|
|
51
|
+
deferred.sum { JSON.generate(it).bytesize } + [deferred.size, tools.size - 1].min
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# The bytes of the request's value at key, written as compact JSON, or none where it has none.
|
|
55
|
+
#: (String) -> Integer
|
|
56
|
+
def written(key) = @body.key?(key) ? JSON.generate(@body[key]).bytesize : 0
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -72,6 +72,11 @@ module Principles
|
|
|
72
72
|
inherited.key?(id) ? { "first_raised_at" => inherited.fetch(id) } : {}
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
# Where each deferral raised again was written up and whom it waited on, by the id of the new finding it became;
|
|
76
|
+
# none in a basis printed before they were carried.
|
|
77
|
+
#: () -> Hash[String, Hash[String, untyped]]
|
|
78
|
+
def deferrals_raised_again = @fields.fetch("deferrals_raised_again", {})
|
|
79
|
+
|
|
75
80
|
# These decisions with each kept finding filed under its members' ids after moves.
|
|
76
81
|
#: (MemberMoves) -> DecidedPriorFindings
|
|
77
82
|
def moved(moves)
|
|
@@ -10,12 +10,18 @@ module Principles
|
|
|
10
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
11
11
|
module Models
|
|
12
12
|
# The changes a correction declares it made to the map after the audit began: the members it moved,
|
|
13
|
-
# and the members whose role or
|
|
13
|
+
# and the members whose role, check, name or reason a fix changed, which each fixed disposition lists in
|
|
14
14
|
# changed_map_entries, and the members fixed dispositions removed. This tool checks them against the
|
|
15
15
|
# map at the base commit, which may also hold
|
|
16
16
|
# members added since, needing no declaration, as a fix maps a member a finding said was missing (T69); whether a
|
|
17
17
|
# change fixes its finding is the agent's judgement.
|
|
18
18
|
class DeclaredMapChanges
|
|
19
|
+
# The fields of a member's entry, beside its place, that say what it is, which a fix may claim it changed.
|
|
20
|
+
CLAIMED = %w[role check name reason].freeze #: Array[String]
|
|
21
|
+
|
|
22
|
+
# Those a fix sets, as change-member-name and change-member-reason do, and never removes.
|
|
23
|
+
SAID = %w[name reason].freeze #: Array[String]
|
|
24
|
+
|
|
19
25
|
# The answer's moved_members and each disposition's changed_map_entries and removed_members.
|
|
20
26
|
#: (untyped) -> DeclaredMapChanges
|
|
21
27
|
def self.declared_in(response)
|
|
@@ -85,7 +91,7 @@ module Principles
|
|
|
85
91
|
end
|
|
86
92
|
|
|
87
93
|
# The map file, when the correction moved a member in it, even under its own id, a fix changed a
|
|
88
|
-
# member's role or
|
|
94
|
+
# member's role, check, name or reason in it, or added/removed members in it, so the agent commits it too.
|
|
89
95
|
#: (String, ?added: Array[String]) -> Array[String]
|
|
90
96
|
def files_to_commit(map_file, added: [])
|
|
91
97
|
empty? && added.empty? ? [] : [map_file]
|
|
@@ -93,7 +99,7 @@ module Principles
|
|
|
93
99
|
|
|
94
100
|
private
|
|
95
101
|
|
|
96
|
-
# Replay removals, then moves and role
|
|
102
|
+
# Replay removals, then moves and role, check, name and reason changes, then members added during the correction.
|
|
97
103
|
#: (Principle, Principle) -> Principle
|
|
98
104
|
def reconstructed(base, current)
|
|
99
105
|
retained = @removals.applied(base, current)
|
|
@@ -124,16 +130,18 @@ module Principles
|
|
|
124
130
|
end
|
|
125
131
|
return replayed(map, id, current.member(id)) unless as_at_base?(map, current, id)
|
|
126
132
|
|
|
127
|
-
raise Error.new("claimed_change_missing", "#{id}'s role and
|
|
128
|
-
|
|
129
|
-
"
|
|
133
|
+
raise Error.new("claimed_change_missing", "#{id}'s role, check, name and reason did not change during this " \
|
|
134
|
+
"audit",
|
|
135
|
+
"The role, check, name and reason of #{id} are as they were at the base commit; remove it " \
|
|
136
|
+
"from changed_map_entries.")
|
|
130
137
|
end
|
|
131
138
|
|
|
132
|
-
# The map with the member's role and check changed to now's, as change-member-role,
|
|
133
|
-
# and remove-member-check changed them.
|
|
139
|
+
# The map with the member's role, name, reason and check changed to now's, as change-member-role, -name,
|
|
140
|
+
# -reason, change-member-check and remove-member-check changed them; no command removes a name or reason.
|
|
134
141
|
#: (Principle, String, Hash[String, untyped]) -> Principle
|
|
135
142
|
def replayed(map, id, now)
|
|
136
|
-
|
|
143
|
+
said = (SAID & now.keys).reduce(map) { |each, field| each.saying(id, field, now.fetch(field)) }
|
|
144
|
+
roled = said.changing_role(id, now.fetch("role"))
|
|
137
145
|
return roled.changing_check(id, now.fetch("check")) if now.key?("check")
|
|
138
146
|
|
|
139
147
|
roled.member(id).key?("check") ? roled.removing_check(id) : roled
|
|
@@ -141,13 +149,13 @@ module Principles
|
|
|
141
149
|
|
|
142
150
|
#: (String, Hash[String, untyped], Hash[String, untyped]) -> Hash[String, untyped]
|
|
143
151
|
def changed_fields(id, was, now)
|
|
144
|
-
changed =
|
|
152
|
+
changed = CLAIMED.reject { |field| was[field] == now[field] }
|
|
145
153
|
{ "member_id" => id, **changed.to_h { |field| [field, { "was" => was[field], "now" => now[field] }] } }
|
|
146
154
|
end
|
|
147
155
|
|
|
148
156
|
#: (Principle, Principle, String) -> bool
|
|
149
157
|
def as_at_base?(map, current, id)
|
|
150
|
-
map.member(id)
|
|
158
|
+
CLAIMED.all? { |field| map.member(id)[field] == current.member(id)[field] }
|
|
151
159
|
end
|
|
152
160
|
|
|
153
161
|
#: (String, String) -> Error
|
|
@@ -160,8 +168,9 @@ module Principles
|
|
|
160
168
|
Error.new("stale_map", "The map of #{principle_id} changed during this audit",
|
|
161
169
|
"If you moved a member to fix a finding, declare it in the answer's moved_members as " \
|
|
162
170
|
"{\"from\": OLD_ID, \"to\": NEW_ID}, and a move that kept its id, as narrowing or widening a " \
|
|
163
|
-
"passage, as {\"from\": ID, \"to\": ID}; if a fix changed a member's role
|
|
164
|
-
"member's id in that fixed disposition's changed_map_entries. If a fix removed a
|
|
171
|
+
"passage, as {\"from\": ID, \"to\": ID}; if a fix changed a member's role, check, name or reason, " \
|
|
172
|
+
"list the member's id in that fixed disposition's changed_map_entries. If a fix removed a " \
|
|
173
|
+
"member with " \
|
|
165
174
|
"remove-member, list its original id in that fixed disposition's removed_members. " \
|
|
166
175
|
"In git, a member you added with " \
|
|
167
176
|
"add-member needs no declaration, as long as nothing else changed.\n" \
|
|
@@ -8,6 +8,8 @@ require_relative "answer_text"
|
|
|
8
8
|
require_relative "disposition_placeholders"
|
|
9
9
|
require_relative "disposition_text_field"
|
|
10
10
|
require_relative "fix_only_fields"
|
|
11
|
+
require_relative "plugin_reference"
|
|
12
|
+
require_relative "unfixed_part"
|
|
11
13
|
require_relative "unfinished_field"
|
|
12
14
|
require_relative "waits_on"
|
|
13
15
|
require_relative "write_up_pointer"
|
|
@@ -24,13 +26,14 @@ module Principles
|
|
|
24
26
|
ACTIONS = %w[fixed deferred accepted disagreed].freeze #: Array[String]
|
|
25
27
|
|
|
26
28
|
# at is the disposition's place in the answer, such as /dispositions/0, which a refusal about its pointers names.
|
|
27
|
-
# samples is the answer guide's disposition for each action, whose text illustrates each field.
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
# samples is the answer guide's disposition for each action, whose text illustrates each field. subject is whose
|
|
30
|
+
# disposition a refusal names it as: its finding's, or the unfixed part's of the fix that gives it.
|
|
31
|
+
#: (untyped, AnswerFields, at: String, samples: Hash[String, untyped], ?subject: String) -> void
|
|
32
|
+
def initialize(disposition, fields, at:, samples:, subject: "Finding #{disposition["finding_id"]}")
|
|
30
33
|
@disposition = disposition
|
|
31
34
|
@fields = fields
|
|
32
35
|
@samples = samples
|
|
33
|
-
@place = AnswerPlace.new(at,
|
|
36
|
+
@place = AnswerPlace.new(at, subject) #: AnswerPlace
|
|
34
37
|
freeze
|
|
35
38
|
end
|
|
36
39
|
|
|
@@ -75,7 +78,19 @@ module Principles
|
|
|
75
78
|
# left empty, as the template's placeholder or as the answer guide's sample, and so a fix's reassessment,
|
|
76
79
|
# which applies to no other action, and a waits_on left as the guide's sample.
|
|
77
80
|
#: () -> Array[UnfinishedField]
|
|
78
|
-
def unfinished = [*unchosen_action, *unwritten_text, *waits_on_left_as_sample]
|
|
81
|
+
def unfinished = [*unchosen_action, *unwritten_text, *waits_on_left_as_sample, *unfixed_part&.unfinished]
|
|
82
|
+
|
|
83
|
+
# The part of its finding a fix leaves unfixed, as the agent gave it, or nil when it gives none.
|
|
84
|
+
#: () -> UnfixedPart?
|
|
85
|
+
def unfixed_part
|
|
86
|
+
part = @disposition["unfixed_part"]
|
|
87
|
+
return unless part
|
|
88
|
+
|
|
89
|
+
place = AnswerPlace.new(@place.child("unfixed_part").pointer, "Finding #{finding_id} unfixed_part")
|
|
90
|
+
own = Disposition.new(part.except("id", "problem").merge("finding_id" => part["id"]), @fields,
|
|
91
|
+
at: place.pointer, samples: @samples, subject: place.subject)
|
|
92
|
+
UnfixedPart.new(part, of: self, outcome: own, place:)
|
|
93
|
+
end
|
|
79
94
|
|
|
80
95
|
# The members this disposition claims it changed, refusing it unless its other fields are sound: only a fix
|
|
81
96
|
# claims any, and each must be among the members that changed. CorrectionAnswer has checked its action and
|
|
@@ -84,6 +99,7 @@ module Principles
|
|
|
84
99
|
def claimed_members(changed)
|
|
85
100
|
action = @disposition["action"]
|
|
86
101
|
checked_fields
|
|
102
|
+
unfixed_part&.check
|
|
87
103
|
members = @fields.array(fix_fields.list("changed_members"), "changed_members")
|
|
88
104
|
entries = @disposition.fetch("changed_map_entries", []) + @disposition.fetch("removed_members", [])
|
|
89
105
|
action == "fixed" ? fixed_members(members, entries, changed) : fix_fields.unclaimed(members, entries)
|
|
@@ -131,6 +147,7 @@ module Principles
|
|
|
131
147
|
# claims a map entry instead, which DeclaredMapChanges has checked changed.
|
|
132
148
|
#: (Array[untyped], Array[untyped], Array[String]) -> Array[untyped]
|
|
133
149
|
def fixed_members(members, entries, changed)
|
|
150
|
+
refuse_plugin_members(members)
|
|
134
151
|
return members unless (members.empty? && entries.empty?) || (members - changed).any?
|
|
135
152
|
|
|
136
153
|
raise Error.new("claimed_change_missing",
|
|
@@ -138,6 +155,20 @@ module Principles
|
|
|
138
155
|
"Make the authorised change and reassess it, or record a deferral.")
|
|
139
156
|
end
|
|
140
157
|
|
|
158
|
+
# A fix never claims a plugin's member changed, whatever its text did: principles never edits an installed
|
|
159
|
+
# plugin's files, which the plugin's next update replaces.
|
|
160
|
+
#: (Array[untyped]) -> void
|
|
161
|
+
def refuse_plugin_members(members)
|
|
162
|
+
plugin = members.select { |id| id.is_a?(String) && PluginReference.in(id) }
|
|
163
|
+
return if plugin.empty?
|
|
164
|
+
|
|
165
|
+
raise Error.new("plugin_member_read_only",
|
|
166
|
+
"Finding #{finding_id} claims a fix to #{plugin.join(", ")}, read from an installed plugin, " \
|
|
167
|
+
"which principles never edits",
|
|
168
|
+
"Settle it another way: fix it in the project's own files and claim those; or set its action " \
|
|
169
|
+
"to deferred, with recorded_at {\"url\": ...} where it is raised upstream; or to accepted.")
|
|
170
|
+
end
|
|
171
|
+
|
|
141
172
|
# The disposition's evidence and recorded_at, which a deferral must give, if only as null, and the
|
|
142
173
|
# one line a deferral may give saying what it waits on.
|
|
143
174
|
#: () -> void
|
|
@@ -168,7 +199,7 @@ module Principles
|
|
|
168
199
|
#: () -> bot
|
|
169
200
|
def unrecorded_deferral
|
|
170
201
|
raise Error.new("invalid_disposition", "Deferred finding #{finding_id} has no recorded_at",
|
|
171
|
-
"Set recorded_at to where the finding is written up, as {
|
|
202
|
+
"Set recorded_at to where the finding is written up, as #{AnswerFields::WRITE_UP_FORMS}; " \
|
|
172
203
|
"or to null when it is written up nowhere.")
|
|
173
204
|
end
|
|
174
205
|
end
|
|
@@ -45,6 +45,18 @@ module Principles
|
|
|
45
45
|
before: ACTION_PLACEHOLDER) #: NamedPlaceholder
|
|
46
46
|
# Every placeholder a slot of a correction's template prints, for any finding, or printed before.
|
|
47
47
|
NAMED = [*TEXT_FIELDS.values.map(&:placeholder), ACTION, EARLIER_ACTION].freeze #: Array[NamedPlaceholder]
|
|
48
|
+
# What the correction's question prints in an unfixed part's problem and reason, as its example
|
|
49
|
+
# `"problem": ..., ... "reason": ...` in dispose-of-each-finding/fix-or-record-each-finding.md, since no
|
|
50
|
+
# template prints an unfixed part.
|
|
51
|
+
QUESTION_EXAMPLE = NamedPlaceholder.new("...", before: "...") #: NamedPlaceholder
|
|
52
|
+
# The text fields an unfixed part gives, which the agent writes: the problem it raises as a finding of its own,
|
|
53
|
+
# and why it is left, which its outcome checks too against the template's reason.
|
|
54
|
+
UNFIXED_TEXT_FIELDS = {
|
|
55
|
+
"problem" => DispositionTextField.new(placeholder: QUESTION_EXAMPLE,
|
|
56
|
+
repair: "Write the problem the fix leaves unfixed."),
|
|
57
|
+
"reason" => DispositionTextField.new(placeholder: QUESTION_EXAMPLE,
|
|
58
|
+
repair: TEXT_FIELDS.fetch("reason").repair)
|
|
59
|
+
}.freeze #: Hash[String, DispositionTextField]
|
|
48
60
|
# Every placeholder a correction's template prints, each text field's and the action's, each with its slot.
|
|
49
61
|
TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION.slotted).freeze #: Hash[String, String]
|
|
50
62
|
|
|
@@ -19,6 +19,10 @@ module Principles
|
|
|
19
19
|
#: NamedPlaceholder
|
|
20
20
|
attr_reader :placeholder
|
|
21
21
|
|
|
22
|
+
# What to write instead.
|
|
23
|
+
#: String
|
|
24
|
+
attr_reader :repair
|
|
25
|
+
|
|
22
26
|
#: (placeholder: NamedPlaceholder, repair: String) -> void
|
|
23
27
|
def initialize(placeholder:, repair:)
|
|
24
28
|
@placeholder = placeholder
|
|
@@ -0,0 +1,73 @@
|
|
|
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 thinking blocks a response says the server dropped from its request, each by its path in the request, such
|
|
8
|
+
# as messages.10.content.0. A dropped block costs no tokens, so a request's context is measured without them.
|
|
9
|
+
class DroppedThinking
|
|
10
|
+
# response is the response as the host logged it, or nil for none.
|
|
11
|
+
#: (untyped) -> void
|
|
12
|
+
def initialize(response)
|
|
13
|
+
# Deepest and latest first, so leaving one out moves no index another names.
|
|
14
|
+
@paths = listed(response).map { it.split(".") }.sort_by { |keys| keys.map { sortable(it) } }
|
|
15
|
+
.reverse.freeze #: Array[Array[String]]
|
|
16
|
+
freeze
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# body without each dropped block, body itself left as it was; a path naming nothing in it is passed over.
|
|
20
|
+
#: (untyped) -> untyped
|
|
21
|
+
def from(body) = @paths.reduce(body) { |kept, keys| without(kept, keys) }
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# The path of each block response says was dropped.
|
|
26
|
+
#: (untyped) -> Array[String]
|
|
27
|
+
def listed(response)
|
|
28
|
+
transformations = response.is_a?(Hash) ? Array(response["input_transformations"]) : []
|
|
29
|
+
transformations.filter_map { it["path"] if it.is_a?(Hash) && it["type"] == "thinking_dropped" }.grep(String)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# A key as it sorts beside its siblings: an index by its number, before any name.
|
|
33
|
+
#: (String) -> [Integer, Integer, String]
|
|
34
|
+
def sortable(key)
|
|
35
|
+
index = index_of(key)
|
|
36
|
+
index ? [0, index, ""] : [1, 0, key]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The array index key names, or nil for a key that is no index.
|
|
40
|
+
#: (String?) -> Integer?
|
|
41
|
+
def index_of(key) = key&.match?(/\A\d+\z/) ? key.to_i : nil
|
|
42
|
+
|
|
43
|
+
# value without what keys name in it, copied only along the way there; value itself where keys name nothing.
|
|
44
|
+
#: (untyped, Array[String]) -> untyped
|
|
45
|
+
def without(value, keys)
|
|
46
|
+
key, *rest = keys
|
|
47
|
+
case value
|
|
48
|
+
when Array then without_at(value, index_of(key), rest)
|
|
49
|
+
when Hash then without_key(value, key.to_s, rest)
|
|
50
|
+
else value
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# hash without key, or without what rest names under it; hash itself where it has no key.
|
|
55
|
+
#: (Hash[untyped, untyped], String, Array[String]) -> Hash[untyped, untyped]
|
|
56
|
+
def without_key(hash, key, rest)
|
|
57
|
+
return hash unless hash.key?(key)
|
|
58
|
+
|
|
59
|
+
rest.empty? ? hash.except(key) : hash.merge(key => without(hash[key], rest))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# list without the element at index, or without what rest names inside it; list itself where index is none.
|
|
63
|
+
#: (Array[untyped], Integer?, Array[String]) -> Array[untyped]
|
|
64
|
+
def without_at(list, index, rest)
|
|
65
|
+
return list unless index && index < list.size
|
|
66
|
+
|
|
67
|
+
copy = list.dup
|
|
68
|
+
rest.empty? ? copy.delete_at(index) : copy[index] = without(list[index], rest)
|
|
69
|
+
copy
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
# A feature that runs fast standard tools in place of Ruby, on only while every tool it needs is on PATH, with
|
|
10
|
+
# no Ruby fallback. TOOLS is the one central table of them, so no command checks PATH
|
|
11
|
+
# itself.
|
|
12
|
+
class Feature
|
|
13
|
+
# The command that scans the logged requests, which a full audit's request also runs.
|
|
14
|
+
LOGGED_REQUEST_SCAN = "show-members-in-logged-requests"
|
|
15
|
+
|
|
16
|
+
# Each feature's command, and the tools it runs, each with what it does there.
|
|
17
|
+
TOOLS = {
|
|
18
|
+
LOGGED_REQUEST_SCAN => {
|
|
19
|
+
"jq" => "decodes each captured request into its text lines",
|
|
20
|
+
"rg" => "finds mapped members' lines in the decoded requests"
|
|
21
|
+
},
|
|
22
|
+
"show-context-budget" => { "jq" => "reads each captured request's shape, to find the turns it opened" }
|
|
23
|
+
}.freeze #: Hash[String, Hash[String, String]]
|
|
24
|
+
|
|
25
|
+
# The feature command runs, with on_path saying whether PATH holds a tool.
|
|
26
|
+
#: (String, on_path: ^(String) -> bool) -> void
|
|
27
|
+
def initialize(command, on_path:)
|
|
28
|
+
@command = command
|
|
29
|
+
@tools = TOOLS.fetch(command) #: Hash[String, String]
|
|
30
|
+
@on_path = on_path
|
|
31
|
+
freeze
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Refuses while a tool the feature runs is not on PATH, naming the first missing and what it does, so the agent
|
|
35
|
+
# asks the user to install it.
|
|
36
|
+
#: () -> void
|
|
37
|
+
def refuse_while_off
|
|
38
|
+
refusal = off_refusal
|
|
39
|
+
raise refusal if refusal
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The refusal the feature gives while a tool it runs is not on PATH, or nil while it is on; for a command that
|
|
43
|
+
# carries on without the feature, such as a full audit's request without its logged-request evidence.
|
|
44
|
+
#: () -> Error?
|
|
45
|
+
def off_refusal
|
|
46
|
+
tool, does = @tools.find { |name, _| !@on_path.call(name) }
|
|
47
|
+
return unless tool
|
|
48
|
+
|
|
49
|
+
Error.new("fast_tools_missing", "#{@command} needs #{tool}, which #{does}, and #{tool} is not on PATH.",
|
|
50
|
+
"Ask the user before installing #{tool}, then run this again.")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "decided_prior_findings"
|
|
5
|
+
require_relative "recorded_finding"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The findings a completed full audit records: each finding its assessment raised, with its correction's
|
|
11
|
+
# disposition, each prior finding the audit kept, and each finding a fix raised from the part of its finding it
|
|
12
|
+
# left unfixed.
|
|
13
|
+
class FindingOutcomes
|
|
14
|
+
# findings are those the assessment raised, dispositions the correction's, one for each, and prior the
|
|
15
|
+
# decisions on the findings the last audit left open.
|
|
16
|
+
#: (Array[untyped], Array[Disposition], DecidedPriorFindings) -> void
|
|
17
|
+
def initialize(findings, dispositions, prior)
|
|
18
|
+
@findings = findings
|
|
19
|
+
@dispositions = dispositions
|
|
20
|
+
@prior = prior
|
|
21
|
+
freeze
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Each finding's outcome: its members and its disposition's action, where it is recorded, if anywhere, and
|
|
25
|
+
# what a deferral says it waits on, if anything.
|
|
26
|
+
# Then each prior finding kept; a new finding that raises one again keeps when it was first raised. Then each
|
|
27
|
+
# finding raised from an unfixed part, which keeps when the finding it was part of was first raised.
|
|
28
|
+
#: () -> Array[untyped]
|
|
29
|
+
def recorded
|
|
30
|
+
raised = @findings.map do |finding|
|
|
31
|
+
id = finding.fetch("id")
|
|
32
|
+
outcome = disposition_of(id).recorded_outcome
|
|
33
|
+
finding.slice(*RecordedFinding::RAISED_FIELDS).merge(outcome, @prior.first_raised(id))
|
|
34
|
+
end + @prior.kept
|
|
35
|
+
@findings.reduce(raised) { |so_far, finding| with_unfixed_part(so_far, finding) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
#: (untyped) -> Disposition
|
|
41
|
+
def disposition_of(id) = @dispositions.find { |each| each.finding_id == id } || raise(KeyError, id)
|
|
42
|
+
|
|
43
|
+
# recorded, with the finding raised from the part of finding its fix left unfixed, if any, refused when an id
|
|
44
|
+
# in recorded is its id.
|
|
45
|
+
#: (Array[untyped], Hash[String, untyped]) -> Array[untyped]
|
|
46
|
+
def with_unfixed_part(recorded, finding)
|
|
47
|
+
id = finding.fetch("id")
|
|
48
|
+
part = disposition_of(id).unfixed_part
|
|
49
|
+
return recorded unless part
|
|
50
|
+
|
|
51
|
+
recorded + [part.raised_from(finding, recorded.map { it.fetch("id") }).merge(@prior.first_raised(id))]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -7,7 +7,7 @@ module Principles
|
|
|
7
7
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
8
|
module Models
|
|
9
9
|
# Every finding the records leave open, deferred or accepted, as one fact the session-start line states: how
|
|
10
|
-
# many wait, and which has waited longest.
|
|
10
|
+
# many deferred wait, and which of them has waited longest.
|
|
11
11
|
class FindingsLeftOpen
|
|
12
12
|
# The findings each record leaves open for the next full audit.
|
|
13
13
|
#: (Array[AuditRecord]) -> FindingsLeftOpen
|
|
@@ -19,19 +19,17 @@ module Principles
|
|
|
19
19
|
freeze
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
# How many
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
# waits_on was asked, which a later audit may have given it.
|
|
22
|
+
# How many someone should raise, those deferred, how many of them have no waits_on and how many one, and the
|
|
23
|
+
# first raised earliest of them as it has waited until now, or nil when none is deferred: an accepted finding
|
|
24
|
+
# waits on no one by design, so every start counts the same. How long it waited runs from first_raised_at,
|
|
25
|
+
# never from when its waits_on was asked, which a later audit may have given it.
|
|
26
26
|
#: (Time) -> Hash[String, untyped]?
|
|
27
27
|
def waiting_at(now)
|
|
28
|
-
|
|
28
|
+
deferred = @findings.select { it.action == "deferred" }
|
|
29
|
+
oldest = deferred.min_by(&:first_raised_time) or return nil
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ "count" => @findings.length, "waiting_on_no_one_named" => unnamed,
|
|
33
|
-
"waiting_on_someone_named" => named.length, "to_raise" => named.length + unnamed,
|
|
34
|
-
"oldest_waiting_on_someone" => named.min_by(&:first_raised_time)&.waited_at(now), **oldest.waited_at(now) }
|
|
31
|
+
{ "count" => deferred.length, "waiting_on_no_one_named" => deferred.count(&:waiting_on_no_one_named?),
|
|
32
|
+
"waiting_on_someone_named" => deferred.count(&:waiting_on_someone_named?), **oldest.waited_at(now) }
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
end
|
|
@@ -10,7 +10,8 @@ module Principles
|
|
|
10
10
|
# Which repositories' HEAD a shell call moved by committing, each named once, in the order the call's
|
|
11
11
|
# directories name them, with the commit HEAD named before the move: what report-after-commit reports on. A
|
|
12
12
|
# checkout or a reset moves HEAD to commits that exist already, so neither is named; the next session start
|
|
13
|
-
# shows any change there. A project never mapped, under the folder's name now or its earlier one, is not named
|
|
13
|
+
# shows any change there. A project never mapped, under the folder's name now or its earlier one, is not named,
|
|
14
|
+
# nor a repository other than the session's project's, such as a scratch clone; its worktrees are named.
|
|
14
15
|
class HeadMoves
|
|
15
16
|
# One repository's move: its root, and the full sha HEAD named before it.
|
|
16
17
|
class Move
|
|
@@ -28,9 +29,12 @@ module Principles
|
|
|
28
29
|
# The reflog subjects of moves that bring in no new commit.
|
|
29
30
|
NOT_A_COMMIT = /\A(?:checkout|reset):/ #: Regexp
|
|
30
31
|
|
|
32
|
+
# What git says of a directory on this machine.
|
|
33
|
+
GIT_AT = ->(directory) { Data::HeadReflog.new(directory) } #: ^(String) -> untyped
|
|
34
|
+
|
|
31
35
|
# git_at gives what git says of a directory, as Data::HeadReflog does.
|
|
32
36
|
#: (AfterCommitInput, ?^(String) -> untyped) -> void
|
|
33
|
-
def initialize(input, git_at =
|
|
37
|
+
def initialize(input, git_at = GIT_AT)
|
|
34
38
|
@input = input
|
|
35
39
|
@git_at = git_at
|
|
36
40
|
freeze
|
|
@@ -38,20 +42,33 @@ module Principles
|
|
|
38
42
|
|
|
39
43
|
#: () -> Array[Move]
|
|
40
44
|
def to_a
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
git = @git_at.call(directory)
|
|
44
|
-
root = git.toplevel
|
|
45
|
-
next if root.nil? || seen.include?(root)
|
|
46
|
-
|
|
47
|
-
seen << root
|
|
45
|
+
project = nil #: String?
|
|
46
|
+
repositories.filter_map do |root, git|
|
|
48
47
|
before = git.mapped? && before_the_move(git)
|
|
49
|
-
|
|
48
|
+
next unless before && git.common_dir == (project ||= the_sessions_repository)
|
|
49
|
+
|
|
50
|
+
Move.new(root:, before:)
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
private
|
|
54
55
|
|
|
56
|
+
# The git folder of the session's project, which its worktrees share and a clone does not, or a value no
|
|
57
|
+
# repository's matches when the session's directory is outside git. Asked only once a repository moved, so a
|
|
58
|
+
# call that committed nothing costs no more git.
|
|
59
|
+
#: () -> String
|
|
60
|
+
def the_sessions_repository = @git_at.call(@input.session_directory).common_dir || ""
|
|
61
|
+
|
|
62
|
+
# Each repository the call's directories are in, once, in their order: what git says of it, by its root.
|
|
63
|
+
#: () -> Hash[String, untyped]
|
|
64
|
+
def repositories
|
|
65
|
+
@input.directories.each_with_object({}) do |directory, found|
|
|
66
|
+
git = @git_at.call(directory)
|
|
67
|
+
root = git.toplevel
|
|
68
|
+
found[root] ||= git if root
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
55
72
|
# The commit HEAD named before it moved during the call, or nil when it did not move then, or moved to no
|
|
56
73
|
# new commit. Without a reflog, HEAD's committer time stands in, and the commit before HEAD starts the range.
|
|
57
74
|
#: (untyped) -> String?
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "digest"
|
|
5
|
+
require_relative "plugin_install"
|
|
6
|
+
require_relative "plugin_reference"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# A file of an installed plugin as a session here would read it: its reference, the install it is in and its
|
|
12
|
+
# text, read once.
|
|
13
|
+
class InstalledComponent
|
|
14
|
+
#: String
|
|
15
|
+
attr_reader :text
|
|
16
|
+
|
|
17
|
+
#: (PluginReference, PluginInstall, String) -> void
|
|
18
|
+
def initialize(reference, install, text)
|
|
19
|
+
@reference = reference
|
|
20
|
+
@install = install
|
|
21
|
+
@text = text
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The version the host installed, for the agent's information only.
|
|
26
|
+
#: () -> String?
|
|
27
|
+
def version = @install.version
|
|
28
|
+
|
|
29
|
+
# The member's path in its map, as its reference names it.
|
|
30
|
+
#: () -> String
|
|
31
|
+
def member_path = @reference.to_s
|
|
32
|
+
|
|
33
|
+
# What the map pins of it: the version installed, and the hash of its text, which alone says whether it changed.
|
|
34
|
+
#: () -> Hash[String, String]
|
|
35
|
+
def pinned = { "version" => version.to_s, "sha256" => Digest::SHA256.hexdigest(@text) }
|
|
36
|
+
|
|
37
|
+
# Where it comes from, as a result prints it.
|
|
38
|
+
#: () -> Hash[String, untyped]
|
|
39
|
+
def source = @reference.source(version)
|
|
40
|
+
|
|
41
|
+
# Its entry in a map, playing the part played gives: its role, and any name, reason and check.
|
|
42
|
+
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
43
|
+
def member(played) = { "path" => member_path, **played, "pinned" => pinned }
|
|
44
|
+
|
|
45
|
+
# What add-member reports of it: its id, the lines it spans and where it comes from. No host's loading of a
|
|
46
|
+
# plugin's file is derived yet.
|
|
47
|
+
#: () -> Hash[String, untyped]
|
|
48
|
+
def added = { "id" => member_path, **lines, "loading" => "not_derived", "source" => source }
|
|
49
|
+
|
|
50
|
+
# The lines it spans: the whole file.
|
|
51
|
+
#: () -> Hash[String, Integer]
|
|
52
|
+
def lines = { "first_line" => 1, "last_line" => [@text.lines.size, 1].max }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|