principles 0.1.3 → 0.1.4
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 +120 -0
- data/README.md +10 -6
- data/lib/principles/command_line.rb +15 -6
- data/lib/principles/command_routes.rb +11 -1
- 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_practices.rb +26 -0
- data/lib/principles/controllers/command.rb +29 -2
- data/lib/principles/controllers/correction.rb +15 -5
- data/lib/principles/controllers/full_audit_request.rb +38 -42
- data/lib/principles/controllers/inventory.rb +77 -71
- data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
- data/lib/principles/controllers/member_addition.rb +19 -4
- data/lib/principles/controllers/member_entries.rb +25 -6
- 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 +24 -7
- data/lib/principles/controllers/meta_principle_setup.rb +2 -2
- data/lib/principles/controllers/open_correction.rb +3 -2
- data/lib/principles/controllers/parts_to_read.rb +46 -5
- 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 +52 -0
- data/lib/principles/controllers/running_tool.rb +39 -13
- data/lib/principles/data/branches_bringing_in.rb +52 -0
- data/lib/principles/data/changes_since.rb +56 -0
- data/lib/principles/data/claude_code_home.rb +58 -0
- data/lib/principles/data/command-steps.json +91 -15
- 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 +32 -0
- data/lib/principles/data/known_marketplaces.rb +50 -0
- data/lib/principles/data/logged_request_matches.rb +138 -0
- data/lib/principles/data/logged_request_scan.rb +120 -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/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 +167 -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 +10 -1
- data/lib/principles/data/string_counts.rb +39 -0
- data/lib/principles/data/tools_on_path.rb +25 -0
- data/lib/principles/invocation_options.rb +4 -2
- data/lib/principles/launch.rb +14 -4
- 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 +128 -0
- data/lib/principles/models/carrier_kind.rb +79 -0
- data/lib/principles/models/cited_files.rb +12 -3
- data/lib/principles/models/decided_prior_findings.rb +5 -0
- 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/feature.rb +53 -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 +44 -0
- data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
- data/lib/principles/models/mapped_baseline.rb +46 -0
- 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 +14 -1
- data/lib/principles/models/member_entry.rb +56 -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 +45 -42
- data/lib/principles/models/member_reach.rb +36 -0
- data/lib/principles/models/member_snapshots.rb +23 -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_in_logged_requests.rb +240 -0
- 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/plugin_component.rb +37 -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_members.rb +15 -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 +35 -29
- data/lib/principles/models/project_history.rb +19 -5
- data/lib/principles/models/recorded_members.rb +7 -0
- data/lib/principles/models/request_logging.rb +196 -0
- data/lib/principles/models/runs_from.rb +0 -5
- data/lib/principles/models/script_comments.rb +58 -0
- data/lib/principles/models/stale_request.rb +9 -0
- data/lib/principles/models/unfixed_part.rb +82 -0
- data/lib/principles/models/unresolved_plugin_members.rb +35 -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 +18 -7
- data/lib/principles/views/assessment_request.rb +8 -3
- 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 +14 -19
- data/lib/principles/views/carrier_checks.rb +40 -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_parts.rb +129 -25
- data/lib/principles/views/correction_request.rb +21 -16
- 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/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 +69 -0
- data/lib/principles/views/map_added_to.rb +14 -12
- data/lib/principles/views/map_result.rb +39 -17
- 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 +68 -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 +14 -2
- 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 +32 -6
- data/lib/principles/views/problem_result.rb +7 -15
- 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/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 +5 -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 +50 -51
- 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/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 +16 -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 +2 -2
- 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-logged-requests.md +20 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +48 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +14 -14
- 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 +10 -10
- data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +10 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +32 -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/see-whether-members-reach-the-agent.md +2 -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-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/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/set-principles-up/entry-file-passage.md +1 -1
- data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
- 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/raise-the-open-findings-waiting-on-no-one.md +1 -0
- data/lib/principles/views/request_logging_result.rb +62 -0
- data/lib/principles/views/request_part.rb +10 -4
- data/lib/principles/views/request_parts.rb +9 -0
- data/lib/principles/views/whole_file_elsewhere.rb +30 -0
- metadata +101 -4
- 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
|
@@ -7,7 +7,9 @@ require_relative "frontmatter_fields"
|
|
|
7
7
|
require_relative "member_file"
|
|
8
8
|
require_relative "text_size"
|
|
9
9
|
require_relative "agent_loads"
|
|
10
|
+
require_relative "carrier_kind"
|
|
10
11
|
require_relative "hook_commands"
|
|
12
|
+
require_relative "plugin_reference"
|
|
11
13
|
require_relative "skill_loads"
|
|
12
14
|
|
|
13
15
|
module Principles
|
|
@@ -46,6 +48,12 @@ module Principles
|
|
|
46
48
|
"when" => "not_determined", "not_derived" => "a rules folder below the project root"
|
|
47
49
|
}.freeze #: Hash[String, String]
|
|
48
50
|
|
|
51
|
+
# A file of an installed plugin, which reaches a session by the plugin's own means, such as its hooks or
|
|
52
|
+
# skills, which this tool does not derive.
|
|
53
|
+
PLUGIN_FILE = {
|
|
54
|
+
"when" => "not_determined", "not_derived" => "a file of an installed plugin"
|
|
55
|
+
}.freeze #: Hash[String, String]
|
|
56
|
+
|
|
49
57
|
# The member's loads, from its whole file as files hold it and its own lines in it; a file that cannot be
|
|
50
58
|
# read gives no size, a member that cannot be found there no size of its own, and freshness reports why.
|
|
51
59
|
#: (Data::ProjectFiles, Locator, hooks: HookCommands) -> MemberLoads
|
|
@@ -88,6 +96,11 @@ module Principles
|
|
|
88
96
|
{ "claude_code" => named.empty? ? claude_code : claude_code.merge("named_in_hooks" => named) }
|
|
89
97
|
end
|
|
90
98
|
|
|
99
|
+
# The kind of carrier the member's file is, whose practices a request names for judging and editing it; kept out
|
|
100
|
+
# of to_h, so what each assessment was judged on stays as it was.
|
|
101
|
+
#: () -> CarrierKind
|
|
102
|
+
def carrier_kind = CarrierKind.new(@path, named_in_hooks: @hooks.naming(@path).any?)
|
|
103
|
+
|
|
91
104
|
# The moments Claude Code loads the member's file at, as to_h names them.
|
|
92
105
|
#: () -> Array[String]
|
|
93
106
|
def moments
|
|
@@ -109,7 +122,9 @@ module Principles
|
|
|
109
122
|
# When Claude Code loads the file, by its facility, with the size of what loads.
|
|
110
123
|
#: () -> Hash[String, untyped]
|
|
111
124
|
def claude_code
|
|
112
|
-
|
|
125
|
+
return PLUGIN_FILE if PluginReference.in(@path)
|
|
126
|
+
|
|
127
|
+
found = loads_by_path
|
|
113
128
|
return { "when" => "no_known_carrier" } unless found
|
|
114
129
|
|
|
115
130
|
# A skill's description member costs its description at start, not the file, so it has only its own size.
|
|
@@ -157,7 +172,7 @@ module Principles
|
|
|
157
172
|
# When Claude Code loads the file, by the facility its path makes it, or nil for a path it does not load
|
|
158
173
|
# by itself.
|
|
159
174
|
#: () -> Hash[String, untyped]?
|
|
160
|
-
def
|
|
175
|
+
def loads_by_path
|
|
161
176
|
if @path.end_with?(".md")
|
|
162
177
|
facility_loads = facility&.to_h
|
|
163
178
|
return facility_loads if facility_loads
|
|
@@ -9,6 +9,8 @@ require_relative "principle_history"
|
|
|
9
9
|
require_relative "principle_mapping_history"
|
|
10
10
|
require_relative "member_state"
|
|
11
11
|
require_relative "locate_refusal"
|
|
12
|
+
require_relative "mapped_baseline"
|
|
13
|
+
require_relative "member_entry"
|
|
12
14
|
|
|
13
15
|
module Principles
|
|
14
16
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -22,20 +24,23 @@ module Principles
|
|
|
22
24
|
# from, and each member's hash and commit at the commit that mapped it where it is.
|
|
23
25
|
class Baselines
|
|
24
26
|
# The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
|
|
25
|
-
# where it is, read with the map as that commit held it
|
|
27
|
+
# where it is, read with the map as that commit held it, none outside git, or for a plugin member, which no
|
|
28
|
+
# commit holds, its version and hash as the map pinned them.
|
|
26
29
|
#: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Baselines
|
|
27
30
|
def self.of(project, members, mapping: nil)
|
|
28
31
|
records = project.audit_records
|
|
29
|
-
mapped
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
new(audit: records.readable(members.principle_id), mapped: mapped(project, members, mapping: mapping),
|
|
33
|
+
in_git: project.history.inside_git?, hashes: records.hashes_to_compare(members.principle_id),
|
|
34
|
+
mapping: mapping)
|
|
32
35
|
end
|
|
33
36
|
|
|
34
|
-
#
|
|
35
|
-
# held it.
|
|
36
|
-
#: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String,
|
|
37
|
-
def self.
|
|
37
|
+
# What this tool knew of each member's text when it was mapped: its hash at the commit that mapped it where it
|
|
38
|
+
# is, read with the map as that commit held it, or a plugin member's pin.
|
|
39
|
+
#: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String, MappedBaseline]
|
|
40
|
+
def self.mapped(project, members, mapping: nil)
|
|
38
41
|
project.principle_history(members.principle_id, mapping: mapping).mapped_baselines(members.keys)
|
|
42
|
+
.transform_values { MappedBaseline.at_commit(it.fetch("sha256"), it.fetch("commit")) }
|
|
43
|
+
.merge(members.pinned.transform_values { MappedBaseline.pinned(it) })
|
|
39
44
|
end
|
|
40
45
|
|
|
41
46
|
# Whether the project is in git, so a member with no baseline is one no commit holds yet.
|
|
@@ -49,7 +54,8 @@ module Principles
|
|
|
49
54
|
# audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
|
|
50
55
|
# completed, so a one-member audit is offered only where one would be accepted. hashes is the member
|
|
51
56
|
# hashes the record holds, which a later copy may have written, so its members are compared read-only.
|
|
52
|
-
|
|
57
|
+
# mapped holds what this tool knew of each member's text when it was mapped, by key.
|
|
58
|
+
#: (audit: AuditRecord?, mapped: Hash[String, MappedBaseline], in_git: bool,
|
|
53
59
|
#| ?hashes: RecordedHashes, ?mapping: PrincipleMappingHistory?) -> void
|
|
54
60
|
def initialize(audit:, mapped:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE, mapping: nil)
|
|
55
61
|
@hashes = hashes
|
|
@@ -66,19 +72,18 @@ module Principles
|
|
|
66
72
|
def mapping_for(key)
|
|
67
73
|
return if @hashes.hash_for(key)
|
|
68
74
|
|
|
69
|
-
@mapping if @mapped
|
|
75
|
+
@mapping if @mapped[key]&.walks_history?
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
# The hash this tool last knew for the member known by key, and what it was: the last audit's, or else its
|
|
73
|
-
# hash
|
|
79
|
+
# hash when it was mapped, with why no audit gave one; neither when it has no baseline.
|
|
74
80
|
#: (String) -> [String?, Hash[String, untyped]?]
|
|
75
81
|
def of(key)
|
|
76
82
|
if (audited = @hashes.hash_for(key))
|
|
77
83
|
[audited, { "baseline" => "audit", "commit" => @audit_base }]
|
|
78
|
-
elsif @mapped
|
|
79
|
-
|
|
80
|
-
[mapped.
|
|
81
|
-
"no_audit_because" => @hashes.empty? ? "no_audit_record" : "not_in_last_audit" }]
|
|
84
|
+
elsif (mapped = @mapped[key])
|
|
85
|
+
because = @hashes.empty? ? "no_audit_record" : "not_in_last_audit"
|
|
86
|
+
[mapped.sha256, { **mapped.since, "no_audit_because" => because }]
|
|
82
87
|
else
|
|
83
88
|
[nil, nil]
|
|
84
89
|
end
|
|
@@ -113,8 +118,9 @@ module Principles
|
|
|
113
118
|
map = project.principles.find(id)
|
|
114
119
|
members = map.members
|
|
115
120
|
mapping = PrincipleMappingHistory.load_if_linked(current: map, project: project)
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
now = project.current_by_key(members)
|
|
122
|
+
new(members: members, now: now, baselines: Baselines.of(project, members, mapping: mapping),
|
|
123
|
+
sources: plugin_sources(project, members, now))
|
|
118
124
|
rescue Error => e
|
|
119
125
|
raise unless listing_all
|
|
120
126
|
|
|
@@ -122,15 +128,31 @@ module Principles
|
|
|
122
128
|
new(members: none, now: {}, baselines: Baselines.of(project, none), unreadable: e.payload)
|
|
123
129
|
end
|
|
124
130
|
|
|
131
|
+
# Where each plugin member found now comes from, by key, at the version installed now.
|
|
132
|
+
#: (Project, PrincipleMembers, Hash[String, untyped]) -> Hash[String, Hash[String, untyped]]
|
|
133
|
+
def self.plugin_sources(project, members, now)
|
|
134
|
+
sources = {} #: Hash[String, Hash[String, untyped]]
|
|
135
|
+
members.each do |member|
|
|
136
|
+
reference = member.plugin_reference
|
|
137
|
+
next unless reference && now[member.key].is_a?(String)
|
|
138
|
+
|
|
139
|
+
sources[member.key] = project.installed_plugins.source(reference)
|
|
140
|
+
end
|
|
141
|
+
sources
|
|
142
|
+
end
|
|
143
|
+
private_class_method :plugin_sources
|
|
144
|
+
|
|
125
145
|
# now holds, for each member by key, its hash now or the refusal that says why it cannot be found.
|
|
126
146
|
# unreadable is the refusal for a map this tool could not read, which is listed as one broken entry.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
147
|
+
# sources holds where each plugin member found now comes from, by key.
|
|
148
|
+
#: (members: PrincipleMembers, now: Hash[String, untyped], baselines: Baselines,
|
|
149
|
+
#| ?unreadable: Hash[String, untyped]?, ?sources: Hash[String, Hash[String, untyped]]) -> void
|
|
150
|
+
def initialize(members:, now:, baselines:, unreadable: nil, sources: {})
|
|
130
151
|
@members = members
|
|
131
152
|
@now = now
|
|
132
153
|
@baselines = baselines
|
|
133
154
|
@unreadable = unreadable
|
|
155
|
+
@sources = sources
|
|
134
156
|
freeze
|
|
135
157
|
end
|
|
136
158
|
|
|
@@ -162,7 +184,7 @@ module Principles
|
|
|
162
184
|
# How many members no audit has assessed, compared only with the commit that mapped them, edited or not, which
|
|
163
185
|
# --short counts on stdout; none while the principle's audits wait on an upgrade.
|
|
164
186
|
#: () -> Integer
|
|
165
|
-
def never_assessed = @baselines.waiting? ? 0 : compared_with.fetch(
|
|
187
|
+
def never_assessed = @baselines.waiting? ? 0 : MappedBaseline::KINDS.sum { compared_with.fetch(it, 0) }
|
|
166
188
|
|
|
167
189
|
# The entries whose own text changed since this tool last knew it, those an audit assessed first. Given a
|
|
168
190
|
# block, each gains "history", what the block makes of its member, the hash it was compared with, and its
|
|
@@ -172,7 +194,7 @@ module Principles
|
|
|
172
194
|
def changed(&history)
|
|
173
195
|
assessed, unassessed = changed_members.partition { |member| assessed?(member) }
|
|
174
196
|
(assessed + unassessed).map do |member|
|
|
175
|
-
history ? history_entry(member, history) : entry(member)
|
|
197
|
+
history && !member.plugin_reference ? history_entry(member, history) : entry(member)
|
|
176
198
|
end
|
|
177
199
|
end
|
|
178
200
|
|
|
@@ -281,26 +303,7 @@ module Principles
|
|
|
281
303
|
|
|
282
304
|
#: (Member) -> Hash[String, untyped]
|
|
283
305
|
def entry(member)
|
|
284
|
-
|
|
285
|
-
now = @now[member.key]
|
|
286
|
-
return compared(listed, member.key, now.to_s) unless now.is_a?(Hash)
|
|
287
|
-
|
|
288
|
-
listed.merge("state" => LocateRefusal.new(now).member_state).merge(now.except("status"))
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
# listed, compared with the last audit's hash for key, or else with its hash at the commit that mapped it.
|
|
292
|
-
# An unchanged member compared only with the commit that mapped it has never been assessed, so it is
|
|
293
|
-
# counted apart from one an audit assessed: counts is read first, and "unchanged" alone reads as audited.
|
|
294
|
-
#: (Hash[String, untyped], String, String) -> Hash[String, untyped]
|
|
295
|
-
def compared(listed, key, sha)
|
|
296
|
-
then_sha, since = baseline(key)
|
|
297
|
-
return listed.merge("state" => "no_baseline") unless since
|
|
298
|
-
unless then_sha == sha
|
|
299
|
-
return listed.merge("state" => "changed", "since" => since,
|
|
300
|
-
**(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
listed.merge("state" => since["baseline"] == "mapping_commit" ? "unchanged_since_mapping" : "unchanged")
|
|
306
|
+
MemberEntry.new(principle_id, member, @now[member.key], @baselines, source: @sources[member.key]).to_h
|
|
304
307
|
end
|
|
305
308
|
|
|
306
309
|
#: (String) -> [String?, Hash[String, untyped]?]
|
|
@@ -0,0 +1,36 @@
|
|
|
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 far one member's text reached the captured requests, from the places the scan saw it: how many requests
|
|
8
|
+
# held its lines, and the most bytes of them one request held.
|
|
9
|
+
class MemberReach
|
|
10
|
+
# member is one member as the scan reports it, with its status and the places it was seen.
|
|
11
|
+
#: (Hash[String, untyped]) -> void
|
|
12
|
+
def initialize(member)
|
|
13
|
+
@member = member
|
|
14
|
+
freeze
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Its key, its id where it is now once moved, status, the requests seen holding its lines and its most bytes in
|
|
18
|
+
# one.
|
|
19
|
+
#: () -> Hash[String, untyped]
|
|
20
|
+
def to_h
|
|
21
|
+
by_request = @member.fetch("seen").group_by { it.fetch("request") }.values
|
|
22
|
+
bytes = by_request.map { |places| places.sum { it.fetch("bytes") } }
|
|
23
|
+
{ **@member.slice("member", "id"),
|
|
24
|
+
"status" => @member.fetch("status"), "seen_in" => bytes.size, "most_bytes" => bytes.max || 0 }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Its reach as to_h gives it, after its principle, with the segments it was seen in, each once: bounded by the
|
|
28
|
+
# member, however many requests and places hold it.
|
|
29
|
+
#: () -> Hash[String, untyped]
|
|
30
|
+
def listed
|
|
31
|
+
{ "principle" => @member.fetch("principle"), **to_h,
|
|
32
|
+
"segments" => @member.fetch("seen").map { it.fetch("segment") }.uniq }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "audited_member_lines"
|
|
5
5
|
require_relative "located_text"
|
|
6
|
+
require_relative "missing_files"
|
|
7
|
+
require_relative "unresolved_plugin_members"
|
|
6
8
|
|
|
7
9
|
module Principles
|
|
8
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -10,18 +12,35 @@ module Principles
|
|
|
10
12
|
# Each of a map's members by id, where it is in its file now and the hash of what it says there, as
|
|
11
13
|
# the project located them all.
|
|
12
14
|
class MemberSnapshots
|
|
13
|
-
# Locate every member before refusing, so one broken reference never hides another.
|
|
15
|
+
# Locate every member before refusing, so one broken reference never hides another. A plugin member no
|
|
16
|
+
# installed plugin gives is refused apart from the broken ones, since no move or removal in the project fixes it.
|
|
14
17
|
#: (Project, Principle) -> MemberSnapshots
|
|
15
18
|
def self.read(project, map)
|
|
19
|
+
found, broken, unresolved = located(project, map.members)
|
|
20
|
+
raise MissingFiles.new(broken, principle: map.id, history: project.history).refusal_of_map unless broken.empty?
|
|
21
|
+
|
|
22
|
+
unresolved = UnresolvedPluginMembers.new(unresolved, principle: map.id)
|
|
23
|
+
raise unresolved.refusal unless unresolved.empty?
|
|
24
|
+
|
|
25
|
+
new(found)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Each of members located by id, and the entry of each that cannot be, with its refusal: the project's
|
|
29
|
+
# members apart from the plugin members no installed plugin gives.
|
|
30
|
+
#: (Project, PrincipleMembers)
|
|
31
|
+
#| -> [Hash[String, LocatedText], Array[Hash[String, untyped]], Array[Hash[String, untyped]]]
|
|
32
|
+
def self.located(project, members)
|
|
16
33
|
broken = [] #: Array[Hash[String, untyped]]
|
|
34
|
+
unresolved = [] #: Array[Hash[String, untyped]]
|
|
17
35
|
found = {} #: Hash[String, LocatedText]
|
|
18
|
-
|
|
36
|
+
members.each do |member|
|
|
19
37
|
found[member.id] = project.located_text(member.locator)
|
|
20
38
|
rescue Error => e
|
|
21
|
-
broken << { "id" => member.id }.merge(e.payload.except("status"))
|
|
39
|
+
(member.plugin_reference ? unresolved : broken) << { "id" => member.id }.merge(e.payload.except("status"))
|
|
22
40
|
end
|
|
23
|
-
|
|
41
|
+
[found, broken, unresolved]
|
|
24
42
|
end
|
|
43
|
+
private_class_method :located
|
|
25
44
|
|
|
26
45
|
#: (Hash[String, LocatedText]) -> void
|
|
27
46
|
def initialize(by_id)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# A member's text as a host sends it. A host lists a skill by its frontmatter description's value, on one line
|
|
8
|
+
# after the skill's name, so a frontmatter field is that value alone: without its key, a block scalar's indicator
|
|
9
|
+
# or the quotes round it. Its lines are matched one by one, stripped, so a folded value's lines still match the
|
|
10
|
+
# one line the host joins them into.
|
|
11
|
+
class MemberTextAsSent
|
|
12
|
+
# The text of the member locator finds in project, a field when locator queries one.
|
|
13
|
+
#: (Project, Locator) -> MemberTextAsSent
|
|
14
|
+
def self.of(project, locator) = new(project.member_text(locator), field: !locator.query.nil?)
|
|
15
|
+
|
|
16
|
+
#: (String, field: bool) -> void
|
|
17
|
+
def initialize(text, field:)
|
|
18
|
+
@text = text
|
|
19
|
+
@field = field
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#: () -> String
|
|
24
|
+
def to_s
|
|
25
|
+
return @text unless @field
|
|
26
|
+
|
|
27
|
+
@text.sub(/\A[\w-]+:[ \t]*(?:[>|][-+]?[ \t]*\n)?/, "").sub(/\A(["'])(.*)\1\s*\z/m, '\2')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "whole_file_member_read"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# Each member of a map's lines now, by id, without their line endings, which a full audit's request parts print
|
|
10
|
+
# so the agent reads the text each member is judged on, and which members' text prints in a part of its own.
|
|
11
|
+
class MemberTexts
|
|
12
|
+
# listed is each member as the request lists it, which says whether the audit carries or judges it.
|
|
13
|
+
#: (Project, Principle, listed: Array[Hash[String, untyped]]) -> void
|
|
14
|
+
def initialize(project, map, listed:)
|
|
15
|
+
@project = project
|
|
16
|
+
@map = map
|
|
17
|
+
@listed = listed.to_h { [it.fetch("id"), it] } #: Hash[String, Hash[String, untyped]]
|
|
18
|
+
freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Each member's lines now, by id.
|
|
22
|
+
#: () -> Hash[String, Array[String]]
|
|
23
|
+
def lines
|
|
24
|
+
@map.members.to_h { [it.id, @project.member_file(it.path).lines_of(it.locator).map(&:chomp)] }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The id of each member whose text prints in a part of its own, as WholeFileMemberRead decides.
|
|
28
|
+
#: () -> Array[String]
|
|
29
|
+
def apart_ids
|
|
30
|
+
@map.members.select { read(it).text_apart? }.map(&:id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# When the request says to read each member's text part whole, by id, as WholeFileMemberRead#read_whole says.
|
|
34
|
+
#: () -> Hash[String, String]
|
|
35
|
+
def read_whole
|
|
36
|
+
@map.members.filter_map { |member| (when_read = read(member).read_whole) && [member.id, when_read] }.to_h
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
#: (Member) -> WholeFileMemberRead
|
|
42
|
+
def read(member) = WholeFileMemberRead.new(whole_file: member.whole_file?, listed: @listed.fetch(member.id))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/request_logging_folder"
|
|
5
|
+
require_relative "../error"
|
|
6
|
+
require_relative "carrier_kind"
|
|
7
|
+
require_relative "member"
|
|
8
|
+
require_relative "member_text_as_sent"
|
|
9
|
+
require_relative "misspelt_member_id"
|
|
10
|
+
|
|
11
|
+
module Principles
|
|
12
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
13
|
+
module Models
|
|
14
|
+
# Which mapped members' text the captured requests hold. Each member is measured by its lines long enough to be
|
|
15
|
+
# told apart from common text, its leading indentation stripped since a host may re-indent; rg finds the decoded
|
|
16
|
+
# request lines holding one, and each member is reported by where its lines were seen.
|
|
17
|
+
class MembersInLoggedRequests
|
|
18
|
+
# A line shorter than this, in bytes, is too common to say a member reached a request.
|
|
19
|
+
SHORTEST_LINE = 24
|
|
20
|
+
# The folder a request names when the agent read or named a captured request in it, so what is found there may
|
|
21
|
+
# be a quote of an earlier request rather than what the host loaded. rg finds lines holding it; only one naming a
|
|
22
|
+
# request file in it counts, since a member may document the folder itself.
|
|
23
|
+
QUOTED = "#{Data::RequestLoggingFolder::FOLDER}/#{Data::RequestLoggingFolder::REQUESTS}/".freeze #: String
|
|
24
|
+
QUOTING = /#{Regexp.escape(QUOTED)}\S*\.request\.json/
|
|
25
|
+
# Each status a member can have, in the order a count of them prints.
|
|
26
|
+
STATUSES = %w[present present_but_not_loaded absent not_a_carrier unmeasurable].freeze #: Array[String]
|
|
27
|
+
|
|
28
|
+
# One mapped member: its principle, its key, the member as its map holds it now, the lines it is measured by,
|
|
29
|
+
# and the kind of carrier its file is.
|
|
30
|
+
class Measured
|
|
31
|
+
#: String
|
|
32
|
+
attr_reader :principle, :member
|
|
33
|
+
|
|
34
|
+
#: Array[String]
|
|
35
|
+
attr_reader :lines
|
|
36
|
+
|
|
37
|
+
#: (principle: String, member: String, mapped: Member, text: String, carrier: CarrierKind) -> void
|
|
38
|
+
def initialize(principle:, member:, mapped:, text:, carrier:)
|
|
39
|
+
@principle = principle
|
|
40
|
+
@member = member
|
|
41
|
+
@mapped = mapped
|
|
42
|
+
@lines = text.lines.map(&:strip).select { it.bytesize >= SHORTEST_LINE }.uniq.freeze #: Array[String]
|
|
43
|
+
@carrier = carrier
|
|
44
|
+
freeze
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Its status, given where it was seen and the tools whose loading the host deferred, each as [request, path]:
|
|
48
|
+
# unmeasurable when it has no line to look for; present once seen in a place the model reads; present but not
|
|
49
|
+
# loaded when seen only inside a deferred tool; else absent, or not a carrier when no host loads its file by
|
|
50
|
+
# itself, since its absence is then expected.
|
|
51
|
+
#: (Array[Hash[String, untyped]], Array[[String, String]]) -> String
|
|
52
|
+
def status(seen, deferred)
|
|
53
|
+
return "unmeasurable" if @lines.empty?
|
|
54
|
+
return @carrier.carrier? ? "absent" : "not_a_carrier" if seen.empty?
|
|
55
|
+
|
|
56
|
+
seen.all? { inside_any?(it, deferred) } ? "present_but_not_loaded" : "present"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Where its lines were seen among matches, each place a request, path and segment, with the share of its lines
|
|
60
|
+
# there, the bytes of every occurrence of them, how many occurrences there are, and the byte offset of each in
|
|
61
|
+
# its string. holding gives the patterns each matched line holds.
|
|
62
|
+
#: (Array[Data::KeptLine], Hash[String, String?], Hash[String, Array[String]])
|
|
63
|
+
#| -> Array[Hash[String, untyped]]
|
|
64
|
+
def seen(matches, sources, holding)
|
|
65
|
+
found = matches.group_by(&:place)
|
|
66
|
+
.transform_values { occurrences(it, holding) }
|
|
67
|
+
found.reject { |_, occurring| occurring.empty? }.map do |(request, path, segment), occurring|
|
|
68
|
+
{ "request" => request, "query_source" => sources[request], "path" => path, "segment" => segment,
|
|
69
|
+
**measures(occurring) }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Its id, where it is now.
|
|
74
|
+
#: () -> String
|
|
75
|
+
def id = @mapped.id
|
|
76
|
+
|
|
77
|
+
# Whether it has no line long enough to be told apart from common text, so no logged request can show it.
|
|
78
|
+
#: () -> bool
|
|
79
|
+
def too_short? = @lines.empty?
|
|
80
|
+
|
|
81
|
+
# The move-member options that widen it, with placeholders to fill, as Member gives them.
|
|
82
|
+
#: () -> String
|
|
83
|
+
def move_placeholders = @mapped.move_placeholders
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
# Whether place, one of where it was seen, lies inside one of tools.
|
|
88
|
+
#: (Hash[String, untyped], Array[[String, String]]) -> bool
|
|
89
|
+
def inside_any?(place, tools)
|
|
90
|
+
tools.any? do |request, path|
|
|
91
|
+
place["request"] == request && (place["path"] == path || place["path"].to_s.start_with?("#{path}."))
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# What occurring, the occurrences of its lines in one place as [line, offset], measure there: the share of its
|
|
96
|
+
# lines they are, their bytes, each occurrence counted, how many there are, and where each starts.
|
|
97
|
+
#: (Array[[String, Integer]]) -> Hash[String, untyped]
|
|
98
|
+
def measures(occurring)
|
|
99
|
+
{ "share" => occurring.map(&:first).uniq.size.fdiv(@lines.size),
|
|
100
|
+
"bytes" => occurring.sum { |line, _| line.bytesize }, "count" => occurring.size,
|
|
101
|
+
"offsets" => occurring.map(&:last).sort }
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Each occurrence of its lines in matches, as [line, offset], offset the byte in its string the occurrence
|
|
105
|
+
# starts at. holding gives the patterns each matched line holds, so only those are looked for in it.
|
|
106
|
+
#: (Array[Data::KeptLine], Hash[String, Array[String]]) -> Array[[String, Integer]]
|
|
107
|
+
def occurrences(matches, holding)
|
|
108
|
+
matches.flat_map do |kept|
|
|
109
|
+
text = kept.text
|
|
110
|
+
(@lines & holding.fetch(text, [])).flat_map { |line| starts(text, line).map { [line, kept.offset + it] } }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# The byte offset of each occurrence of line in text, each found after the one before it ends.
|
|
115
|
+
#: (String, String) -> Array[Integer]
|
|
116
|
+
def starts(text, line)
|
|
117
|
+
found = [] #: Array[Integer]
|
|
118
|
+
from = 0
|
|
119
|
+
while (start = text.byteindex(line, from))
|
|
120
|
+
found << start
|
|
121
|
+
from = start + line.bytesize
|
|
122
|
+
end
|
|
123
|
+
found
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Every mapped member of project, by principle, with its text now.
|
|
128
|
+
#: (Project) -> MembersInLoggedRequests
|
|
129
|
+
def self.mapped_in(project)
|
|
130
|
+
principles = project.principles
|
|
131
|
+
new(principles.ids.flat_map { |id| measured(project, id, principles.find(id).members, &:key) })
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Every member of project's own files, not a plugin's, whose text has no line long enough to be told apart from
|
|
135
|
+
# common text, so no logged request can show whether it reached the agent; the project widens it with
|
|
136
|
+
# move-member.
|
|
137
|
+
#: (Project) -> Array[Measured]
|
|
138
|
+
def self.too_short_in(project)
|
|
139
|
+
principles = project.principles
|
|
140
|
+
principles.ids.flat_map { |id| measured(project, id, principles.find(id).members.in_project, &:key) }
|
|
141
|
+
.select(&:too_short?)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# The members of map whose ids are in listed, each named by its id as the audit's request lists it.
|
|
145
|
+
#: (Project, Principle, Array[String]) -> MembersInLoggedRequests
|
|
146
|
+
def self.listed_in(project, map, listed)
|
|
147
|
+
new(measured(project, map.id, map.members, &:id).select { listed.include?(it.member) })
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Each of members of the principle, named as name gives, with its text now as a host sends it and the kind of
|
|
151
|
+
# carrier it is.
|
|
152
|
+
#: (Project, String, PrincipleMembers) { (Member) -> String } -> Array[Measured]
|
|
153
|
+
def self.measured(project, principle, members, &name)
|
|
154
|
+
loads = project.member_loads(members)
|
|
155
|
+
members.map do |member|
|
|
156
|
+
Measured.new(principle:, member: name.call(member), mapped: member,
|
|
157
|
+
text: MemberTextAsSent.of(project, member.locator).to_s,
|
|
158
|
+
carrier: loads.fetch(member.id).carrier_kind)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
private_class_method :measured
|
|
162
|
+
|
|
163
|
+
#: (Array[Measured]) -> void
|
|
164
|
+
def initialize(members)
|
|
165
|
+
@members = members
|
|
166
|
+
freeze
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Only the members whose keys are named, so the scan looks for their lines alone; refused as unknown_member for
|
|
170
|
+
# a key no member has, naming the key it is spelled like, since a misspelt one would list nothing.
|
|
171
|
+
#: (Array[String]) -> MembersInLoggedRequests
|
|
172
|
+
def only(keys)
|
|
173
|
+
known = @members.map(&:member)
|
|
174
|
+
unknown = keys.find { !known.include?(it) }
|
|
175
|
+
raise unknown_member(unknown, known) if unknown
|
|
176
|
+
|
|
177
|
+
self.class.new(@members.select { keys.include?(it.member) })
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Every line a member is measured by, once each, and the logged request's path a quoting request holds, for
|
|
181
|
+
# the scan to find.
|
|
182
|
+
#: () -> Array[String]
|
|
183
|
+
def patterns = [*@members.flat_map(&:lines), QUOTED].uniq
|
|
184
|
+
|
|
185
|
+
# How many members have each status, every status counted, then each member with where it was seen, given the
|
|
186
|
+
# scan's requests, its matches and the tools it found deferred, how many requests the index gives no
|
|
187
|
+
# query_source, and which requests quote a logged request's path.
|
|
188
|
+
#: (Array[Hash[String, String?]], Array[Data::KeptLine], Array[[String, String]])
|
|
189
|
+
#| -> { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
|
|
190
|
+
#| quoting_requests: Array[String] }
|
|
191
|
+
def report(requests, matches, deferred)
|
|
192
|
+
members = members_seen(requests, matches, deferred)
|
|
193
|
+
{ members_by_status: by_status(members), members: members, orphans: requests.count { it["query_source"].nil? },
|
|
194
|
+
quoting_requests: matches.select { QUOTING.match?(it.text) }.map(&:request).uniq.sort }
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
private
|
|
198
|
+
|
|
199
|
+
# The refusal for key, which no mapped member has, with the one it is spelled like, if any.
|
|
200
|
+
#: (String, Array[String]) -> Error
|
|
201
|
+
def unknown_member(key, known)
|
|
202
|
+
unknown = "#{key} is not a mapped member's key"
|
|
203
|
+
repair = "Run show-members-in-logged-requests without --member to list every member's key."
|
|
204
|
+
closest = MisspeltMemberId.new(key).closest(known)
|
|
205
|
+
return Error.new("unknown_member", unknown, repair) unless closest
|
|
206
|
+
|
|
207
|
+
Error.new("unknown_member", "#{unknown}; did you mean #{closest}?", repair).including("did_you_mean" => closest)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# How many of members, as report lists them, have each status, none left out for having no member.
|
|
211
|
+
#: (Array[Hash[String, untyped]]) -> Hash[String, Integer]
|
|
212
|
+
def by_status(members) = STATUSES.to_h { |status| [status, members.count { it.fetch("status") == status }] }
|
|
213
|
+
|
|
214
|
+
#: (Array[Hash[String, String?]], Array[Data::KeptLine], Array[[String, String]])
|
|
215
|
+
#| -> Array[Hash[String, untyped]]
|
|
216
|
+
def members_seen(requests, matches, deferred)
|
|
217
|
+
sources = requests.to_h { [it.fetch("file").to_s, it["query_source"]] }
|
|
218
|
+
holding = patterns_held(matches)
|
|
219
|
+
@members.map do |member|
|
|
220
|
+
seen = member.seen(matches, sources, holding)
|
|
221
|
+
{ "principle" => member.principle, "member" => member.member, **moved_to(member),
|
|
222
|
+
"status" => member.status(seen, deferred), "seen" => seen }
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Where member is now, as its id, once a move has left its key naming where it was; nothing while they agree.
|
|
227
|
+
#: (Measured) -> Hash[String, String]
|
|
228
|
+
def moved_to(member) = member.id == member.member ? {} : { "id" => member.id }
|
|
229
|
+
|
|
230
|
+
# The patterns each distinct matched line holds. rg names only the leftmost match on a line, so two members
|
|
231
|
+
# sharing a line are both found here. The same member text recurs in every request, so the distinct lines rg
|
|
232
|
+
# matched are few, and this pass over them is bounded by that small set, not by the bodies' size.
|
|
233
|
+
#: (Array[Data::KeptLine]) -> Hash[String, Array[String]]
|
|
234
|
+
def patterns_held(matches)
|
|
235
|
+
all = patterns
|
|
236
|
+
matches.map(&:text).uniq.to_h { |line| [line, all.select { line.include?(it) }] }
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|