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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/request_logging_folder"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# What the host captured under requests/, read from its files and its index: each session's requests, files and
|
|
10
|
+
# bytes, and the request files no index line names, whose cause is the agent's to judge.
|
|
11
|
+
class CapturedSessions
|
|
12
|
+
# Files counted, and their bytes.
|
|
13
|
+
class Tally
|
|
14
|
+
#: Integer
|
|
15
|
+
attr_reader :files, :bytes
|
|
16
|
+
|
|
17
|
+
#: (files: Integer, bytes: Integer) -> void
|
|
18
|
+
def initialize(files:, bytes:)
|
|
19
|
+
@files = files
|
|
20
|
+
@bytes = bytes
|
|
21
|
+
freeze
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#: () -> Hash[String, Integer]
|
|
25
|
+
def to_h = { "files" => @files, "bytes" => @bytes }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# One session's tally: its requests, the files they and their responses fill, and those files' bytes.
|
|
29
|
+
class Session
|
|
30
|
+
#: String
|
|
31
|
+
attr_reader :session_id
|
|
32
|
+
#: Integer
|
|
33
|
+
attr_reader :requests
|
|
34
|
+
#: Tally
|
|
35
|
+
attr_reader :tally
|
|
36
|
+
|
|
37
|
+
#: (String, Integer, Tally) -> void
|
|
38
|
+
def initialize(session_id, requests, tally)
|
|
39
|
+
@session_id = session_id
|
|
40
|
+
@requests = requests
|
|
41
|
+
@tally = tally
|
|
42
|
+
freeze
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#: () -> Hash[String, untyped]
|
|
46
|
+
def to_h = { "session_id" => @session_id, "requests" => @requests, **@tally.to_h }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
#: (Array[Data::RequestLoggingFolder::CapturedFile], Array[Data::RequestLoggingFolder::IndexLine]) -> void
|
|
50
|
+
def initialize(files, index_lines)
|
|
51
|
+
@files = files.to_h { |file| [file.name, file] } #: Hash[String, Data::RequestLoggingFolder::CapturedFile]
|
|
52
|
+
@index_lines = index_lines
|
|
53
|
+
freeze
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Each session the index names, in the order it first names them.
|
|
57
|
+
#: () -> Array[Session]
|
|
58
|
+
def sessions
|
|
59
|
+
@index_lines.group_by(&:session_id).map do |session_id, lines|
|
|
60
|
+
named = lines.flat_map { |line| named_files(line) }.uniq
|
|
61
|
+
Session.new(session_id, lines.size, Tally.new(files: named.size, bytes: named.sum(&:bytes)))
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# The request files no index line names, counted, and their bytes.
|
|
66
|
+
#: () -> Tally
|
|
67
|
+
def orphans
|
|
68
|
+
unnamed = unnamed_requests
|
|
69
|
+
Tally.new(files: unnamed.size, bytes: unnamed.sum(&:bytes))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# When the newest request file was written, which says whether requests still arrive, or nil before any.
|
|
73
|
+
#: () -> Time?
|
|
74
|
+
def newest_request_written_at
|
|
75
|
+
@files.values.select { |file| file.name.end_with?(".request.json") }.map(&:modified_at).max
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Whether the host captured no request yet, as before a session is launched with capture on.
|
|
79
|
+
#: () -> bool
|
|
80
|
+
def none? = newest_request_written_at.nil?
|
|
81
|
+
|
|
82
|
+
# The session of the index's newest line, by its timestamp, or nil before the index has one. It compares the
|
|
83
|
+
# timestamps as text, which orders them only while the host writes them in one ISO 8601 form, not yet seen on a
|
|
84
|
+
# real launch.
|
|
85
|
+
#: () -> String?
|
|
86
|
+
def newest_session_id = @index_lines.max_by(&:timestamp)&.session_id
|
|
87
|
+
|
|
88
|
+
# The names of the files the index names for every session but the newest keep, ranked by each session's
|
|
89
|
+
# newest line, as newest_session_id compares them, leaving every file a kept session also names; then the
|
|
90
|
+
# request files no line names that were written before every kept session's file. With no session kept, every
|
|
91
|
+
# such file stays, since it may belong to a session still running.
|
|
92
|
+
#: (Integer) -> Array[String]
|
|
93
|
+
def older_than_newest(keep)
|
|
94
|
+
ranked = @index_lines.group_by(&:session_id).values.sort_by { |lines| lines.map(&:timestamp).max.to_s }
|
|
95
|
+
kept = ranked.last(keep).flatten
|
|
96
|
+
names(ranked.flatten - kept) - names(kept) + orphans_written_before(kept)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
#: (Array[Data::RequestLoggingFolder::IndexLine]) -> Array[String]
|
|
102
|
+
def orphans_written_before(kept)
|
|
103
|
+
oldest = kept.flat_map { |line| named_files(line) }.map(&:modified_at).min
|
|
104
|
+
return [] unless oldest
|
|
105
|
+
|
|
106
|
+
unnamed_requests.select { |file| file.modified_at < oldest }.map(&:name)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
#: () -> Array[Data::RequestLoggingFolder::CapturedFile]
|
|
110
|
+
def unnamed_requests
|
|
111
|
+
indexed = @index_lines.map { |line| base_name(line.request_file) }
|
|
112
|
+
@files.values.select { |file| file.name.end_with?(".request.json") && !indexed.include?(file.name) }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
#: (Array[Data::RequestLoggingFolder::IndexLine]) -> Array[String]
|
|
116
|
+
def names(lines) = lines.flat_map { |line| named_files(line) }.map(&:name).uniq
|
|
117
|
+
|
|
118
|
+
#: (String) -> String
|
|
119
|
+
def base_name(path) = path.split("/").last.to_s
|
|
120
|
+
|
|
121
|
+
# The files a line names that the folder holds, by name, since the index names them by their full paths.
|
|
122
|
+
#: (Data::RequestLoggingFolder::IndexLine) -> Array[Data::RequestLoggingFolder::CapturedFile]
|
|
123
|
+
def named_files(line)
|
|
124
|
+
[line.request_file, line.response_file].filter_map { |path| @files[base_name(path)] }
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../prose_list"
|
|
6
|
+
require_relative "agent_loads"
|
|
7
|
+
require_relative "hook_commands"
|
|
8
|
+
require_relative "plugin_reference"
|
|
9
|
+
|
|
10
|
+
module Principles
|
|
11
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
12
|
+
module Models
|
|
13
|
+
# The kind of harness carrier a member's file is, by its path, whose own practices a request names for judging and
|
|
14
|
+
# editing it: an instruction file, a rule, a skill or a subagent, a plugin's too, a hook configuration, a script a
|
|
15
|
+
# hook command names, or none when no host loads the path by itself.
|
|
16
|
+
# Text a program prints into context has no kind here: the path cannot show it, so the agent judges it.
|
|
17
|
+
class CarrierKind
|
|
18
|
+
# The instruction files a host reads in a folder, Claude Code's and Codex's, at the root or below it.
|
|
19
|
+
INSTRUCTION_FILE = %r{(?:\A|/)(?:CLAUDE\.md|\.claude/CLAUDE\.md|CLAUDE\.local\.md|AGENTS\.md)\z} #: Regexp
|
|
20
|
+
|
|
21
|
+
# A rule file in a .claude/rules folder, at the root or below it.
|
|
22
|
+
RULE_FILE = %r{(?:\A|/)\.claude/rules/.+\.md\z} #: Regexp
|
|
23
|
+
|
|
24
|
+
# A skill's file in any skills folder: under .claude, as SkillLoads::SKILL_FILE, whose loading it derives, or at a
|
|
25
|
+
# plugin's root, such as a project's own plugin folder, whose loading it does not.
|
|
26
|
+
SKILL_IN_ANY_SKILLS_FOLDER = %r{(?:\A|/)skills/[^/]+/SKILL\.md\z} #: Regexp
|
|
27
|
+
|
|
28
|
+
# A plugin member's agent file, in the agents folder at the plugin's root.
|
|
29
|
+
PLUGIN_AGENT_FILE = %r{\A#{Regexp.escape(PluginReference::PREFIX)}[^/]+/agents/(?:[^/]+/)*[^/]+\.md\z} #: Regexp
|
|
30
|
+
|
|
31
|
+
# The hooks file at a plugin's root, or a project's own plugin folder, beside the settings files hooks are read
|
|
32
|
+
# from.
|
|
33
|
+
HOOKS_FILE = %r{(?:\A|/)hooks/hooks\.json\z} #: Regexp
|
|
34
|
+
|
|
35
|
+
# Each kind a path alone shows, in the order they are tried, with the paths that make a file one.
|
|
36
|
+
BY_PATH = {
|
|
37
|
+
"instructions" => [INSTRUCTION_FILE],
|
|
38
|
+
"rule" => [RULE_FILE],
|
|
39
|
+
"skill" => [SKILL_IN_ANY_SKILLS_FOLDER],
|
|
40
|
+
"subagent" => [AgentLoads::AGENT_FILE, PLUGIN_AGENT_FILE],
|
|
41
|
+
"hook_configuration" => [HOOKS_FILE, *HookCommands::ON_EVERY_HOST.map { /\A#{Regexp.escape(it)}\z/ }]
|
|
42
|
+
}.freeze #: Hash[String, Array[Regexp]]
|
|
43
|
+
|
|
44
|
+
# The kind of a file no host loads by itself.
|
|
45
|
+
NONE = "none" #: String
|
|
46
|
+
|
|
47
|
+
# Every kind's name: those a path shows, then a hook script and none.
|
|
48
|
+
NAMES = [*BY_PATH.keys, "hook_script", NONE].freeze #: Array[String]
|
|
49
|
+
|
|
50
|
+
# name, as an agent gives it, refused unless it is one of NAMES.
|
|
51
|
+
#: (String) -> String
|
|
52
|
+
def self.named(name)
|
|
53
|
+
return name if NAMES.include?(name)
|
|
54
|
+
|
|
55
|
+
raise Error.new("unknown_carrier_kind", "There is no carrier kind named #{name.inspect}.",
|
|
56
|
+
"Name one of #{ProseList.new(NAMES)}.")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# named_in_hooks is whether a hook command names the file, which makes a file no other kind holds a hook script.
|
|
60
|
+
#: (String, ?named_in_hooks: bool) -> void
|
|
61
|
+
def initialize(path, named_in_hooks: false)
|
|
62
|
+
@path = path
|
|
63
|
+
@named_in_hooks = named_in_hooks
|
|
64
|
+
freeze
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The kind's name, as show-carrier-practices takes it: the first BY_PATH names, or else a hook script or none.
|
|
68
|
+
#: () -> String
|
|
69
|
+
def name
|
|
70
|
+
by_path = BY_PATH.find { |_, paths| paths.any? { it.match?(@path) } }&.first
|
|
71
|
+
by_path || (@named_in_hooks ? "hook_script" : NONE)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Whether a host loads a file of this kind by itself, so its absence from a request is not expected.
|
|
75
|
+
#: () -> bool
|
|
76
|
+
def carrier? = name != NONE
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "assessment_report"
|
|
5
5
|
require_relative "project_history"
|
|
6
|
+
require_relative "installed_plugins"
|
|
7
|
+
require_relative "plugin_reference"
|
|
6
8
|
|
|
7
9
|
module Principles
|
|
8
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -31,9 +33,16 @@ module Principles
|
|
|
31
33
|
changed.uniq.sort
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
# Each cited file that no longer exists, in git or outside it
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
# Each cited file that no longer exists, in git or outside it; a plugin's file, which is not in the project,
|
|
37
|
+
# when the plugin installed now does not hold it.
|
|
38
|
+
#: (InstalledPlugins) -> Array[String]
|
|
39
|
+
def missing(plugins)
|
|
40
|
+
existing = @history.existing(@paths)
|
|
41
|
+
@paths.reject do |path|
|
|
42
|
+
reference = PluginReference.in(path)
|
|
43
|
+
reference ? plugins.holds?(reference) : existing.include?(path)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
37
46
|
end
|
|
38
47
|
end
|
|
39
48
|
end
|
|
@@ -72,6 +72,11 @@ module Principles
|
|
|
72
72
|
inherited.key?(id) ? { "first_raised_at" => inherited.fetch(id) } : {}
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
# Where each deferral raised again was written up and whom it waited on, by the id of the new finding it became;
|
|
76
|
+
# none in a basis printed before they were carried.
|
|
77
|
+
#: () -> Hash[String, Hash[String, untyped]]
|
|
78
|
+
def deferrals_raised_again = @fields.fetch("deferrals_raised_again", {})
|
|
79
|
+
|
|
75
80
|
# These decisions with each kept finding filed under its members' ids after moves.
|
|
76
81
|
#: (MemberMoves) -> DecidedPriorFindings
|
|
77
82
|
def moved(moves)
|
|
@@ -8,6 +8,8 @@ require_relative "answer_text"
|
|
|
8
8
|
require_relative "disposition_placeholders"
|
|
9
9
|
require_relative "disposition_text_field"
|
|
10
10
|
require_relative "fix_only_fields"
|
|
11
|
+
require_relative "plugin_reference"
|
|
12
|
+
require_relative "unfixed_part"
|
|
11
13
|
require_relative "unfinished_field"
|
|
12
14
|
require_relative "waits_on"
|
|
13
15
|
require_relative "write_up_pointer"
|
|
@@ -24,13 +26,14 @@ module Principles
|
|
|
24
26
|
ACTIONS = %w[fixed deferred accepted disagreed].freeze #: Array[String]
|
|
25
27
|
|
|
26
28
|
# at is the disposition's place in the answer, such as /dispositions/0, which a refusal about its pointers names.
|
|
27
|
-
# samples is the answer guide's disposition for each action, whose text illustrates each field.
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
# samples is the answer guide's disposition for each action, whose text illustrates each field. subject is whose
|
|
30
|
+
# disposition a refusal names it as: its finding's, or the unfixed part's of the fix that gives it.
|
|
31
|
+
#: (untyped, AnswerFields, at: String, samples: Hash[String, untyped], ?subject: String) -> void
|
|
32
|
+
def initialize(disposition, fields, at:, samples:, subject: "Finding #{disposition["finding_id"]}")
|
|
30
33
|
@disposition = disposition
|
|
31
34
|
@fields = fields
|
|
32
35
|
@samples = samples
|
|
33
|
-
@place = AnswerPlace.new(at,
|
|
36
|
+
@place = AnswerPlace.new(at, subject) #: AnswerPlace
|
|
34
37
|
freeze
|
|
35
38
|
end
|
|
36
39
|
|
|
@@ -75,7 +78,19 @@ module Principles
|
|
|
75
78
|
# left empty, as the template's placeholder or as the answer guide's sample, and so a fix's reassessment,
|
|
76
79
|
# which applies to no other action, and a waits_on left as the guide's sample.
|
|
77
80
|
#: () -> Array[UnfinishedField]
|
|
78
|
-
def unfinished = [*unchosen_action, *unwritten_text, *waits_on_left_as_sample]
|
|
81
|
+
def unfinished = [*unchosen_action, *unwritten_text, *waits_on_left_as_sample, *unfixed_part&.unfinished]
|
|
82
|
+
|
|
83
|
+
# The part of its finding a fix leaves unfixed, as the agent gave it, or nil when it gives none.
|
|
84
|
+
#: () -> UnfixedPart?
|
|
85
|
+
def unfixed_part
|
|
86
|
+
part = @disposition["unfixed_part"]
|
|
87
|
+
return unless part
|
|
88
|
+
|
|
89
|
+
place = AnswerPlace.new(@place.child("unfixed_part").pointer, "Finding #{finding_id} unfixed_part")
|
|
90
|
+
own = Disposition.new(part.except("id", "problem").merge("finding_id" => part["id"]), @fields,
|
|
91
|
+
at: place.pointer, samples: @samples, subject: place.subject)
|
|
92
|
+
UnfixedPart.new(part, of: self, outcome: own, place:)
|
|
93
|
+
end
|
|
79
94
|
|
|
80
95
|
# The members this disposition claims it changed, refusing it unless its other fields are sound: only a fix
|
|
81
96
|
# claims any, and each must be among the members that changed. CorrectionAnswer has checked its action and
|
|
@@ -84,6 +99,7 @@ module Principles
|
|
|
84
99
|
def claimed_members(changed)
|
|
85
100
|
action = @disposition["action"]
|
|
86
101
|
checked_fields
|
|
102
|
+
unfixed_part&.check
|
|
87
103
|
members = @fields.array(fix_fields.list("changed_members"), "changed_members")
|
|
88
104
|
entries = @disposition.fetch("changed_map_entries", []) + @disposition.fetch("removed_members", [])
|
|
89
105
|
action == "fixed" ? fixed_members(members, entries, changed) : fix_fields.unclaimed(members, entries)
|
|
@@ -131,6 +147,7 @@ module Principles
|
|
|
131
147
|
# claims a map entry instead, which DeclaredMapChanges has checked changed.
|
|
132
148
|
#: (Array[untyped], Array[untyped], Array[String]) -> Array[untyped]
|
|
133
149
|
def fixed_members(members, entries, changed)
|
|
150
|
+
refuse_plugin_members(members)
|
|
134
151
|
return members unless (members.empty? && entries.empty?) || (members - changed).any?
|
|
135
152
|
|
|
136
153
|
raise Error.new("claimed_change_missing",
|
|
@@ -138,6 +155,20 @@ module Principles
|
|
|
138
155
|
"Make the authorised change and reassess it, or record a deferral.")
|
|
139
156
|
end
|
|
140
157
|
|
|
158
|
+
# A fix never claims a plugin's member changed, whatever its text did: principles never edits an installed
|
|
159
|
+
# plugin's files, which the plugin's next update replaces.
|
|
160
|
+
#: (Array[untyped]) -> void
|
|
161
|
+
def refuse_plugin_members(members)
|
|
162
|
+
plugin = members.select { |id| id.is_a?(String) && PluginReference.in(id) }
|
|
163
|
+
return if plugin.empty?
|
|
164
|
+
|
|
165
|
+
raise Error.new("plugin_member_read_only",
|
|
166
|
+
"Finding #{finding_id} claims a fix to #{plugin.join(", ")}, read from an installed plugin, " \
|
|
167
|
+
"which principles never edits",
|
|
168
|
+
"Settle it another way: fix it in the project's own files and claim those; or set its action " \
|
|
169
|
+
"to deferred, with recorded_at {\"url\": ...} where it is raised upstream; or to accepted.")
|
|
170
|
+
end
|
|
171
|
+
|
|
141
172
|
# The disposition's evidence and recorded_at, which a deferral must give, if only as null, and the
|
|
142
173
|
# one line a deferral may give saying what it waits on.
|
|
143
174
|
#: () -> void
|
|
@@ -168,7 +199,7 @@ module Principles
|
|
|
168
199
|
#: () -> bot
|
|
169
200
|
def unrecorded_deferral
|
|
170
201
|
raise Error.new("invalid_disposition", "Deferred finding #{finding_id} has no recorded_at",
|
|
171
|
-
"Set recorded_at to where the finding is written up, as {
|
|
202
|
+
"Set recorded_at to where the finding is written up, as #{AnswerFields::WRITE_UP_FORMS}; " \
|
|
172
203
|
"or to null when it is written up nowhere.")
|
|
173
204
|
end
|
|
174
205
|
end
|
|
@@ -45,6 +45,18 @@ module Principles
|
|
|
45
45
|
before: ACTION_PLACEHOLDER) #: NamedPlaceholder
|
|
46
46
|
# Every placeholder a slot of a correction's template prints, for any finding, or printed before.
|
|
47
47
|
NAMED = [*TEXT_FIELDS.values.map(&:placeholder), ACTION, EARLIER_ACTION].freeze #: Array[NamedPlaceholder]
|
|
48
|
+
# What the correction's question prints in an unfixed part's problem and reason, as its example
|
|
49
|
+
# `"problem": ..., ... "reason": ...` in dispose-of-each-finding/fix-or-record-each-finding.md, since no
|
|
50
|
+
# template prints an unfixed part.
|
|
51
|
+
QUESTION_EXAMPLE = NamedPlaceholder.new("...", before: "...") #: NamedPlaceholder
|
|
52
|
+
# The text fields an unfixed part gives, which the agent writes: the problem it raises as a finding of its own,
|
|
53
|
+
# and why it is left, which its outcome checks too against the template's reason.
|
|
54
|
+
UNFIXED_TEXT_FIELDS = {
|
|
55
|
+
"problem" => DispositionTextField.new(placeholder: QUESTION_EXAMPLE,
|
|
56
|
+
repair: "Write the problem the fix leaves unfixed."),
|
|
57
|
+
"reason" => DispositionTextField.new(placeholder: QUESTION_EXAMPLE,
|
|
58
|
+
repair: TEXT_FIELDS.fetch("reason").repair)
|
|
59
|
+
}.freeze #: Hash[String, DispositionTextField]
|
|
48
60
|
# Every placeholder a correction's template prints, each text field's and the action's, each with its slot.
|
|
49
61
|
TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION.slotted).freeze #: Hash[String, String]
|
|
50
62
|
|
|
@@ -19,6 +19,10 @@ module Principles
|
|
|
19
19
|
#: NamedPlaceholder
|
|
20
20
|
attr_reader :placeholder
|
|
21
21
|
|
|
22
|
+
# What to write instead.
|
|
23
|
+
#: String
|
|
24
|
+
attr_reader :repair
|
|
25
|
+
|
|
22
26
|
#: (placeholder: NamedPlaceholder, repair: String) -> void
|
|
23
27
|
def initialize(placeholder:, repair:)
|
|
24
28
|
@placeholder = placeholder
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# A feature that runs fast standard tools in place of Ruby, on only while every tool it needs is on PATH, with
|
|
10
|
+
# no Ruby fallback. TOOLS is the one central table of them, so no command checks PATH
|
|
11
|
+
# itself.
|
|
12
|
+
class Feature
|
|
13
|
+
# The command that scans the logged requests, which a full audit's request also runs.
|
|
14
|
+
LOGGED_REQUEST_SCAN = "show-members-in-logged-requests"
|
|
15
|
+
|
|
16
|
+
# Each feature's command, and the tools it runs, each with what it does there.
|
|
17
|
+
TOOLS = {
|
|
18
|
+
LOGGED_REQUEST_SCAN => {
|
|
19
|
+
"jq" => "decodes each captured request into its text lines",
|
|
20
|
+
"rg" => "finds mapped members' lines in the decoded requests"
|
|
21
|
+
}
|
|
22
|
+
}.freeze #: Hash[String, Hash[String, String]]
|
|
23
|
+
|
|
24
|
+
# The feature command runs, with on_path saying whether PATH holds a tool.
|
|
25
|
+
#: (String, on_path: ^(String) -> bool) -> void
|
|
26
|
+
def initialize(command, on_path:)
|
|
27
|
+
@command = command
|
|
28
|
+
@tools = TOOLS.fetch(command) #: Hash[String, String]
|
|
29
|
+
@on_path = on_path
|
|
30
|
+
freeze
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Refuses while a tool the feature runs is not on PATH, naming the first missing and what it does, so the agent
|
|
34
|
+
# asks the user to install it.
|
|
35
|
+
#: () -> void
|
|
36
|
+
def refuse_while_off
|
|
37
|
+
refusal = off_refusal
|
|
38
|
+
raise refusal if refusal
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# The refusal the feature gives while a tool it runs is not on PATH, or nil while it is on; for a command that
|
|
42
|
+
# carries on without the feature, such as a full audit's request without its logged-request evidence.
|
|
43
|
+
#: () -> Error?
|
|
44
|
+
def off_refusal
|
|
45
|
+
tool, does = @tools.find { |name, _| !@on_path.call(name) }
|
|
46
|
+
return unless tool
|
|
47
|
+
|
|
48
|
+
Error.new("fast_tools_missing", "#{@command} needs #{tool}, which #{does}, and #{tool} is not on PATH.",
|
|
49
|
+
"Ask the user before installing #{tool}, then run this again.")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "decided_prior_findings"
|
|
5
|
+
require_relative "recorded_finding"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The findings a completed full audit records: each finding its assessment raised, with its correction's
|
|
11
|
+
# disposition, each prior finding the audit kept, and each finding a fix raised from the part of its finding it
|
|
12
|
+
# left unfixed.
|
|
13
|
+
class FindingOutcomes
|
|
14
|
+
# findings are those the assessment raised, dispositions the correction's, one for each, and prior the
|
|
15
|
+
# decisions on the findings the last audit left open.
|
|
16
|
+
#: (Array[untyped], Array[Disposition], DecidedPriorFindings) -> void
|
|
17
|
+
def initialize(findings, dispositions, prior)
|
|
18
|
+
@findings = findings
|
|
19
|
+
@dispositions = dispositions
|
|
20
|
+
@prior = prior
|
|
21
|
+
freeze
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Each finding's outcome: its members and its disposition's action, where it is recorded, if anywhere, and
|
|
25
|
+
# what a deferral says it waits on, if anything.
|
|
26
|
+
# Then each prior finding kept; a new finding that raises one again keeps when it was first raised. Then each
|
|
27
|
+
# finding raised from an unfixed part, which keeps when the finding it was part of was first raised.
|
|
28
|
+
#: () -> Array[untyped]
|
|
29
|
+
def recorded
|
|
30
|
+
raised = @findings.map do |finding|
|
|
31
|
+
id = finding.fetch("id")
|
|
32
|
+
outcome = disposition_of(id).recorded_outcome
|
|
33
|
+
finding.slice(*RecordedFinding::RAISED_FIELDS).merge(outcome, @prior.first_raised(id))
|
|
34
|
+
end + @prior.kept
|
|
35
|
+
@findings.reduce(raised) { |so_far, finding| with_unfixed_part(so_far, finding) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
#: (untyped) -> Disposition
|
|
41
|
+
def disposition_of(id) = @dispositions.find { |each| each.finding_id == id } || raise(KeyError, id)
|
|
42
|
+
|
|
43
|
+
# recorded, with the finding raised from the part of finding its fix left unfixed, if any, refused when an id
|
|
44
|
+
# in recorded is its id.
|
|
45
|
+
#: (Array[untyped], Hash[String, untyped]) -> Array[untyped]
|
|
46
|
+
def with_unfixed_part(recorded, finding)
|
|
47
|
+
id = finding.fetch("id")
|
|
48
|
+
part = disposition_of(id).unfixed_part
|
|
49
|
+
return recorded unless part
|
|
50
|
+
|
|
51
|
+
recorded + [part.raised_from(finding, recorded.map { it.fetch("id") }).merge(@prior.first_raised(id))]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -7,7 +7,7 @@ module Principles
|
|
|
7
7
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
8
|
module Models
|
|
9
9
|
# Every finding the records leave open, deferred or accepted, as one fact the session-start line states: how
|
|
10
|
-
# many wait, and which has waited longest.
|
|
10
|
+
# many deferred wait, and which of them has waited longest.
|
|
11
11
|
class FindingsLeftOpen
|
|
12
12
|
# The findings each record leaves open for the next full audit.
|
|
13
13
|
#: (Array[AuditRecord]) -> FindingsLeftOpen
|
|
@@ -19,19 +19,17 @@ module Principles
|
|
|
19
19
|
freeze
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
# How many
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
# waits_on was asked, which a later audit may have given it.
|
|
22
|
+
# How many someone should raise, those deferred, how many of them have no waits_on and how many one, and the
|
|
23
|
+
# first raised earliest of them as it has waited until now, or nil when none is deferred: an accepted finding
|
|
24
|
+
# waits on no one by design, so every start counts the same. How long it waited runs from first_raised_at,
|
|
25
|
+
# never from when its waits_on was asked, which a later audit may have given it.
|
|
26
26
|
#: (Time) -> Hash[String, untyped]?
|
|
27
27
|
def waiting_at(now)
|
|
28
|
-
|
|
28
|
+
deferred = @findings.select { it.action == "deferred" }
|
|
29
|
+
oldest = deferred.min_by(&:first_raised_time) or return nil
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ "count" => @findings.length, "waiting_on_no_one_named" => unnamed,
|
|
33
|
-
"waiting_on_someone_named" => named.length, "to_raise" => named.length + unnamed,
|
|
34
|
-
"oldest_waiting_on_someone" => named.min_by(&:first_raised_time)&.waited_at(now), **oldest.waited_at(now) }
|
|
31
|
+
{ "count" => deferred.length, "waiting_on_no_one_named" => deferred.count(&:waiting_on_no_one_named?),
|
|
32
|
+
"waiting_on_someone_named" => deferred.count(&:waiting_on_someone_named?), **oldest.waited_at(now) }
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
end
|
|
@@ -10,7 +10,8 @@ module Principles
|
|
|
10
10
|
# Which repositories' HEAD a shell call moved by committing, each named once, in the order the call's
|
|
11
11
|
# directories name them, with the commit HEAD named before the move: what report-after-commit reports on. A
|
|
12
12
|
# checkout or a reset moves HEAD to commits that exist already, so neither is named; the next session start
|
|
13
|
-
# shows any change there. A project never mapped, under the folder's name now or its earlier one, is not named
|
|
13
|
+
# shows any change there. A project never mapped, under the folder's name now or its earlier one, is not named,
|
|
14
|
+
# nor a repository other than the session's project's, such as a scratch clone; its worktrees are named.
|
|
14
15
|
class HeadMoves
|
|
15
16
|
# One repository's move: its root, and the full sha HEAD named before it.
|
|
16
17
|
class Move
|
|
@@ -28,9 +29,12 @@ module Principles
|
|
|
28
29
|
# The reflog subjects of moves that bring in no new commit.
|
|
29
30
|
NOT_A_COMMIT = /\A(?:checkout|reset):/ #: Regexp
|
|
30
31
|
|
|
32
|
+
# What git says of a directory on this machine.
|
|
33
|
+
GIT_AT = ->(directory) { Data::HeadReflog.new(directory) } #: ^(String) -> untyped
|
|
34
|
+
|
|
31
35
|
# git_at gives what git says of a directory, as Data::HeadReflog does.
|
|
32
36
|
#: (AfterCommitInput, ?^(String) -> untyped) -> void
|
|
33
|
-
def initialize(input, git_at =
|
|
37
|
+
def initialize(input, git_at = GIT_AT)
|
|
34
38
|
@input = input
|
|
35
39
|
@git_at = git_at
|
|
36
40
|
freeze
|
|
@@ -38,20 +42,33 @@ module Principles
|
|
|
38
42
|
|
|
39
43
|
#: () -> Array[Move]
|
|
40
44
|
def to_a
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
git = @git_at.call(directory)
|
|
44
|
-
root = git.toplevel
|
|
45
|
-
next if root.nil? || seen.include?(root)
|
|
46
|
-
|
|
47
|
-
seen << root
|
|
45
|
+
project = nil #: String?
|
|
46
|
+
repositories.filter_map do |root, git|
|
|
48
47
|
before = git.mapped? && before_the_move(git)
|
|
49
|
-
|
|
48
|
+
next unless before && git.common_dir == (project ||= the_sessions_repository)
|
|
49
|
+
|
|
50
|
+
Move.new(root:, before:)
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
private
|
|
54
55
|
|
|
56
|
+
# The git folder of the session's project, which its worktrees share and a clone does not, or a value no
|
|
57
|
+
# repository's matches when the session's directory is outside git. Asked only once a repository moved, so a
|
|
58
|
+
# call that committed nothing costs no more git.
|
|
59
|
+
#: () -> String
|
|
60
|
+
def the_sessions_repository = @git_at.call(@input.session_directory).common_dir || ""
|
|
61
|
+
|
|
62
|
+
# Each repository the call's directories are in, once, in their order: what git says of it, by its root.
|
|
63
|
+
#: () -> Hash[String, untyped]
|
|
64
|
+
def repositories
|
|
65
|
+
@input.directories.each_with_object({}) do |directory, found|
|
|
66
|
+
git = @git_at.call(directory)
|
|
67
|
+
root = git.toplevel
|
|
68
|
+
found[root] ||= git if root
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
55
72
|
# The commit HEAD named before it moved during the call, or nil when it did not move then, or moved to no
|
|
56
73
|
# new commit. Without a reflog, HEAD's committer time stands in, and the commit before HEAD starts the range.
|
|
57
74
|
#: (untyped) -> String?
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "digest"
|
|
5
|
+
require_relative "plugin_install"
|
|
6
|
+
require_relative "plugin_reference"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# A file of an installed plugin as a session here would read it: its reference, the install it is in and its
|
|
12
|
+
# text, read once.
|
|
13
|
+
class InstalledComponent
|
|
14
|
+
#: String
|
|
15
|
+
attr_reader :text
|
|
16
|
+
|
|
17
|
+
#: (PluginReference, PluginInstall, String) -> void
|
|
18
|
+
def initialize(reference, install, text)
|
|
19
|
+
@reference = reference
|
|
20
|
+
@install = install
|
|
21
|
+
@text = text
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The version the host installed, for the agent's information only.
|
|
26
|
+
#: () -> String?
|
|
27
|
+
def version = @install.version
|
|
28
|
+
|
|
29
|
+
# The member's path in its map, as its reference names it.
|
|
30
|
+
#: () -> String
|
|
31
|
+
def member_path = @reference.to_s
|
|
32
|
+
|
|
33
|
+
# What the map pins of it: the version installed, and the hash of its text, which alone says whether it changed.
|
|
34
|
+
#: () -> Hash[String, String]
|
|
35
|
+
def pinned = { "version" => version.to_s, "sha256" => Digest::SHA256.hexdigest(@text) }
|
|
36
|
+
|
|
37
|
+
# Where it comes from, as a result prints it.
|
|
38
|
+
#: () -> Hash[String, untyped]
|
|
39
|
+
def source = @reference.source(version)
|
|
40
|
+
|
|
41
|
+
# Its entry in a map, playing role.
|
|
42
|
+
#: (String) -> Hash[String, untyped]
|
|
43
|
+
def member(role) = { "path" => member_path, "role" => role, "pinned" => pinned }
|
|
44
|
+
|
|
45
|
+
# What add-member reports of it: its id, the lines it spans and where it comes from. No host's loading of a
|
|
46
|
+
# plugin's file is derived yet.
|
|
47
|
+
#: () -> Hash[String, untyped]
|
|
48
|
+
def added = { "id" => member_path, **lines, "loading" => "not_derived", "source" => source }
|
|
49
|
+
|
|
50
|
+
# The lines it spans: the whole file.
|
|
51
|
+
#: () -> Hash[String, Integer]
|
|
52
|
+
def lines = { "first_line" => 1, "last_line" => [@text.lines.size, 1].max }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|