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
|
@@ -11,7 +11,8 @@ module Principles
|
|
|
11
11
|
# to the full audit, but a member whose text is the one last judged needs nothing at all.
|
|
12
12
|
class AcknowledgementRefusal
|
|
13
13
|
# Why a one-member audit cannot judge member's change against record, or nil when it can: the record must
|
|
14
|
-
# be completed and have assessed the member, the member's text must differ from the one it assessed,
|
|
14
|
+
# be completed and have assessed the member, the member's text must differ from the one it assessed, it must
|
|
15
|
+
# be the project's, since a one-member audit reads its change from git, which holds no plugin's file, its check
|
|
15
16
|
# must be the one the record ran, so none new, changed, removed or last not run escapes a full audit's review.
|
|
16
17
|
# The one owner of these preconditions, which
|
|
17
18
|
# list-member-problems asks before offering the audit that Acknowledgement refuses by them; git is
|
|
@@ -19,21 +20,28 @@ module Principles
|
|
|
19
20
|
#: (AuditRecord, Member, now_sha256: String?) -> AcknowledgementRefusal?
|
|
20
21
|
def self.of(record, member, now_sha256:)
|
|
21
22
|
members = record.members
|
|
22
|
-
recorded = members.hash_for(member.key)
|
|
23
23
|
check = members.check_since(member.key, member.check)
|
|
24
|
-
reason =
|
|
25
|
-
|
|
26
|
-
elsif !recorded then :not_assessed
|
|
27
|
-
elsif recorded == now_sha256 then :unchanged
|
|
28
|
-
elsif check != :unchanged then check
|
|
29
|
-
end
|
|
24
|
+
reason = baseline_missing(record, members.hash_for(member.key), now_sha256) ||
|
|
25
|
+
(:plugin if member.plugin_reference) || (check unless check == :unchanged)
|
|
30
26
|
new(member, record.principle_id, reason, ran: members.check_run_for(member.key)) if reason
|
|
31
27
|
end
|
|
32
28
|
|
|
29
|
+
# Why record gives no baseline to judge a change against, the member's hash it assessed being recorded and
|
|
30
|
+
# its hash now now_sha256: open, not completed, the member not assessed, or unchanged; nil when it gives one.
|
|
31
|
+
#: (AuditRecord, String?, String?) -> Symbol?
|
|
32
|
+
def self.baseline_missing(record, recorded, now_sha256)
|
|
33
|
+
if record.open_after_a_completed_audit? then :open
|
|
34
|
+
elsif !record.completed? then :not_completed
|
|
35
|
+
elsif !recorded then :not_assessed
|
|
36
|
+
elsif recorded == now_sha256 then :unchanged
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
private_class_method :baseline_missing
|
|
40
|
+
|
|
33
41
|
# principle_id is the member's principle, whose full audit each refusal names. reason, which raise! raises, is
|
|
34
|
-
# :open, :not_completed, :not_assessed, :unchanged, or how the member's check stands to the one the
|
|
35
|
-
# ran, as RecordedMembers#check_since says; ran is the command that record ran, if any. Without a reason
|
|
36
|
-
# only refuses for a reason its caller states.
|
|
42
|
+
# :open, :not_completed, :not_assessed, :unchanged, :plugin, or how the member's check stands to the one the
|
|
43
|
+
# record ran, as RecordedMembers#check_since says; ran is the command that record ran, if any. Without a reason
|
|
44
|
+
# it only refuses for a reason its caller states.
|
|
37
45
|
#: (Member, String, ?Symbol?, ?ran: String?) -> void
|
|
38
46
|
def initialize(member, principle_id, reason = nil, ran: nil)
|
|
39
47
|
@reason = reason
|
|
@@ -58,6 +66,7 @@ module Principles
|
|
|
58
66
|
when :open then open_audit
|
|
59
67
|
when :not_completed then refuse("#{@principle_id} has no completed audit, so no baseline has been judged")
|
|
60
68
|
when :not_assessed then refuse("no completed audit assessed #{@member.id}")
|
|
69
|
+
when :plugin then refuse("it is read from an installed plugin, whose changes git holds no history of")
|
|
61
70
|
else refuse("#{check_since_record}, so a full audit reviews it")
|
|
62
71
|
end
|
|
63
72
|
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "list_member_problems_check"
|
|
5
|
+
require_relative "member_problems"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The one-member audits list-member-problems offers across maps: the changed members each may judge, joined
|
|
11
|
+
# where principles share one, leaving out the principles whose records wait on an upgrade.
|
|
12
|
+
class AcknowledgementsToOffer
|
|
13
|
+
# maps is each map's MemberProblems; except, the principles whose records wait on an upgrade.
|
|
14
|
+
#: (Array[MemberProblems], except: Array[String]) -> void
|
|
15
|
+
def initialize(maps, except:)
|
|
16
|
+
@maps = maps
|
|
17
|
+
@except = except
|
|
18
|
+
freeze
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Each set of principle ids, in id order, with the members they acknowledge together, those of principles that
|
|
22
|
+
# share one joined in one acknowledgement across them. Each set holding a member last names comes after the
|
|
23
|
+
# others.
|
|
24
|
+
#: () -> Hash[Array[String], Array[String]]
|
|
25
|
+
def together = offered.partition { |_ids, members| !members.intersect?(last) }.flatten(1).to_h
|
|
26
|
+
|
|
27
|
+
# The acknowledgeable members whose check is this tool's own list-member-problems --short, which refuses their
|
|
28
|
+
# acknowledgement while it lists a member the answer leaves out, so they are acknowledged after the others;
|
|
29
|
+
# none whose set holds every member --short lists, since nothing else is to come first.
|
|
30
|
+
#: () -> Array[String]
|
|
31
|
+
def last
|
|
32
|
+
sets = offered.values
|
|
33
|
+
self_checked.select { |id| sets.find { it.include?(id) }&.then { listed_beside?(it) } }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
# The sets to offer: those grouped, with every set holding a member --short checks joined into one across their
|
|
39
|
+
# principles, since apart each such member's check lists the other's and none could pass.
|
|
40
|
+
#: () -> Hash[Array[String], Array[String]]
|
|
41
|
+
def offered
|
|
42
|
+
checking, others = grouped.partition { |_ids, members| members.intersect?(self_checked) }
|
|
43
|
+
return grouped if checking.length < 2
|
|
44
|
+
|
|
45
|
+
others.to_h.merge(checking.flat_map(&:first).uniq.sort => checking.flat_map(&:last).uniq)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The members, of every map, whose check is this tool's own list-member-problems --short.
|
|
49
|
+
#: () -> Array[String]
|
|
50
|
+
def self_checked
|
|
51
|
+
@maps.flat_map { |map| map.members.select { ListMemberProblemsCheck.of(it.check.to_s) }.map(&:id) }.uniq
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Each set of principle ids with the members they acknowledge together, in no set order.
|
|
55
|
+
#: () -> Hash[Array[String], Array[String]]
|
|
56
|
+
def grouped
|
|
57
|
+
acknowledgeable.reduce({}) do |joined, (id, members)|
|
|
58
|
+
@except.include?(id) ? joined : joining(joined, id, members)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Whether --short lists a member set leaves out: one changed, or one no audit has assessed, in a map whose
|
|
63
|
+
# record waits on no upgrade.
|
|
64
|
+
#: (Array[String]) -> bool
|
|
65
|
+
def listed_beside?(set)
|
|
66
|
+
acting = @maps.reject { @except.include?(it.principle_id) }
|
|
67
|
+
acting.any? { it.never_assessed.positive? } ||
|
|
68
|
+
acting.flat_map(&:entries).any? { it.fetch("state") == "changed" && !set.include?(it.fetch("id")) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# For each map with a changed member a one-member audit may judge, the ids of those members.
|
|
72
|
+
#: () -> Hash[String, Array[String]]
|
|
73
|
+
def acknowledgeable
|
|
74
|
+
@maps.to_h { |map| [map.principle_id, map.acknowledgeable_member_ids] }.reject { |_, ids| ids.empty? }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# groups with principle id's members joined into each group that shares one of them, as one group.
|
|
78
|
+
#: (Hash[Array[String], Array[String]], String, Array[String]) -> Hash[Array[String], Array[String]]
|
|
79
|
+
def joining(groups, id, members)
|
|
80
|
+
joined = groups.select { |_ids, others| others.intersect?(members) }
|
|
81
|
+
rest = groups.reject { |ids, _others| joined.key?(ids) }
|
|
82
|
+
rest.merge([*joined.keys.flatten, id].sort => [*joined.values.flatten, *members].uniq)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -31,6 +31,10 @@ module Principles
|
|
|
31
31
|
#: Integer
|
|
32
32
|
attr_reader :started
|
|
33
33
|
|
|
34
|
+
# The session's directory, whose project and its worktrees are the only repositories reported on.
|
|
35
|
+
#: String
|
|
36
|
+
attr_reader :session_directory
|
|
37
|
+
|
|
34
38
|
# The hook's input as the process it runs in reads it, the one owner of that reading for the executable, before
|
|
35
39
|
# the rest of this tool loads, and for the command: started at clock, unless environment's PRINCIPLES_HOOK_NOW,
|
|
36
40
|
# a test seam no session sets, gives the second; with home as ~; and for input naming no cwd, the session's
|
|
@@ -48,6 +52,7 @@ module Principles
|
|
|
48
52
|
given = parsed(text)
|
|
49
53
|
@event = EVENTS.find { it == given["hook_event_name"] } #: String?
|
|
50
54
|
@started = started_before(now, given["duration_ms"]) #: Integer
|
|
55
|
+
@session_directory = fallback
|
|
51
56
|
@cwd = text(given["cwd"]) || fallback #: String
|
|
52
57
|
tool_input = given["tool_input"]
|
|
53
58
|
@command = (text(tool_input["command"]) if tool_input.is_a?(Hash)) || "" #: String
|
|
@@ -18,6 +18,9 @@ module Principles
|
|
|
18
18
|
LINK_REPAIR = "Give recorded_at as {\"url\": \"https://...\"}, the whole link to where it is written up, " \
|
|
19
19
|
"such as an issue, with no other field; or as {\"path\": ..., \"heading\": ...} for a file in " \
|
|
20
20
|
"the project."
|
|
21
|
+
# The two forms a recorded_at takes, which a repair asking for one names.
|
|
22
|
+
WRITE_UP_FORMS = "{\"path\": ..., \"heading\": ...} for a file in the project, or {\"url\": \"https://...\"} " \
|
|
23
|
+
"for a page outside it, such as an issue"
|
|
21
24
|
|
|
22
25
|
#: (^(Locator) -> void) -> void
|
|
23
26
|
def initialize(locate)
|
|
@@ -17,12 +17,19 @@ module Principles
|
|
|
17
17
|
new("base_commit" => base, "last_completed_revision" => record&.last_completed&.revision)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
# audited_change is the commit that last changed the map's file or a member's file at the base, which the id
|
|
21
|
+
# digests in place of the base, so a commit elsewhere leaves the id as it was; the base until given.
|
|
22
|
+
#: (Hash[String, untyped], ?String?) -> void
|
|
23
|
+
def initialize(fields, audited_change = fields["base_commit"])
|
|
22
24
|
@fields = fields
|
|
25
|
+
@audited_change = audited_change
|
|
23
26
|
freeze
|
|
24
27
|
end
|
|
25
28
|
|
|
29
|
+
# This basis, its id digesting commit, the last change to the files the audit reads at its base, nil outside git.
|
|
30
|
+
#: (String?) -> AssessmentBasis
|
|
31
|
+
def audited_at(commit) = AssessmentBasis.new(@fields, commit)
|
|
32
|
+
|
|
26
33
|
#: () -> Hash[String, untyped]
|
|
27
34
|
def to_h = @fields
|
|
28
35
|
|
|
@@ -41,7 +48,7 @@ module Principles
|
|
|
41
48
|
|
|
42
49
|
# What the request id digests of the basis, in a fixed order, so how the answer orders its keys changes nothing.
|
|
43
50
|
#: () -> Array[String?]
|
|
44
|
-
def digested = [
|
|
51
|
+
def digested = [@audited_change, revision]
|
|
45
52
|
end
|
|
46
53
|
end
|
|
47
54
|
end
|
|
@@ -16,6 +16,7 @@ require_relative "carried_assessments"
|
|
|
16
16
|
require_relative "prior_findings"
|
|
17
17
|
require_relative "decided_prior_findings"
|
|
18
18
|
require_relative "disposition"
|
|
19
|
+
require_relative "finding_outcomes"
|
|
19
20
|
require_relative "stale_request"
|
|
20
21
|
require_relative "map_change"
|
|
21
22
|
|
|
@@ -69,7 +70,7 @@ module Principles
|
|
|
69
70
|
def check_assessment_request(request_id, basis:, committed:, record:, loads:, &started_from)
|
|
70
71
|
prior = prior_findings(record)
|
|
71
72
|
now_id = assessment_id(basis, prior.digested, loads.listed)
|
|
72
|
-
return prior if now_id == request_id && (basis.base.nil? || committed ==
|
|
73
|
+
return prior if now_id == request_id && (basis.base.nil? || committed == in_project_now)
|
|
73
74
|
|
|
74
75
|
raise StaleRequest.new(id, changed_since(committed), correction_open: record&.open? || false,
|
|
75
76
|
map_change: map_change(request_id, basis, record, loads,
|
|
@@ -149,16 +150,10 @@ module Principles
|
|
|
149
150
|
before
|
|
150
151
|
end
|
|
151
152
|
|
|
152
|
-
#
|
|
153
|
-
# what a deferral says it waits on, if anything.
|
|
154
|
-
# Then each prior finding kept; a new finding that raises one again keeps when it was first raised.
|
|
153
|
+
# The findings the completed audit records, as FindingOutcomes gives them.
|
|
155
154
|
#: (Array[untyped], Array[Disposition], ?DecidedPriorFindings) -> Array[untyped]
|
|
156
155
|
def outcomes(findings, dispositions, prior = DecidedPriorFindings::NONE)
|
|
157
|
-
findings
|
|
158
|
-
id = finding.fetch("id")
|
|
159
|
-
disposition = dispositions.find { |each| each.finding_id == id } or raise KeyError, id
|
|
160
|
-
finding.slice(*RecordedFinding::RAISED_FIELDS).merge(disposition.recorded_outcome, prior.first_raised(id))
|
|
161
|
-
end + prior.kept
|
|
156
|
+
FindingOutcomes.new(findings, dispositions, prior).recorded
|
|
162
157
|
end
|
|
163
158
|
|
|
164
159
|
# What each member's assessment is judged on beside its text, from each member's loads: its map entry and when
|
|
@@ -217,7 +212,12 @@ module Principles
|
|
|
217
212
|
# The ids of the members whose hash now differs from the one committed, the base commit's, gives; none
|
|
218
213
|
# outside git.
|
|
219
214
|
#: (Hash[String, String]?) -> Array[String]
|
|
220
|
-
def changed_since(committed) = committed ?
|
|
215
|
+
def changed_since(committed) = committed ? in_project_now.reject { |id, sha| committed[id] == sha }.keys : []
|
|
216
|
+
|
|
217
|
+
# Each hash now of a member in the project's own files, which a commit can hold, by id; a plugin's member,
|
|
218
|
+
# outside git, is compared only through the request id.
|
|
219
|
+
#: () -> Hash[String, String]
|
|
220
|
+
def in_project_now = members.in_project.ids.to_h { [it, @now.fetch(it)] }
|
|
221
221
|
|
|
222
222
|
#: () -> Error
|
|
223
223
|
def stale_request = StaleRequest.new(id).refusal
|
|
@@ -175,6 +175,11 @@ module Principles
|
|
|
175
175
|
kept ? AuditRecord.new(kept) : nil
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
+
# Whether it holds a completed audit other than written, a record just completed, so written is not the first
|
|
179
|
+
# to complete; a retry of written reads written back, so it is the first still.
|
|
180
|
+
#: (AuditRecord) -> bool
|
|
181
|
+
def completed_other_than?(written) = last_completed&.then { !it.same_as?(written) } || false
|
|
182
|
+
|
|
178
183
|
# This record with the member known by key moved to change's to_sha256, and change kept beside it.
|
|
179
184
|
# Nothing else changes: the map version, base commit and findings stay the audit's own.
|
|
180
185
|
# check_result is the result reported for the member's check, which replaces the one the record kept.
|
|
@@ -204,6 +209,11 @@ module Principles
|
|
|
204
209
|
#: () -> Array[String]
|
|
205
210
|
def open_ids = left_open.map(&:id)
|
|
206
211
|
|
|
212
|
+
# The ids of the findings it leaves open whose action is action, deferred or accepted, which a completed
|
|
213
|
+
# audit's result names apart.
|
|
214
|
+
#: (String) -> Array[String]
|
|
215
|
+
def left_open_ids(action) = left_open.select { it.action == action }.map(&:id)
|
|
216
|
+
|
|
207
217
|
# The ids of the findings it leaves open on the member known by key, which the next full audit decides beside
|
|
208
218
|
# it.
|
|
209
219
|
#: (String) -> Array[String]
|
|
@@ -155,9 +155,10 @@ module Principles
|
|
|
155
155
|
[file(record.principle_id), *record.cited_files(@history).committed_with(changed, reported)]
|
|
156
156
|
end
|
|
157
157
|
|
|
158
|
-
# Each file record cites that no longer exists, which files_to_commit leaves out
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
# Each file record cites that no longer exists, which files_to_commit leaves out, a plugin's file asked of
|
|
159
|
+
# plugins.
|
|
160
|
+
#: (AuditRecord, InstalledPlugins) -> Array[String]
|
|
161
|
+
def cited_files_missing(record, plugins) = record.cited_files(@history).missing(plugins)
|
|
161
162
|
|
|
162
163
|
# Writes record's file and names it, relative to the project.
|
|
163
164
|
#: (AuditRecord) -> String
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
require_relative "assessment_report"
|
|
5
5
|
require_relative "json_digest"
|
|
6
6
|
require_relative "principle"
|
|
7
|
+
require_relative "stale_request"
|
|
7
8
|
|
|
8
9
|
module Principles
|
|
9
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -86,6 +87,14 @@ module Principles
|
|
|
86
87
|
#: (now: Hash[String, String]) -> Array[String]
|
|
87
88
|
def added(now:) = now.keys.reject { |id| began_with?(id) }
|
|
88
89
|
|
|
90
|
+
# Refuses an answer to this audit as stale once the text of a plugin member in now differs from the text the
|
|
91
|
+
# audit began with: an update to the installed plugin, which no fix can claim.
|
|
92
|
+
#: (now: Hash[String, String]) -> void
|
|
93
|
+
def check_plugin_members_unchanged(now:)
|
|
94
|
+
updated = changed(now:).select { @map.members.with_id(it)&.plugin_reference }
|
|
95
|
+
raise StaleRequest.plugin_updated(id, updated) if updated.any?
|
|
96
|
+
end
|
|
97
|
+
|
|
89
98
|
# The members whose hash in now differs from their hash when the audit began.
|
|
90
99
|
#: (now: Hash[String, String]) -> Array[String]
|
|
91
100
|
def changed(now:)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "locator"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# A new member's locator as its map stores it: its passage's opening without the indent it was quoted with, when
|
|
11
|
+
# that still names one place, so its id does not keep the spaces of a YAML key or a nested list item. The given
|
|
12
|
+
# opening contains the unindented one, so a lone occurrence of the unindented one is at the same place. A member
|
|
13
|
+
# already mapped keeps its locator, since its id is that locator and audit records file it under that id.
|
|
14
|
+
class AuthoredLocator
|
|
15
|
+
#: (Project, Locator) -> void
|
|
16
|
+
def initialize(project, locator)
|
|
17
|
+
@project = project
|
|
18
|
+
@locator = locator
|
|
19
|
+
freeze
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# The locator to store: the unindented one where it locates, else the one given.
|
|
23
|
+
#: () -> Locator
|
|
24
|
+
def stored
|
|
25
|
+
unindented = @locator.with_opening_unindented or return @locator
|
|
26
|
+
@project.locate_for_authoring(unindented)
|
|
27
|
+
unindented
|
|
28
|
+
rescue Error
|
|
29
|
+
@locator
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -50,9 +50,8 @@ module Principles
|
|
|
50
50
|
# name, which the budget cuts by.
|
|
51
51
|
#: (Array[Hash[String, untyped]]) -> Hash[String, CandidateOutline]
|
|
52
52
|
def outlines(test_data_hints)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(paths - test_data).to_h { |path| [path, CandidateOutline.new(@text_of.call(path))] }
|
|
53
|
+
outlined_paths(test_data_hints).to_h { |path| [path, outline_of(path)] }
|
|
54
|
+
.select { |path, outline| path.match?(MARKDOWN) || outline.sections.any? }
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
# Each Markdown or settings file, with its size, and a skill's entry file spelt otherwise than SKILL.md with its
|
|
@@ -76,6 +75,27 @@ module Principles
|
|
|
76
75
|
|
|
77
76
|
private
|
|
78
77
|
|
|
78
|
+
# The listed files the survey outlines: every one but those the test-data hints name.
|
|
79
|
+
#: (Array[Hash[String, untyped]]) -> Array[String]
|
|
80
|
+
def outlined_paths(test_data_hints)
|
|
81
|
+
test_data = hints(test_data_hints).map { |hint| hint.fetch("path") }
|
|
82
|
+
listed.map { |file| file.fetch("path") } - test_data
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# The outline of one listed file, from its text: a Markdown file's by its headings and items, any other's by its
|
|
86
|
+
# comments.
|
|
87
|
+
#: (String) -> CandidateOutline
|
|
88
|
+
def outline_of(path) = CandidateOutline.new(@text_of.call(path), as: reader_for(path))
|
|
89
|
+
|
|
90
|
+
# What reads a file's outline: Markdown by its headings and items, a CI workflow by its jobs and steps, and any
|
|
91
|
+
# other text by its comments.
|
|
92
|
+
#: (String) -> (singleton(MarkdownText) | singleton(ScriptComments) | singleton(WorkflowJobs))
|
|
93
|
+
def reader_for(path)
|
|
94
|
+
return MarkdownText if path.match?(MARKDOWN)
|
|
95
|
+
|
|
96
|
+
path.match?(WorkflowJobs::PATH) ? WorkflowJobs : ScriptComments
|
|
97
|
+
end
|
|
98
|
+
|
|
79
99
|
# files with those changed names first, each marked changed_in_range, and the rest after, each in its order.
|
|
80
100
|
#: (Array[Hash[String, untyped]], Array[String]) -> Array[Hash[String, untyped]]
|
|
81
101
|
def changed_first(files, changed)
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require_relative "
|
|
5
|
-
require_relative "frontmatter_fields"
|
|
4
|
+
require_relative "markdown_text"
|
|
6
5
|
require_relative "outline_group"
|
|
7
|
-
require_relative "
|
|
8
|
-
require_relative "
|
|
6
|
+
require_relative "script_comments"
|
|
7
|
+
require_relative "workflow_jobs"
|
|
9
8
|
|
|
10
9
|
module Principles
|
|
11
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
12
11
|
module Models
|
|
13
|
-
# One candidate file's outline, as the survey reads it in place of the file:
|
|
14
|
-
#
|
|
15
|
-
# and missed a principles section written as one numbered list, so this tool prints both.
|
|
12
|
+
# One candidate file's outline, as the survey reads it in place of the file: the sections of the text it outlines,
|
|
13
|
+
# and that text's description and opening line when it has them, cut to fit a budget.
|
|
16
14
|
class CandidateOutline
|
|
17
|
-
HEADING = /\A#+\s/
|
|
18
|
-
FENCE = /\A\s*(?:```|~~~)/
|
|
19
|
-
# A top-level list item, its marker and its text; an indented one is nested, and left out.
|
|
20
|
-
ITEM = /\A(\d+\.|[-*])\s+(.*)/
|
|
21
|
-
# A horizontal rule, such as `* * *` or `- - -`, which is no item.
|
|
22
|
-
RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
|
|
23
|
-
LINK = /\[([^\]]*)\]\([^)]*\)/
|
|
24
|
-
BOLD_LEAD = /\A\*\*[^*]+\*\*/
|
|
25
|
-
# The most characters of an item printed, cut back to a whole word.
|
|
26
|
-
ITEM_CHARACTERS = 60
|
|
27
|
-
# The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
|
|
28
|
-
# mid-clause left 30 of one user's 45 opening lines a fragment. The line is short only when
|
|
29
|
-
# its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
|
|
30
|
-
# accepted, since the file's path and outline still say what it holds.
|
|
31
|
-
OPENING_CHARACTERS = 160
|
|
32
15
|
# The cuts that shorten an outline to fit a budget, in the order they are made, each keeping those before it.
|
|
33
16
|
# The last leaves the whole outline out, which a big enough project needs once every other cut is made.
|
|
34
17
|
CUTS = %w[description items headings opening_line outline].freeze
|
|
@@ -36,19 +19,11 @@ module Principles
|
|
|
36
19
|
ENTRY_FILE_CUTS = CUTS.length - 1 #: Integer
|
|
37
20
|
# The deepest heading level a cut outline keeps once its headings are folded.
|
|
38
21
|
FOLDED_BELOW = 2
|
|
39
|
-
# The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
|
|
40
|
-
# one user's descriptions printed 12,537 B uncut, and suggested about 300.
|
|
41
|
-
DESCRIPTION_CHARACTERS = 300
|
|
42
22
|
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#: (String) -> void
|
|
49
|
-
def initialize(text)
|
|
50
|
-
@lines = text.lines #: Array[String]
|
|
51
|
-
@frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
|
|
23
|
+
# The file's text, read as the kind of text `as` names.
|
|
24
|
+
#: (String, ?as: singleton(MarkdownText) | singleton(ScriptComments) | singleton(WorkflowJobs)) -> void
|
|
25
|
+
def initialize(text, as: MarkdownText)
|
|
26
|
+
@text = as.new(text) #: MarkdownText | ScriptComments | WorkflowJobs
|
|
52
27
|
freeze
|
|
53
28
|
end
|
|
54
29
|
|
|
@@ -58,14 +33,16 @@ module Principles
|
|
|
58
33
|
def to_h(cuts: 0)
|
|
59
34
|
return {} if left_out?(cuts)
|
|
60
35
|
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
description = @text.description
|
|
37
|
+
{ "description" => made?("description", cuts) ? @text.cut_description : description,
|
|
38
|
+
"opening_line" => (@text.opening_line unless made?("opening_line", cuts) && description),
|
|
63
39
|
"outline" => outline_lines(cuts) }.compact
|
|
64
40
|
end
|
|
65
41
|
|
|
66
|
-
# Whether the first `cuts` of CUTS
|
|
42
|
+
# Whether the outline's lines are cut once the first `cuts` of CUTS are made: by those cuts, rather than only its
|
|
43
|
+
# description, or by a section leaving items out past OutlineSection::MOST_ITEMS before any cut.
|
|
67
44
|
#: (Integer) -> bool
|
|
68
|
-
def outline_cut?(cuts) = made?("items", cuts)
|
|
45
|
+
def outline_cut?(cuts) = made?("items", cuts) || sections.any?(&:leaves_items_out?)
|
|
69
46
|
|
|
70
47
|
# Whether the first `cuts` of CUTS leave the whole outline out, the file printing its path and size alone.
|
|
71
48
|
#: (Integer) -> bool
|
|
@@ -79,16 +56,9 @@ module Principles
|
|
|
79
56
|
#: () -> Array[String]
|
|
80
57
|
def cut_lines = sections.flat_map(&:cut_lines)
|
|
81
58
|
|
|
82
|
-
#
|
|
83
|
-
# the lines of the file it spans.
|
|
59
|
+
# The text's sections, each a heading with the items under it and the lines of the file it spans.
|
|
84
60
|
#: () -> Array[OutlineSection]
|
|
85
|
-
def sections
|
|
86
|
-
body = unfenced
|
|
87
|
-
starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
|
|
88
|
-
starts.zip(starts.drop(1)).filter_map do |first, after|
|
|
89
|
-
section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
61
|
+
def sections = @text.sections
|
|
92
62
|
|
|
93
63
|
private
|
|
94
64
|
|
|
@@ -96,7 +66,7 @@ module Principles
|
|
|
96
66
|
# headings folded into the heading above, whose 11,112 B kept one user's result over budget.
|
|
97
67
|
#: (Integer) -> Array[String]
|
|
98
68
|
def outline_lines(cuts)
|
|
99
|
-
return lines unless
|
|
69
|
+
return lines unless made?("items", cuts)
|
|
100
70
|
return cut_lines unless made?("headings", cuts)
|
|
101
71
|
|
|
102
72
|
groups.flat_map(&:folded_lines)
|
|
@@ -113,83 +83,6 @@ module Principles
|
|
|
113
83
|
# Whether the first `cuts` of CUTS include the one named.
|
|
114
84
|
#: (String, Integer) -> bool
|
|
115
85
|
def made?(cut, cuts) = CUTS.take(cuts).include?(cut)
|
|
116
|
-
|
|
117
|
-
# The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
|
|
118
|
-
# heading nor an item.
|
|
119
|
-
#: (Array[String], first_line: Integer) -> OutlineSection?
|
|
120
|
-
def section(lines, first_line:)
|
|
121
|
-
heading = lines.first if lines.first&.match?(HEADING)
|
|
122
|
-
items = lines.select { |line| item?(line) }.map { |line| item(line) }
|
|
123
|
-
return nil unless heading || items.any?
|
|
124
|
-
|
|
125
|
-
OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# A top-level list item, not a horizontal rule written with the same marks.
|
|
129
|
-
#: (String) -> bool
|
|
130
|
-
def item?(line) = line.match?(ITEM) && !line.match?(RULE)
|
|
131
|
-
|
|
132
|
-
# The index in the file of the body's first line, after any frontmatter.
|
|
133
|
-
#: () -> Integer
|
|
134
|
-
def body_start = (@frontmatter.closing_line || -1) + 1
|
|
135
|
-
|
|
136
|
-
# The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
|
|
137
|
-
#: () -> String?
|
|
138
|
-
def description
|
|
139
|
-
written = @frontmatter.field_lines("$.description") or return nil
|
|
140
|
-
text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
|
|
141
|
-
text[QUOTED, 2] || text
|
|
142
|
-
rescue Error
|
|
143
|
-
nil
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
# The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
|
|
147
|
-
# characters it holds and the lines of the file that hold it, so the agent reads just those back.
|
|
148
|
-
#: () -> String?
|
|
149
|
-
def cut_description
|
|
150
|
-
text = description or return nil
|
|
151
|
-
within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
|
|
152
|
-
return text unless within.cut?
|
|
153
|
-
|
|
154
|
-
kept = within.kept
|
|
155
|
-
first, last = @frontmatter.field("$.description")
|
|
156
|
-
"#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
|
|
160
|
-
# joined, with links as their text. The first physical line was a fragment in a hard-wrapped file.
|
|
161
|
-
#: () -> String?
|
|
162
|
-
def opening_line
|
|
163
|
-
body = unfenced
|
|
164
|
-
first = body.index { |line| prose?(line) } or return nil
|
|
165
|
-
paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
|
|
166
|
-
TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
#: (String) -> bool
|
|
170
|
-
def prose?(line)
|
|
171
|
-
text = line.strip
|
|
172
|
-
!text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
|
|
176
|
-
#: () -> Array[String]
|
|
177
|
-
def unfenced
|
|
178
|
-
fenced = false #: bool
|
|
179
|
-
body = @lines.drop(body_start).map(&:chomp)
|
|
180
|
-
body.map do |line|
|
|
181
|
-
fenced = !fenced if line.match?(FENCE)
|
|
182
|
-
fenced || line.match?(FENCE) ? "" : line
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
# An item by its marker and its bold lead, or its opening words, with links as their text.
|
|
187
|
-
#: (String) -> String
|
|
188
|
-
def item(line)
|
|
189
|
-
marker, text = line.match(ITEM)&.captures
|
|
190
|
-
text = text.to_s.gsub(LINK, '\1')
|
|
191
|
-
"#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: ITEM_CHARACTERS).by_words}"
|
|
192
|
-
end
|
|
193
86
|
end
|
|
194
87
|
end
|
|
195
88
|
end
|