principles 0.1.2 → 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 +132 -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 +31 -3
- 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_acknowledgement.rb +21 -11
- 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 +45 -17
- 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 +34 -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 +15 -0
- data/lib/principles/models/acknowledgement_placeholders.rb +43 -18
- 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 +38 -7
- data/lib/principles/models/disposition_placeholders.rb +27 -7
- 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/named_placeholder.rb +17 -7
- 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 +23 -0
- 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/template_placeholders.rb +10 -9
- 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 +41 -29
- 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 +16 -16
- 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 +22 -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_brief.rb +0 -1
- data/lib/principles/views/first_audit_line.rb +4 -5
- data/lib/principles/views/invocation.rb +16 -6
- 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/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
- 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/dispose-of-each-finding/retain-assessment-and-correction.md +1 -1
- 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-answer-check.md +3 -3
- 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-open-correction.md +1 -1
- 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 +11 -11
- 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/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
- 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
|
@@ -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
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "../error"
|
|
5
|
+
require_relative "../prose_list"
|
|
5
6
|
require_relative "project_history"
|
|
6
7
|
|
|
7
8
|
module Principles
|
|
@@ -28,42 +29,66 @@ module Principles
|
|
|
28
29
|
freeze
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
# The broken members, each whose file is missing
|
|
32
|
-
#
|
|
32
|
+
# The broken members, each whose file is missing without a repair of its own, since the refusal's repair says
|
|
33
|
+
# once how to repair the members missing_files groups.
|
|
33
34
|
#: () -> Array[Hash[String, untyped]]
|
|
34
|
-
def members
|
|
35
|
-
@broken.map do |entry|
|
|
36
|
-
next entry unless missing?(entry)
|
|
37
|
-
|
|
38
|
-
entry.merge("repair" => "Its file, #{entry.fetch("path")}, is missing: see that path in missing_files, " \
|
|
39
|
-
"with any rename git detected, then run a command from repair_with.")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
35
|
+
def members = @broken.map { |entry| missing?(entry) ? entry.except("repair") : entry }
|
|
42
36
|
|
|
43
37
|
# The broken_members refusal for these members, saying how to repair each. note comes before what
|
|
44
38
|
# missing_files says, and rerun names what to run once they are repaired.
|
|
45
39
|
# rerun is the command to run once the members are repaired, or nil when it is the one the agent ran.
|
|
46
40
|
#: (String, ?rerun: String?, ?note: String) -> Error
|
|
47
41
|
def refusal(message, rerun: nil, note: "")
|
|
42
|
+
files = to_a
|
|
48
43
|
Error.new("broken_members", message,
|
|
49
44
|
"For each member listed, say whether it moved or is gone, and run the matching command in its " \
|
|
50
45
|
"repair_with: the move-member, with its NEW_PATH, HEADING, NEW_OPENING_TEXT, NEW_ENDING_TEXT or " \
|
|
51
46
|
"QUERY filled in, if it moved, or the remove-member if it is gone. #{note}#{REPAIR}" \
|
|
52
|
-
"#{rerun ? "\nThen run it again: #{rerun}" : " Then run the command again."}")
|
|
53
|
-
.including(**({ "principle" => @principle } if @principle), "members" => members, "missing_files" =>
|
|
47
|
+
"#{waiting(files)}#{rerun ? "\nThen run it again: #{rerun}" : " Then run the command again."}")
|
|
48
|
+
.including(**({ "principle" => @principle } if @principle), "members" => members, "missing_files" => files)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The broken_members refusal of the principle's map, naming each of these members.
|
|
52
|
+
#: () -> Error
|
|
53
|
+
def refusal_of_map
|
|
54
|
+
ids = @broken.map { |member| member.fetch("id") }.join(", ")
|
|
55
|
+
refusal("#{@broken.length} of #{@principle}'s members cannot be found or read: #{ids}")
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
# Each missing path, in the order first named, with the members that name it.
|
|
57
59
|
#: () -> Array[Hash[String, untyped]]
|
|
58
60
|
def to_a
|
|
59
|
-
missing = @broken.select { |entry| missing?(entry) }
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
end
|
|
61
|
+
missing = @broken.select { |entry| missing?(entry) }.group_by { |entry| entry.fetch("path") }
|
|
62
|
+
branches = brought_in(missing.keys)
|
|
63
|
+
missing.map { |path, entries| file(path, entries, branches[path]) }
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
private
|
|
66
67
|
|
|
68
|
+
# The missing path, with the entries of the members that name it, what git says of it, and on_branches, the
|
|
69
|
+
# local branches that bring it in, when any does.
|
|
70
|
+
#: (String, Array[Hash[String, untyped]], Array[String]?) -> Hash[String, untyped]
|
|
71
|
+
def file(path, entries, branches)
|
|
72
|
+
waiting_on = branches ? { "on_branches" => branches } : {}
|
|
73
|
+
{ "path" => path, "members" => entries.map { |entry| named(entry) } }.merge(renamed(path), waiting_on)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# The local branches that bring in each of paths, asked of git once, and only when a file is missing.
|
|
77
|
+
#: (Array[String]) -> Hash[String, Array[String]]
|
|
78
|
+
def brought_in(paths) = (@history&.branches_bringing_in(paths) unless paths.empty?) || {}
|
|
79
|
+
|
|
80
|
+
# What the repair says of each of files a local branch brings in: that its members may wait for that branch to
|
|
81
|
+
# merge, kept as they are, which is the agent's to judge.
|
|
82
|
+
#: (Array[Hash[String, untyped]]) -> String
|
|
83
|
+
def waiting(files)
|
|
84
|
+
files.filter_map do |file|
|
|
85
|
+
branches = file["on_branches"] or next
|
|
86
|
+
named = ProseList.new(branches, conjunction: "or").to_s
|
|
87
|
+
" #{file.fetch("path")} is on local branch #{named}, whose commits not on HEAD bring it in: if its " \
|
|
88
|
+
"members wait on that branch, keep them as they are, running neither command, until #{named} merges."
|
|
89
|
+
end.join
|
|
90
|
+
end
|
|
91
|
+
|
|
67
92
|
#: (Hash[String, untyped]) -> bool
|
|
68
93
|
def missing?(entry)
|
|
69
94
|
entry["code"] == "unreadable_file" && !entry["path"].nil?
|
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
module Principles
|
|
5
5
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
6
|
module Models
|
|
7
|
-
# A placeholder a template prints naming the id of the slot it fills, a member's or a finding's,
|
|
8
|
-
# are alike and a file-edit tool's one-match replace fills one. Its text for any id, or
|
|
9
|
-
#
|
|
7
|
+
# A placeholder a template prints naming the id of the slot it fills, a member's or a finding's, or the slot's
|
|
8
|
+
# position, so no two slots are alike and a file-edit tool's one-match replace fills one. Its text for any id, or
|
|
9
|
+
# the text it printed before, sent in any slot, is left as printed: a plain text, or an earlier NamedPlaceholder
|
|
10
|
+
# with its own earlier text, so an answer filled from any release's template is read alike.
|
|
10
11
|
class NamedPlaceholder
|
|
11
12
|
# The slot in slotted that each slot's id fills.
|
|
12
13
|
SLOT = "%<id>s" #: String
|
|
13
14
|
|
|
14
|
-
# slotted is the text with SLOT where the id goes; before is the text it printed before
|
|
15
|
-
#: (String, before: String) -> void
|
|
15
|
+
# slotted is the text with SLOT where the id goes; before is the text it printed before, plain or named.
|
|
16
|
+
#: (String, before: String | NamedPlaceholder) -> void
|
|
16
17
|
def initialize(slotted, before:)
|
|
17
18
|
@slotted = slotted
|
|
18
19
|
@before = before
|
|
@@ -24,9 +25,18 @@ module Principles
|
|
|
24
25
|
#: String
|
|
25
26
|
attr_reader :slotted
|
|
26
27
|
|
|
27
|
-
# Whether text is this placeholder, for any id or as it was printed before
|
|
28
|
+
# Whether text is this placeholder, for any id or as it was printed before.
|
|
28
29
|
#: (untyped) -> bool
|
|
29
|
-
def left?(text) =
|
|
30
|
+
def left?(text) = (text.is_a?(String) && @pattern.match?(text)) || earlier?(text)
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# Whether text is the placeholder as it was printed before.
|
|
35
|
+
#: (untyped) -> bool
|
|
36
|
+
def earlier?(text)
|
|
37
|
+
earlier = @before
|
|
38
|
+
earlier.is_a?(NamedPlaceholder) ? earlier.left?(text) : text == earlier
|
|
39
|
+
end
|
|
30
40
|
end
|
|
31
41
|
end
|
|
32
42
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "member"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The other maps whose member set nearly matches a map's once a member joins it, so two maps carrying one
|
|
11
|
+
# principle are seen as they are mapped. Nearly matching is a stated measure, compared by member id: at least
|
|
12
|
+
# SHARED members held by both, and at least SHARE of the members either holds, when the new member is one of them.
|
|
13
|
+
# It reports a fact the agent judges; it decides nothing.
|
|
14
|
+
class NearlyMatchingMaps
|
|
15
|
+
# The fewest members two maps share before their sets can nearly match; one shared member is a shared carrier.
|
|
16
|
+
SHARED = 2 #: Integer
|
|
17
|
+
|
|
18
|
+
# The least share of the members either map holds that both hold.
|
|
19
|
+
SHARE = Rational(2, 3) #: Rational
|
|
20
|
+
|
|
21
|
+
#: (Project, Principle, Member) -> void
|
|
22
|
+
def initialize(project, map, member)
|
|
23
|
+
@project = project
|
|
24
|
+
@map = map
|
|
25
|
+
@member = member
|
|
26
|
+
freeze
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Each other map nearly matching, its id with the members both hold and the members either holds. A map that
|
|
30
|
+
# cannot be read is left out, since list-member-problems reports it.
|
|
31
|
+
#: () -> Array[Hash[String, untyped]]
|
|
32
|
+
def elsewhere
|
|
33
|
+
maps = @project.principles
|
|
34
|
+
(maps.ids - [@map.id]).filter_map { |id| near(id, maps) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
#: (String, MappedPrinciples) -> Hash[String, untyped]?
|
|
40
|
+
def near(id, maps)
|
|
41
|
+
ids = member_ids(@map)
|
|
42
|
+
theirs = member_ids(maps.find(id))
|
|
43
|
+
shared = (ids & theirs).length
|
|
44
|
+
either = (ids | theirs).length
|
|
45
|
+
return unless theirs.include?(@member.id) && shared >= SHARED && Rational(shared, either) >= SHARE
|
|
46
|
+
|
|
47
|
+
{ "principle_id" => id, "shared" => shared, "members_in_either" => either }
|
|
48
|
+
rescue Error
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#: (Principle) -> Array[String]
|
|
53
|
+
def member_ids(map) = map.members.to_a.map(&:id)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "audit_record"
|
|
6
|
+
require_relative "correction_basis"
|
|
6
7
|
|
|
7
8
|
module Principles
|
|
8
9
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -52,6 +53,10 @@ module Principles
|
|
|
52
53
|
# The findings the basis asks the correction to dispose of.
|
|
53
54
|
#: () -> Array[Hash[String, untyped]]
|
|
54
55
|
def findings = @basis.fetch("findings")
|
|
56
|
+
|
|
57
|
+
# The decisions on prior findings the basis carries to completion.
|
|
58
|
+
#: () -> DecidedPriorFindings
|
|
59
|
+
def prior_decided = CorrectionBasis.new(@basis).prior_decided
|
|
55
60
|
end
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -38,13 +38,14 @@ module Principles
|
|
|
38
38
|
"audited_at" => @audited_at, "first_raised_at" => first_raised_at, **raised_in, **waiting, **kept_evidence }
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
# The finding as the next full audit's request lists it, with
|
|
42
|
-
# since when, for the agent to confirm, and each
|
|
41
|
+
# The finding as the next full audit's request lists it, with why it was left open, which for an accepted one is
|
|
42
|
+
# the owner's ruling, when it was first raised, what it waits on, since when, for the agent to confirm, and each
|
|
43
|
+
# change made to it since its record.
|
|
43
44
|
#: () -> Hash[String, untyped]
|
|
44
45
|
def for_next_audit
|
|
45
46
|
{ "finding_id" => id, "member_ids" => @finding.member_ids, **problem,
|
|
46
47
|
**present("recorded_at", recorded_at&.to_h),
|
|
47
|
-
"action" => @finding.action,
|
|
48
|
+
"action" => @finding.action, **present("reason", @finding.reason),
|
|
48
49
|
"first_raised_at" => first_raised_at, **raised_in, **waiting,
|
|
49
50
|
**present("changed_since_audit", @finding.changes_since_audit) }
|
|
50
51
|
end
|
|
@@ -38,7 +38,7 @@ module Principles
|
|
|
38
38
|
# range changed print, when there are any: they are never left out, and which to drop is the agent's call.
|
|
39
39
|
#: (Hash[String, untyped]) { (Hash[String, untyped]) -> Integer } -> Hash[String, untyped]
|
|
40
40
|
def cut(listing, &printed_bytes)
|
|
41
|
-
shortest = cut_order(listing).reduce(listing) do |shorter, (path, cuts)|
|
|
41
|
+
shortest = cut_order(listing).reduce(cut_before_budget(listing)) do |shorter, (path, cuts)|
|
|
42
42
|
return shorter if printed_bytes.call(shorter) <= BYTES
|
|
43
43
|
|
|
44
44
|
cut_file(shorter, path, cuts)
|
|
@@ -48,6 +48,15 @@ module Principles
|
|
|
48
48
|
|
|
49
49
|
private
|
|
50
50
|
|
|
51
|
+
# The listing naming under outlines_cut each file whose outline leaves items out before any cut is made.
|
|
52
|
+
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
53
|
+
def cut_before_budget(listing)
|
|
54
|
+
paths = listing.fetch("files").map { |file| file.fetch("path") }.select do |path|
|
|
55
|
+
@outlines[path]&.outline_cut?(0)
|
|
56
|
+
end
|
|
57
|
+
paths.empty? ? listing : listing.merge("outlines_cut" => paths)
|
|
58
|
+
end
|
|
59
|
+
|
|
51
60
|
# The listing every cut left past BYTES, naming what its range's outlines print, when it lists any.
|
|
52
61
|
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
53
62
|
def past_budget(listing)
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
# One item of a candidate file's outline, as printed, and the line of the file it starts on, so an outline that
|
|
8
|
+
# leaves items out can say where to read them back.
|
|
9
|
+
class OutlineItem
|
|
10
|
+
#: String
|
|
11
|
+
attr_reader :text
|
|
12
|
+
|
|
13
|
+
# Counted from 1.
|
|
14
|
+
#: Integer
|
|
15
|
+
attr_reader :line
|
|
16
|
+
|
|
17
|
+
#: (String, line: Integer) -> void
|
|
18
|
+
def initialize(text, line:)
|
|
19
|
+
@text = text
|
|
20
|
+
@line = line
|
|
21
|
+
freeze
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative "outline_item"
|
|
5
|
+
|
|
4
6
|
module Principles
|
|
5
7
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
8
|
module Models
|
|
@@ -9,6 +11,8 @@ module Principles
|
|
|
9
11
|
class OutlineSection
|
|
10
12
|
# The most items printed under one heading; a longer list says how many more it holds.
|
|
11
13
|
MOST_ITEMS = 20
|
|
14
|
+
# The most characters of an item printed, cut back to a whole word.
|
|
15
|
+
ITEM_CHARACTERS = 60
|
|
12
16
|
# A heading's marks, as many as its level.
|
|
13
17
|
MARKS = /\A#+/
|
|
14
18
|
|
|
@@ -27,7 +31,7 @@ module Principles
|
|
|
27
31
|
#: Integer
|
|
28
32
|
attr_reader :level
|
|
29
33
|
|
|
30
|
-
#: (heading: String?, items: Array[
|
|
34
|
+
#: (heading: String?, items: Array[OutlineItem], first_line: Integer, last_line: Integer) -> void
|
|
31
35
|
def initialize(heading:, items:, first_line:, last_line:)
|
|
32
36
|
@heading = heading
|
|
33
37
|
@level = heading.to_s[MARKS].to_s.length #: Integer
|
|
@@ -37,11 +41,14 @@ module Principles
|
|
|
37
41
|
freeze
|
|
38
42
|
end
|
|
39
43
|
|
|
40
|
-
# The section as the outline prints it: its heading, its items up to MOST_ITEMS, then how many more
|
|
44
|
+
# The section as the outline prints it: its heading, its items up to MOST_ITEMS, then how many more and the lines
|
|
45
|
+
# from the first of them to the section's end, so the agent reads just those back.
|
|
41
46
|
#: () -> Array[String]
|
|
42
47
|
def lines
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
left_out = @items.drop(MOST_ITEMS)
|
|
49
|
+
first = left_out.first
|
|
50
|
+
[*@heading, *@items.first(MOST_ITEMS).map(&:text),
|
|
51
|
+
*("(#{left_out.length} more, lines #{first.line}-#{@last_line})" if first)]
|
|
45
52
|
end
|
|
46
53
|
|
|
47
54
|
# The section as a cut outline prints it: its heading, then, if it holds items, how many and the lines of the file
|
|
@@ -51,6 +58,10 @@ module Principles
|
|
|
51
58
|
|
|
52
59
|
#: () -> Integer
|
|
53
60
|
def item_count = @items.length
|
|
61
|
+
|
|
62
|
+
# Whether the outline prints fewer of its items than it holds, past MOST_ITEMS.
|
|
63
|
+
#: () -> bool
|
|
64
|
+
def leaves_items_out? = @items.length > MOST_ITEMS
|
|
54
65
|
end
|
|
55
66
|
end
|
|
56
67
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require "shellwords"
|
|
4
5
|
require_relative "../error"
|
|
5
6
|
require_relative "../prose_list"
|
|
6
7
|
|
|
@@ -24,10 +25,12 @@ module Principles
|
|
|
24
25
|
freeze
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
# The part, refused unless the request, or its template, has it or leaves it out as empty
|
|
28
|
+
# The part, refused unless the request, or its template, has it or leaves it out as empty: named as it is, or as
|
|
29
|
+
# the index prints it, one shell word quoted where a shell would split it, for a name passed outside a shell.
|
|
28
30
|
#: () -> String
|
|
29
31
|
def part
|
|
30
|
-
|
|
32
|
+
named = [@part, *as_shell_word].find { @printed.include?(it) || @empty.include?(it) }
|
|
33
|
+
return named if named
|
|
31
34
|
|
|
32
35
|
whole = @template ? "template" : "request"
|
|
33
36
|
refusal = Error.new("unknown_part",
|
|
@@ -36,6 +39,17 @@ module Principles
|
|
|
36
39
|
raise refusal.ending_with([Error::RepairCommand.new(purpose: "To print one part", command: "start-audit",
|
|
37
40
|
values: [@id], usage:)])
|
|
38
41
|
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
# The part as a shell reads it, when it reads as one word; none when it does not, or holds an unbalanced quote.
|
|
46
|
+
#: () -> Array[String]
|
|
47
|
+
def as_shell_word
|
|
48
|
+
words = Shellwords.split(@part)
|
|
49
|
+
words.size == 1 ? words : []
|
|
50
|
+
rescue ArgumentError
|
|
51
|
+
[]
|
|
52
|
+
end
|
|
39
53
|
end
|
|
40
54
|
end
|
|
41
55
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
# The file a plugin member names, by its path inside the plugin. It takes plain characters only, segments of
|
|
10
|
+
# letters, digits, dots, dashes and underscores, none of them . or .., so it can only name a file under the
|
|
11
|
+
# plugin's own folder and reads the same wherever it is printed. No first case needs any other character.
|
|
12
|
+
class PluginComponent
|
|
13
|
+
# One segment of the path: plain characters, and not . or .. alone.
|
|
14
|
+
SEGMENT = /\A(?!\.{1,2}\z)[A-Za-z0-9._-]+\z/ #: Regexp
|
|
15
|
+
|
|
16
|
+
# Whether path is plain, as a component must be.
|
|
17
|
+
#: (String) -> bool
|
|
18
|
+
def self.plain?(path) = !path.empty? && path.split("/", -1).all? { |segment| segment.match?(SEGMENT) }
|
|
19
|
+
|
|
20
|
+
#: String
|
|
21
|
+
attr_reader :path
|
|
22
|
+
|
|
23
|
+
#: (String) -> void
|
|
24
|
+
def initialize(path)
|
|
25
|
+
unless self.class.plain?(path)
|
|
26
|
+
raise Error.new("plugin_component_not_plain",
|
|
27
|
+
"#{path.inspect} is not a plain relative path inside the plugin",
|
|
28
|
+
"Name the file by its path inside the plugin, in segments of letters, digits, dots, " \
|
|
29
|
+
"dashes and underscores, with no . or .. segment.")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
@path = path
|
|
33
|
+
freeze
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|