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,58 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "outline_section"
|
|
5
|
+
require_relative "without_prose"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# A script's or configuration file's text as its outline reads it: its whole-line `#` comments, where a hook or a
|
|
11
|
+
# CI check writes the rule it enforces, which a survey reading Markdown headings alone never found.
|
|
12
|
+
class ScriptComments
|
|
13
|
+
include WithoutProse
|
|
14
|
+
|
|
15
|
+
# A whole-line comment and its text, past any indent and the space after the mark.
|
|
16
|
+
COMMENT = /\A\s*#\s?(.*)/
|
|
17
|
+
# A first line naming the script's interpreter, which is no comment.
|
|
18
|
+
SHEBANG = /\A#!/
|
|
19
|
+
# A Ruby magic comment, such as frozen_string_literal or Sorbet's typed sigil, which sets how the file runs and
|
|
20
|
+
# states no rule.
|
|
21
|
+
MAGIC = /\A#\s*(?:frozen_string_literal|typed|encoding|coding|warn_indent|shareable_constant_value):/
|
|
22
|
+
|
|
23
|
+
#: (String) -> void
|
|
24
|
+
def initialize(text)
|
|
25
|
+
@lines = text.lines.map(&:chomp) #: Array[String]
|
|
26
|
+
freeze
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# One section with no heading, its items the comments, spanning the lines from the first to the last; none when
|
|
30
|
+
# the text has no comment.
|
|
31
|
+
#: () -> Array[OutlineSection]
|
|
32
|
+
def sections
|
|
33
|
+
comments = comment_numbers
|
|
34
|
+
first = comments.first or return []
|
|
35
|
+
|
|
36
|
+
items = comments.map { |number| OutlineItem.new(item(@lines.fetch(number - 1)), line: number) }
|
|
37
|
+
[OutlineSection.new(heading: nil, items:, first_line: first, last_line: comments.fetch(-1))]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# The number in the file, counted from 1, of each line that is a comment with text.
|
|
43
|
+
#: () -> Array[Integer]
|
|
44
|
+
def comment_numbers
|
|
45
|
+
@lines.each_index.filter_map do |index|
|
|
46
|
+
line = @lines.fetch(index)
|
|
47
|
+
next if (index.zero? && line.match?(SHEBANG)) || line.match?(MAGIC)
|
|
48
|
+
|
|
49
|
+
index + 1 unless line[COMMENT, 1].to_s.strip.empty?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# A comment as its mark and its whole text, so any line can be quoted as an exact --starting-at.
|
|
54
|
+
#: (String) -> String
|
|
55
|
+
def item(line) = "# #{line[COMMENT, 1].to_s.strip}"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
require_relative "../data/request_logging_folder"
|
|
6
|
+
require_relative "../data/user_request_logging_folder"
|
|
7
|
+
require_relative "../data/repository"
|
|
8
|
+
require_relative "request_logging"
|
|
9
|
+
|
|
10
|
+
module Principles
|
|
11
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
12
|
+
module Models
|
|
13
|
+
# The sessions registered to this project while request logging is on in the user's own settings, which write
|
|
14
|
+
# every project's requests to one user-level folder: a scan keeps a request only when its session is registered
|
|
15
|
+
# here. The session-start hook registers each session from the session_id and cwd its documented input gives,
|
|
16
|
+
# never from a request's text (022 F4, F5). The registry is the repository's main checkout's, so a worktree's
|
|
17
|
+
# sessions stay registered once it is removed, and every checkout reads the same one (022 F8).
|
|
18
|
+
class SessionRegistry
|
|
19
|
+
#: (Data::UserRequestLoggingFolder, Data::Repository) -> void
|
|
20
|
+
def initialize(user_folder, repository)
|
|
21
|
+
@user_folder = user_folder
|
|
22
|
+
@repository = repository
|
|
23
|
+
freeze
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Records session_id, started in cwd, once, while the user-level folder exists, writing the folder's .gitignore
|
|
27
|
+
# first so the registry is never where git could commit it. A write that fails registers nothing and says
|
|
28
|
+
# nothing, since the hook running this prints nothing of it.
|
|
29
|
+
#: (session_id: String?, cwd: String?) -> void
|
|
30
|
+
def register(session_id:, cwd:)
|
|
31
|
+
return unless session_id && cwd && @user_folder.exist?
|
|
32
|
+
|
|
33
|
+
root = @repository.main_checkout_root
|
|
34
|
+
folder = @user_folder.registry_folder(root)
|
|
35
|
+
guard(folder)
|
|
36
|
+
@user_folder.add_project_root(root) unless @user_folder.project_roots.include?(root)
|
|
37
|
+
return if session_ids(folder).include?(session_id)
|
|
38
|
+
|
|
39
|
+
folder.append_to_registry(JSON.generate("session_id" => session_id, "cwd" => cwd))
|
|
40
|
+
rescue SystemCallError
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Each session registered, in the order it was.
|
|
45
|
+
#: (?Data::RequestLoggingFolder) -> Array[String]
|
|
46
|
+
def session_ids(folder = registry_folder) = folder.registered_session_ids
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
# The main checkout's request-logging folder, asking git for it only when called.
|
|
51
|
+
#: () -> Data::RequestLoggingFolder
|
|
52
|
+
def registry_folder = @user_folder.registry_folder(@repository.main_checkout_root)
|
|
53
|
+
|
|
54
|
+
#: (Data::RequestLoggingFolder) -> void
|
|
55
|
+
def guard(folder)
|
|
56
|
+
ignore = Data::RequestLoggingFolder::IGNORE
|
|
57
|
+
folder.write(ignore, RequestLogging::IGNORE_EVERYTHING) unless folder.files.include?(ignore)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -17,16 +17,25 @@ module Principles
|
|
|
17
17
|
#: String
|
|
18
18
|
attr_reader :source
|
|
19
19
|
|
|
20
|
+
# The session and the directory it started in, as the hook's input names them; nil when it names none.
|
|
21
|
+
#: String?
|
|
22
|
+
attr_reader :session_id, :cwd
|
|
23
|
+
|
|
20
24
|
#: (String) -> void
|
|
21
25
|
def initialize(text)
|
|
22
26
|
given = parsed(text)
|
|
23
|
-
|
|
24
|
-
@source = SOURCES.include?(
|
|
27
|
+
fields = given.is_a?(Hash) ? given : {} #: Hash[String, untyped]
|
|
28
|
+
@source = SOURCES.include?(fields["source"]) ? fields["source"].to_s : "startup" #: String
|
|
29
|
+
@session_id = named(fields["session_id"]) #: String?
|
|
30
|
+
@cwd = named(fields["cwd"]) #: String?
|
|
25
31
|
freeze
|
|
26
32
|
end
|
|
27
33
|
|
|
28
34
|
private
|
|
29
35
|
|
|
36
|
+
#: (untyped) -> String?
|
|
37
|
+
def named(value) = value.is_a?(String) && !value.empty? ? value : nil
|
|
38
|
+
|
|
30
39
|
#: (String) -> untyped
|
|
31
40
|
def parsed(text)
|
|
32
41
|
JSON.parse(text)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "turn_opening"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# How one session's context moved from its first turn opening to its last, as sent: when each was sent, how many
|
|
10
|
+
# there were, and the bytes and input tokens at each end with their change, so a session whose context grew is
|
|
11
|
+
# seen without reading every opening (034).
|
|
12
|
+
class SessionTrend
|
|
13
|
+
# openings are the session's turn openings, in the order sent, at least one.
|
|
14
|
+
#: (Array[TurnOpening]) -> void
|
|
15
|
+
def initialize(openings)
|
|
16
|
+
@openings = openings
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#: () -> Hash[String, untyped]
|
|
21
|
+
def to_h
|
|
22
|
+
first = @openings.fetch(0)
|
|
23
|
+
last = @openings.fetch(-1)
|
|
24
|
+
{ "from" => first.request_at, "to" => last.request_at, "turn_openings" => @openings.size,
|
|
25
|
+
"bytes" => moved(first.parts.bytes, last.parts.bytes),
|
|
26
|
+
"input_tokens" => moved(first.input_tokens, last.input_tokens) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# A count at each end, and its change, null where either end is.
|
|
32
|
+
#: (Integer?, Integer?) -> Hash[String, Integer?]
|
|
33
|
+
def moved(first, last) = { "first" => first, "last" => last, "change" => first && last && (last - first) }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -26,6 +26,15 @@ module Principles
|
|
|
26
26
|
freeze
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# The refusal of an answer whose audit began before the installed plugin changed the text of members, its
|
|
30
|
+
# plugin members: no fix can claim a plugin's change, so the audit starts again on the new text.
|
|
31
|
+
#: (String, Array[String]) -> Error
|
|
32
|
+
def self.plugin_updated(principle_id, members)
|
|
33
|
+
Error.new("stale_request", "This request no longer matches #{principle_id}: the installed plugin changed " \
|
|
34
|
+
"#{ProseList.new(members)} since the audit began",
|
|
35
|
+
"Start the audit again and answer the new request: #{Error::EXECUTABLE} start-audit #{principle_id}")
|
|
36
|
+
end
|
|
37
|
+
|
|
29
38
|
#: () -> Error
|
|
30
39
|
def refusal
|
|
31
40
|
Error.new("stale_request", "This request no longer matches #{@principle_id}: #{cause}", repair)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/logged_request_scan"
|
|
5
|
+
require_relative "context_parts"
|
|
6
|
+
require_relative "dropped_thinking"
|
|
7
|
+
require_relative "members_by_part"
|
|
8
|
+
require_relative "part_token_estimates"
|
|
9
|
+
require_relative "request_time"
|
|
10
|
+
|
|
11
|
+
module Principles
|
|
12
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
13
|
+
module Models
|
|
14
|
+
# A captured request that opens one of the agent's turns, whose body is the whole context the host loaded before
|
|
15
|
+
# the turn's work started, and the host's own count of the tokens it took. A request continuing a thread sends
|
|
16
|
+
# only what it adds, so only a turn opening's body is its context (034, F7). It gives counts alone, never text.
|
|
17
|
+
class TurnOpening
|
|
18
|
+
# The usage fields that together count every input token the request took, cached or not.
|
|
19
|
+
INPUT_TOKENS = %w[input_tokens cache_read_input_tokens cache_creation_input_tokens].freeze #: Array[String]
|
|
20
|
+
|
|
21
|
+
# The turn openings among scan's requests, as RequestKind labels them, grouped by session in the order their
|
|
22
|
+
# first was sent, each session's in the order they were sent.
|
|
23
|
+
# members gives, by request file, the mapped members each sent.
|
|
24
|
+
#: (Array[Hash[String, String?]], Data::LoggedRequestScan, ?Hash[String, MembersByPart])
|
|
25
|
+
#| -> Array[[String?, Array[TurnOpening]]]
|
|
26
|
+
def self.by_session(requests, scan, members = {})
|
|
27
|
+
openings = requests.select { it["turn_position"] == "turn_opening" }
|
|
28
|
+
.map { new(it, scan, members.fetch(it.fetch("file").to_s) { MembersByPart.new([]) }) }
|
|
29
|
+
openings.sort_by { RequestTime.new(it.request_at) }.group_by(&:session_id).to_a
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# request is its row as the scan lists it; its body and response are read from scan; members are the mapped
|
|
33
|
+
# members it sent.
|
|
34
|
+
#: (Hash[String, String?], Data::LoggedRequestScan, MembersByPart) -> void
|
|
35
|
+
def initialize(request, scan, members)
|
|
36
|
+
@request = request
|
|
37
|
+
@members = members
|
|
38
|
+
response = request["response_file"]
|
|
39
|
+
@response = response && scan.response(response) #: untyped
|
|
40
|
+
sent = scan.body(request.fetch("file").to_s)
|
|
41
|
+
@body = DroppedThinking.new(@response).from(sent) #: untyped
|
|
42
|
+
@dropped_bytes = ContextParts.new(sent).bytes - parts.bytes #: Integer
|
|
43
|
+
freeze
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#: () -> String?
|
|
47
|
+
def session_id = @request["session_id"]
|
|
48
|
+
|
|
49
|
+
# When it was sent, in UTC, from its index line.
|
|
50
|
+
#: () -> String?
|
|
51
|
+
def request_at = RequestTime.new(@request["timestamp"]).utc
|
|
52
|
+
|
|
53
|
+
# Its context's parts, as ContextParts splits them, without the thinking blocks its response says the server
|
|
54
|
+
# dropped; any other key of the request, such as its metadata, is not context.
|
|
55
|
+
#: () -> ContextParts
|
|
56
|
+
def parts = ContextParts.new(@body)
|
|
57
|
+
|
|
58
|
+
# Every input token its response counted, cached or not.
|
|
59
|
+
#: () -> Integer?
|
|
60
|
+
def input_tokens
|
|
61
|
+
usage = @response.is_a?(Hash) ? @response["usage"] : nil
|
|
62
|
+
INPUT_TOKENS.sum { usage.fetch(it, 0) } if usage.is_a?(Hash)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# The mapped members it sent, by principle and part.
|
|
66
|
+
#: MembersByPart
|
|
67
|
+
attr_reader :members
|
|
68
|
+
|
|
69
|
+
# Its counts, with the members it sent, as --session lists each turn opening.
|
|
70
|
+
#: () -> Hash[String, untyped]
|
|
71
|
+
def with_members = to_h.merge("members" => @members.to_a)
|
|
72
|
+
|
|
73
|
+
#: () -> Hash[String, untyped]
|
|
74
|
+
def to_h
|
|
75
|
+
split = parts
|
|
76
|
+
estimates = PartTokenEstimates.new(split.to_a, input_tokens)
|
|
77
|
+
{ "request" => @request.fetch("file"), "request_at" => request_at, "bytes" => split.bytes,
|
|
78
|
+
"dropped_bytes" => @dropped_bytes, "input_tokens" => input_tokens,
|
|
79
|
+
"bytes_per_token" => estimates.bytes_per_token, "parts" => estimates.to_a }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/request_shape"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# Whether a model turn's request opens a turn of the agent's or continues one after a tool result; only a model
|
|
10
|
+
# turn has one. The host does not say; this is a heuristic from how the request's last message ends: user or
|
|
11
|
+
# system text with no tool result opens a turn, and a tool result continues one. Text the host adds mid-turn
|
|
12
|
+
# with no tool result would read as opening one. A request ending any other way is unclassified.
|
|
13
|
+
class TurnPosition
|
|
14
|
+
# Every position, in the order counts of them print.
|
|
15
|
+
NAMES = %w[turn_opening mid_turn unclassified].freeze #: Array[String]
|
|
16
|
+
# The position each ending the scan reads names.
|
|
17
|
+
BY_ENDING = { "text" => "turn_opening", "tool_result" => "mid_turn" }.freeze #: Hash[String, String]
|
|
18
|
+
|
|
19
|
+
# How many of requests, as RequestKind labels them, are at each position, every position counted.
|
|
20
|
+
#: (Array[Hash[String, String?]]) -> Hash[String, Integer]
|
|
21
|
+
def self.counted(requests) = NAMES.to_h { |name| [name, requests.count { it["turn_position"] == name }] }
|
|
22
|
+
|
|
23
|
+
# How many of each query_source's model turns, as RequestKind labels them, are at each position, every
|
|
24
|
+
# position counted, by query_source in name order; a request the index gives no query_source is under orphan.
|
|
25
|
+
#: (Array[Hash[String, String?]]) -> Hash[String, Hash[String, Integer]]
|
|
26
|
+
def self.counted_by_query_source(requests)
|
|
27
|
+
turns = requests.select { it["turn_position"] }.group_by { it["query_source"] || "orphan" }
|
|
28
|
+
turns.sort.to_h { |source, those| [source, counted(those)] }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# shape is the model turn's request's, as Data::RequestShape gives it.
|
|
32
|
+
#: (Data::RequestShape) -> void
|
|
33
|
+
def initialize(shape)
|
|
34
|
+
@shape = shape
|
|
35
|
+
freeze
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Its position's name.
|
|
39
|
+
#: () -> String
|
|
40
|
+
def to_s = @shape.continues_thread? ? "mid_turn" : BY_ENDING.fetch(@shape.ending, "unclassified")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "answer_place"
|
|
6
|
+
require_relative "disposition_placeholders"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# The part of a finding that a fix settles only in part, which the fix leaves unfixed: raised as a finding of its
|
|
12
|
+
# own, under the id the agent gives it, deferred or accepted as a disposition is, so the record keeps both the
|
|
13
|
+
# part fixed and the part still open, rather than deferring the whole finding. Its outcome is checked as the
|
|
14
|
+
# disposition of that new finding.
|
|
15
|
+
class UnfixedPart
|
|
16
|
+
# What an unfixed part may be left as: open, since the part fixed belongs to the fix itself.
|
|
17
|
+
ACTIONS = %w[deferred accepted].freeze #: Array[String]
|
|
18
|
+
|
|
19
|
+
# part is the unfixed_part the disposition fixing in part gives, at place in the answer; outcome is part as
|
|
20
|
+
# the new finding's own disposition.
|
|
21
|
+
#: (Hash[String, untyped], of: Disposition, outcome: Disposition, place: AnswerPlace) -> void
|
|
22
|
+
def initialize(part, of:, outcome:, place:)
|
|
23
|
+
@part = part
|
|
24
|
+
@of = of
|
|
25
|
+
@outcome = outcome
|
|
26
|
+
@place = place
|
|
27
|
+
freeze
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The id of the finding it raises, as the agent gave it.
|
|
31
|
+
#: () -> untyped
|
|
32
|
+
def id = @part["id"]
|
|
33
|
+
|
|
34
|
+
# Its problem and reason when left empty or as the question's example, then each other field its outcome
|
|
35
|
+
# leaves for the agent still, as a disposition's, refusing it first when it is fixed or disagreed, which leave
|
|
36
|
+
# nothing open.
|
|
37
|
+
#: () -> Array[UnfinishedField]
|
|
38
|
+
def unfinished
|
|
39
|
+
action = @part["action"]
|
|
40
|
+
if (Disposition::ACTIONS - ACTIONS).include?(action)
|
|
41
|
+
refuse("/action", "is #{action.inspect}, not deferred or accepted",
|
|
42
|
+
"Set its action to deferred or accepted; a part fixed too belongs to the fix itself.")
|
|
43
|
+
end
|
|
44
|
+
own = DispositionPlaceholders::UNFIXED_TEXT_FIELDS.filter_map do |name, field|
|
|
45
|
+
field.left_in(@part[name], @place.child(name), name, sample: nil)
|
|
46
|
+
end
|
|
47
|
+
[*own, *@outcome.unfinished].uniq { it.field.fetch("pointer") }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Refuses it unless it belongs to a fix, and its pointers and waits_on unless they are sound, as a disposition's.
|
|
51
|
+
#: () -> void
|
|
52
|
+
def check
|
|
53
|
+
unless @of.fixed?
|
|
54
|
+
refuse("", "is only for a fix, and this disposition is #{@of.action}", "Leave unfixed_part out.")
|
|
55
|
+
end
|
|
56
|
+
@outcome.claimed_members([])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# The finding it raises from finding, the one its fix settles in part: finding's members and evidence, with its
|
|
60
|
+
# own id, problem and outcome; refused when taken, the ids of the record's other findings, holds its id.
|
|
61
|
+
#: (Hash[String, untyped], Array[untyped]) -> Hash[String, untyped]
|
|
62
|
+
def raised_from(finding, taken)
|
|
63
|
+
if taken.include?(id)
|
|
64
|
+
refuse("/id", "takes the id #{id}, which another finding has",
|
|
65
|
+
"Give it an id that no other finding in this audit's record has.")
|
|
66
|
+
end
|
|
67
|
+
{ "id" => id, **finding.slice("member_ids", "evidence"), "problem" => @part.fetch("problem"),
|
|
68
|
+
**@outcome.recorded_outcome }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
# Refuses what sits at pointer, inside the unfixed part, with problem and repair.
|
|
74
|
+
#: (String, String, String) -> bot
|
|
75
|
+
def refuse(pointer, problem, repair)
|
|
76
|
+
message = "Finding #{@of.finding_id}'s unfixed_part #{problem}"
|
|
77
|
+
raise Error.new("invalid_disposition", message, repair,
|
|
78
|
+
fields: [{ "pointer" => "#{@place.pointer}#{pointer}", "problem" => message }])
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
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 principle's plugin members no installed plugin gives, each with the refusal that says why, which no move or
|
|
10
|
+
# removal in the project fixes, so they are refused apart from its broken members.
|
|
11
|
+
class UnresolvedPluginMembers
|
|
12
|
+
# members are their entries, each its id with its refusal's code, message and repair.
|
|
13
|
+
#: (Array[Hash[String, untyped]], principle: String) -> void
|
|
14
|
+
def initialize(members, principle:)
|
|
15
|
+
@members = members
|
|
16
|
+
@principle = principle
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#: () -> bool
|
|
21
|
+
def empty? = @members.empty?
|
|
22
|
+
|
|
23
|
+
# The refusal naming each member, with its own reason and repair.
|
|
24
|
+
#: () -> Error
|
|
25
|
+
def refusal
|
|
26
|
+
ids = @members.map { |member| member.fetch("id") }
|
|
27
|
+
Error.new("plugin_members_unresolved",
|
|
28
|
+
"#{ids.length} of #{@principle}'s members are in no plugin installed for this project: " \
|
|
29
|
+
"#{ids.join(", ")}",
|
|
30
|
+
"Follow each member's repair, then run the command again.")
|
|
31
|
+
.including("principle" => @principle, "members" => @members)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../data/user_request_logging_folder"
|
|
6
|
+
require_relative "captured_sessions"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# The requests in the user-level folder, where the host writes every project's while request logging is on in
|
|
12
|
+
# the user's own settings: each session in it belongs to a project only once that project's hook registered it,
|
|
13
|
+
# so a session no listed project registered is pruned, and only counted (022 F8).
|
|
14
|
+
class UserLoggedRequests
|
|
15
|
+
# What a prune removed: how many sessions, and their files and bytes.
|
|
16
|
+
class Pruned
|
|
17
|
+
#: Integer
|
|
18
|
+
attr_reader :sessions
|
|
19
|
+
#: CapturedSessions::Tally
|
|
20
|
+
attr_reader :tally
|
|
21
|
+
|
|
22
|
+
# sessions is how many sessions lost a file, and files each file removed.
|
|
23
|
+
#: (Integer, Array[Data::CapturedRequests::CapturedFile]) -> void
|
|
24
|
+
def initialize(sessions, files)
|
|
25
|
+
@sessions = sessions
|
|
26
|
+
@tally = CapturedSessions::Tally.new(files: files.size, bytes: files.sum(&:bytes)) #: CapturedSessions::Tally
|
|
27
|
+
freeze
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#: () -> Hash[String, Integer]
|
|
31
|
+
def to_h = { "sessions" => @sessions, **@tally.to_h }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
NONE = Pruned.new(0, []) #: Pruned
|
|
35
|
+
|
|
36
|
+
#: (Data::UserRequestLoggingFolder) -> void
|
|
37
|
+
def initialize(user_folder)
|
|
38
|
+
@user_folder = user_folder
|
|
39
|
+
freeze
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Removes the files of each session the host's index names that no listed project registered, leaving a file
|
|
43
|
+
# a registered session's line also names, and every request no index line names, since one may be a running
|
|
44
|
+
# session's request in flight. It prunes nothing while no project is listed, and nothing at all while any
|
|
45
|
+
# listed registry cannot be read, since a session it holds would be removed as no one's.
|
|
46
|
+
# A file it cannot remove stops it, and it counts only what it removed.
|
|
47
|
+
#: () -> Pruned
|
|
48
|
+
def prune
|
|
49
|
+
registered = registered_sessions or return NONE
|
|
50
|
+
requests = @user_folder.requests
|
|
51
|
+
everything = CapturedSessions.new(requests.captured_files, requests.index_lines)
|
|
52
|
+
unregistered = everything.session_ids - registered
|
|
53
|
+
removed = removed(requests, everything.of(unregistered).files_apart_from(everything.of(registered)))
|
|
54
|
+
Pruned.new(losing_a_file(everything, unregistered, removed), removed)
|
|
55
|
+
rescue Error, SystemCallError
|
|
56
|
+
NONE
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
# How many of sessions lost one of the files removed.
|
|
62
|
+
#: (CapturedSessions, Array[String], Array[Data::CapturedRequests::CapturedFile]) -> Integer
|
|
63
|
+
def losing_a_file(everything, sessions, removed)
|
|
64
|
+
names = removed.map(&:name)
|
|
65
|
+
sessions.count { |id| everything.of([id]).file_names.intersect?(names) }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Each of files removed from requests, in order, until one cannot be.
|
|
69
|
+
#: (Data::CapturedRequests, Array[Data::CapturedRequests::CapturedFile])
|
|
70
|
+
#| -> Array[Data::CapturedRequests::CapturedFile]
|
|
71
|
+
def removed(requests, files)
|
|
72
|
+
done = [] #: Array[Data::CapturedRequests::CapturedFile]
|
|
73
|
+
files.each do |file|
|
|
74
|
+
requests.remove_request(file.name)
|
|
75
|
+
done << file
|
|
76
|
+
end
|
|
77
|
+
done
|
|
78
|
+
rescue SystemCallError
|
|
79
|
+
done || []
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Every session a listed project registered, or nil while no project is listed.
|
|
83
|
+
#: () -> Array[String]?
|
|
84
|
+
def registered_sessions
|
|
85
|
+
roots = @user_folder.exist? ? @user_folder.project_roots : []
|
|
86
|
+
roots.flat_map { |root| @user_folder.registry_folder(root).registered_session_ids } unless roots.empty?
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/claude_code_home"
|
|
5
|
+
require_relative "../data/user_request_logging_folder"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The env entries in the user's own Claude Code settings that turn request logging on for every session they
|
|
11
|
+
# start, from the Desktop app and IDEs as from a terminal. This tool prints them and never writes those settings:
|
|
12
|
+
# they are the user's to edit (022 F1).
|
|
13
|
+
class UserSettingsEntries
|
|
14
|
+
# The entries that switch the host's telemetry on and its exporters off, which the user may have set for
|
|
15
|
+
# telemetry of their own, so only they know whether one was added for request logging.
|
|
16
|
+
TELEMETRY_AND_EXPORTERS = %w[CLAUDE_CODE_ENABLE_TELEMETRY OTEL_METRICS_EXPORTER OTEL_LOGS_EXPORTER
|
|
17
|
+
OTEL_TRACES_EXPORTER].freeze #: Array[String]
|
|
18
|
+
|
|
19
|
+
#: (Data::ClaudeCodeHome, Data::UserRequestLoggingFolder) -> void
|
|
20
|
+
def initialize(claude_code, user_folder)
|
|
21
|
+
@claude_code = claude_code
|
|
22
|
+
@user_folder = user_folder
|
|
23
|
+
freeze
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The user's settings file, under CLAUDE_CONFIG_DIR when set.
|
|
27
|
+
#: () -> String
|
|
28
|
+
def settings_file = @claude_code.settings_file
|
|
29
|
+
|
|
30
|
+
# The entry that is request logging's alone: the host writes each request's body to the user-level folder.
|
|
31
|
+
#: () -> Hash[String, String]
|
|
32
|
+
def own = { "OTEL_LOG_RAW_API_BODIES" => "file:#{@user_folder.requests_path}" }
|
|
33
|
+
|
|
34
|
+
# The entries that turn request logging on: telemetry on, so the host logs each request's body, the entry of its
|
|
35
|
+
# own, and each exporter none, so nothing leaves the machine, apart from an exporter the user's settings set,
|
|
36
|
+
# which stays theirs; every exporter when those settings cannot be read.
|
|
37
|
+
#: () -> Hash[String, String]
|
|
38
|
+
def to_add
|
|
39
|
+
set = @claude_code.settings_env_keys || []
|
|
40
|
+
{ "CLAUDE_CODE_ENABLE_TELEMETRY" => "1", **own,
|
|
41
|
+
**(TELEMETRY_AND_EXPORTERS.drop(1) - set).to_h { [it, "none"] } }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Whether the user's settings file is there but cannot be read as settings, so every exporter entry is printed.
|
|
45
|
+
#: () -> bool
|
|
46
|
+
def settings_unreadable? = @claude_code.settings_env_keys.nil?
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
# How a full audit's request prints a whole-file member's text: in a part of its own, which the index lists and
|
|
8
|
+
# sizes, so a member's part does not print tens of kilobytes beside its metadata. A member the audit judges is
|
|
9
|
+
# read whole from that part, as a stated step of the judgement, since no diff shows a line a change elsewhere
|
|
10
|
+
# left stale, and so is a carried member a fact fires on, if the agent judges it again. A member judged for its
|
|
11
|
+
# text changing shows its changed lines beside that step: an acknowledged one in its acknowledged lines, any
|
|
12
|
+
# other in changed_lines. A passage keeps its text in its member part.
|
|
13
|
+
class WholeFileMemberRead
|
|
14
|
+
# whole_file says whether the member is a whole file; listed is the member as the request lists it, with
|
|
15
|
+
# carried_forward and flagged when its last assessment is carried, or judge_because when it is judged again.
|
|
16
|
+
#: (whole_file: bool, listed: Hash[String, untyped]) -> void
|
|
17
|
+
def initialize(whole_file:, listed:)
|
|
18
|
+
@whole_file = whole_file
|
|
19
|
+
@listed = listed
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Whether the member's text prints in a part of its own rather than in its member part.
|
|
24
|
+
#: () -> bool
|
|
25
|
+
def text_apart? = @whole_file
|
|
26
|
+
|
|
27
|
+
# When the request says to read that part whole: "judged", as a step of judging the member, or "flagged", for a
|
|
28
|
+
# carried member a fact fires on, if the agent judges it again; nil when it does not say to.
|
|
29
|
+
#: () -> String?
|
|
30
|
+
def read_whole
|
|
31
|
+
return unless @whole_file
|
|
32
|
+
return "judged" unless carried?
|
|
33
|
+
|
|
34
|
+
"flagged" if @listed["flagged"]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Whether its part shows its changed lines since the last full audit: its text changed and no acknowledgement
|
|
38
|
+
# shows the change.
|
|
39
|
+
#: () -> bool
|
|
40
|
+
def changed_lines? = @whole_file && @listed["judge_because"] == "text_changed"
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
#: () -> bool
|
|
45
|
+
def carried? = !@listed["carried_forward"].nil?
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
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 parts of a candidate outline that text other than Markdown lacks: a description and an opening line, which
|
|
8
|
+
# a script or a CI workflow, outlined by its comments or its jobs, never has.
|
|
9
|
+
module WithoutProse
|
|
10
|
+
#: () -> nil
|
|
11
|
+
def description = nil
|
|
12
|
+
|
|
13
|
+
#: () -> nil
|
|
14
|
+
def cut_description = nil
|
|
15
|
+
|
|
16
|
+
#: () -> nil
|
|
17
|
+
def opening_line = nil
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|