principles 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +132 -0
- data/README.md +10 -6
- data/lib/principles/command_line.rb +15 -6
- data/lib/principles/command_routes.rb +11 -1
- data/lib/principles/controllers/acknowledgement.rb +19 -4
- data/lib/principles/controllers/acknowledgements.rb +43 -12
- data/lib/principles/controllers/after_commit_report.rb +15 -2
- data/lib/principles/controllers/assessment.rb +7 -3
- data/lib/principles/controllers/audit.rb +17 -8
- data/lib/principles/controllers/audit_completion.rb +34 -9
- data/lib/principles/controllers/carrier_practices.rb +26 -0
- data/lib/principles/controllers/command.rb +31 -3
- data/lib/principles/controllers/correction.rb +15 -5
- data/lib/principles/controllers/full_audit_request.rb +38 -42
- data/lib/principles/controllers/inventory.rb +77 -71
- data/lib/principles/controllers/last_record_notice_beside.rb +51 -0
- data/lib/principles/controllers/member_acknowledgement.rb +21 -11
- data/lib/principles/controllers/member_addition.rb +19 -4
- data/lib/principles/controllers/member_entries.rb +25 -6
- data/lib/principles/controllers/member_problems_report.rb +26 -6
- data/lib/principles/controllers/members_a_commit_changed.rb +14 -5
- data/lib/principles/controllers/members_in_logged_requests.rb +52 -0
- data/lib/principles/controllers/members_to_assess.rb +24 -7
- data/lib/principles/controllers/meta_principle_setup.rb +2 -2
- data/lib/principles/controllers/open_correction.rb +3 -2
- data/lib/principles/controllers/parts_to_read.rb +46 -5
- data/lib/principles/controllers/plugin_member_addition.rb +48 -0
- data/lib/principles/controllers/principle_listing.rb +84 -0
- data/lib/principles/controllers/request_logging.rb +52 -0
- data/lib/principles/controllers/running_tool.rb +45 -17
- data/lib/principles/data/branches_bringing_in.rb +52 -0
- data/lib/principles/data/changes_since.rb +56 -0
- data/lib/principles/data/claude_code_home.rb +58 -0
- data/lib/principles/data/command-steps.json +91 -15
- data/lib/principles/data/decoded_leaf.rb +63 -0
- data/lib/principles/data/head_reflog.rb +13 -2
- data/lib/principles/data/kept_line.rb +32 -0
- data/lib/principles/data/known_marketplaces.rb +50 -0
- data/lib/principles/data/logged_request_matches.rb +138 -0
- data/lib/principles/data/logged_request_scan.rb +120 -0
- data/lib/principles/data/map_files.rb +18 -4
- data/lib/principles/data/plugin_folder.rb +85 -0
- data/lib/principles/data/plugin_registry.rb +73 -0
- data/lib/principles/data/principles_store.rb +49 -0
- data/lib/principles/data/ran.rb +25 -0
- data/lib/principles/data/raw_request_filter.rb +61 -0
- data/lib/principles/data/repository.rb +34 -27
- data/lib/principles/data/request_logging_folder.rb +167 -0
- data/lib/principles/data/running_version.rb +1 -1
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +16 -1
- data/lib/principles/data/schemas/acknowledgements-answer.schema.json +16 -1
- data/lib/principles/data/schemas/assessment-answer.schema.json +8 -0
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +14 -0
- data/lib/principles/data/schemas/member-map.schema.json +10 -1
- data/lib/principles/data/string_counts.rb +39 -0
- data/lib/principles/data/tools_on_path.rb +25 -0
- data/lib/principles/invocation_options.rb +4 -2
- data/lib/principles/launch.rb +14 -4
- data/lib/principles/models/acknowledged_check.rb +11 -1
- data/lib/principles/models/acknowledgement.rb +15 -0
- data/lib/principles/models/acknowledgement_placeholders.rb +43 -18
- data/lib/principles/models/acknowledgement_refusal.rb +20 -11
- data/lib/principles/models/acknowledgements_to_offer.rb +86 -0
- data/lib/principles/models/after_commit_input.rb +5 -0
- data/lib/principles/models/answer_fields.rb +3 -0
- data/lib/principles/models/assessment_basis.rb +10 -3
- data/lib/principles/models/audit.rb +10 -10
- data/lib/principles/models/audit_record.rb +10 -0
- data/lib/principles/models/audit_records.rb +4 -3
- data/lib/principles/models/audit_start.rb +9 -0
- data/lib/principles/models/authored_locator.rb +33 -0
- data/lib/principles/models/candidate_files.rb +23 -3
- data/lib/principles/models/candidate_outline.rb +18 -125
- data/lib/principles/models/captured_sessions.rb +128 -0
- data/lib/principles/models/carrier_kind.rb +79 -0
- data/lib/principles/models/cited_files.rb +12 -3
- data/lib/principles/models/decided_prior_findings.rb +5 -0
- data/lib/principles/models/disposition.rb +38 -7
- data/lib/principles/models/disposition_placeholders.rb +27 -7
- data/lib/principles/models/disposition_text_field.rb +4 -0
- data/lib/principles/models/feature.rb +53 -0
- data/lib/principles/models/finding_outcomes.rb +55 -0
- data/lib/principles/models/findings_left_open.rb +9 -11
- data/lib/principles/models/head_moves.rb +27 -10
- data/lib/principles/models/installed_component.rb +55 -0
- data/lib/principles/models/installed_plugins.rb +174 -0
- data/lib/principles/models/kept_sessions.rb +34 -0
- data/lib/principles/models/locator.rb +8 -0
- data/lib/principles/models/logged_request_reach.rb +44 -0
- data/lib/principles/models/logged_request_scan_completeness.rb +43 -0
- data/lib/principles/models/mapped_baseline.rb +46 -0
- data/lib/principles/models/maps_holding_file_whole.rb +42 -0
- data/lib/principles/models/markdown_text.rb +143 -0
- data/lib/principles/models/member.rb +14 -1
- data/lib/principles/models/member_entry.rb +56 -0
- data/lib/principles/models/member_lines.rb +11 -0
- data/lib/principles/models/member_loads.rb +17 -2
- data/lib/principles/models/member_problems.rb +45 -42
- data/lib/principles/models/member_reach.rb +36 -0
- data/lib/principles/models/member_snapshots.rb +23 -4
- data/lib/principles/models/member_text_as_sent.rb +31 -0
- data/lib/principles/models/member_texts.rb +45 -0
- data/lib/principles/models/members_in_logged_requests.rb +240 -0
- data/lib/principles/models/missing_files.rb +41 -16
- data/lib/principles/models/named_placeholder.rb +17 -7
- data/lib/principles/models/nearly_matching_maps.rb +56 -0
- data/lib/principles/models/open_correction.rb +5 -0
- data/lib/principles/models/open_finding.rb +4 -3
- data/lib/principles/models/outline_budget.rb +10 -1
- data/lib/principles/models/outline_item.rb +25 -0
- data/lib/principles/models/outline_section.rb +15 -4
- data/lib/principles/models/part_named.rb +16 -2
- data/lib/principles/models/plugin_component.rb +37 -0
- data/lib/principles/models/plugin_install.rb +33 -0
- data/lib/principles/models/plugin_name.rb +23 -0
- data/lib/principles/models/plugin_reference.rb +53 -0
- data/lib/principles/models/principle_members.rb +15 -0
- data/lib/principles/models/prior_finding_decision.rb +1 -1
- data/lib/principles/models/prior_finding_outcomes.rb +12 -1
- data/lib/principles/models/problem_report.rb +14 -25
- data/lib/principles/models/project.rb +35 -29
- data/lib/principles/models/project_history.rb +23 -0
- data/lib/principles/models/recorded_members.rb +7 -0
- data/lib/principles/models/request_logging.rb +196 -0
- data/lib/principles/models/runs_from.rb +0 -5
- data/lib/principles/models/script_comments.rb +58 -0
- data/lib/principles/models/stale_request.rb +9 -0
- data/lib/principles/models/template_placeholders.rb +10 -9
- data/lib/principles/models/unfixed_part.rb +82 -0
- data/lib/principles/models/unresolved_plugin_members.rb +35 -0
- data/lib/principles/models/whole_file_member_read.rb +48 -0
- data/lib/principles/models/without_prose.rb +20 -0
- data/lib/principles/models/workflow_jobs.rb +92 -0
- data/lib/principles/show_members_in_logged_requests_options.rb +27 -0
- data/lib/principles/show_principle_options.rb +32 -0
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledged_result.rb +31 -12
- data/lib/principles/views/acknowledgement_result.rb +41 -29
- data/lib/principles/views/acknowledgement_template_alone.rb +55 -0
- data/lib/principles/views/acknowledgements_offered.rb +54 -0
- data/lib/principles/views/added_member.rb +22 -6
- data/lib/principles/views/answer_in_a_file.rb +16 -16
- data/lib/principles/views/assessed_members.rb +18 -7
- data/lib/principles/views/assessment_request.rb +8 -3
- data/lib/principles/views/audit_changes.rb +14 -8
- data/lib/principles/views/audit_findings.rb +34 -0
- data/lib/principles/views/audit_result.rb +14 -19
- data/lib/principles/views/carrier_checks.rb +40 -0
- data/lib/principles/views/carrier_practices_page.rb +49 -0
- data/lib/principles/views/completed_audit_findings.rb +33 -0
- data/lib/principles/views/completed_audit_next_step.rb +12 -4
- data/lib/principles/views/consecutive_sections_elsewhere.rb +4 -0
- data/lib/principles/views/context_parts.rb +129 -25
- data/lib/principles/views/correction_request.rb +22 -17
- data/lib/principles/views/disposition_template.rb +35 -0
- data/lib/principles/views/first_audit.rb +29 -15
- data/lib/principles/views/first_audit_brief.rb +0 -1
- data/lib/principles/views/first_audit_line.rb +4 -5
- data/lib/principles/views/invocation.rb +16 -6
- data/lib/principles/views/last_record_notice.rb +41 -0
- data/lib/principles/views/lines_shared_with_member.rb +16 -22
- data/lib/principles/views/logged_request_status_meanings.rb +29 -0
- data/lib/principles/views/logged_requests_evidence.rb +69 -0
- data/lib/principles/views/map_added_to.rb +14 -12
- data/lib/principles/views/map_result.rb +39 -17
- data/lib/principles/views/member_change_since_baseline.rb +4 -0
- data/lib/principles/views/member_row.rb +13 -4
- data/lib/principles/views/member_sets_overlap.rb +31 -0
- data/lib/principles/views/members_a_commit_changed.rb +42 -25
- data/lib/principles/views/members_changed_during_audit.rb +27 -0
- data/lib/principles/views/members_in_logged_requests_result.rb +68 -0
- data/lib/principles/views/members_too_short_to_scan.rb +45 -0
- data/lib/principles/views/members_with_no_baseline.rb +6 -6
- data/lib/principles/views/meta_principle_result.rb +14 -2
- data/lib/principles/views/open_findings_line.rb +31 -92
- data/lib/principles/views/parts_index_result.rb +9 -5
- data/lib/principles/views/principle_read_result.rb +52 -11
- data/lib/principles/views/prior_findings_result.rb +9 -1
- data/lib/principles/views/problem_facts.rb +5 -3
- data/lib/principles/views/problem_lines.rb +32 -6
- data/lib/principles/views/problem_result.rb +7 -15
- data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +6 -6
- data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +9 -8
- data/lib/principles/views/prompts/assess-every-member/read-a-flagged-member-s-text-whole.md +3 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-judged-member-s-text-whole.md +3 -0
- data/lib/principles/views/prompts/assess-every-member/turn-on-request-logging-to-see-what-reaches-context.md +2 -0
- data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +7 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +1 -1
- data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +1 -1
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-configuration.md +41 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-hook-scripts.md +35 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-instruction-files.md +37 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-other-text-an-agent-reads.md +38 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-rule-files.md +34 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-skills.md +35 -0
- data/lib/principles/views/prompts/follow-each-carriers-best-practices/practices-for-subagent-definitions.md +35 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +50 -51
- data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +32 -32
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
- data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +7 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +16 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +2 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +3 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +7 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +8 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/show-carrier-practices.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +20 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +48 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +14 -14
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -27
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +11 -11
- data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +10 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +32 -0
- data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +3 -2
- data/lib/principles/views/prompts/read-what-reached-the-context/explain-request-logging-to-the-user.md +11 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/see-whether-members-reach-the-agent.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-absent-means.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-not-a-carrier-means.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-present-but-not-loaded-means.md +2 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-present-means.md +1 -0
- data/lib/principles/views/prompts/read-what-reached-the-context/what-unmeasurable-means.md +2 -0
- data/lib/principles/views/prompts/report-after-a-commit/plugin-members-are-still-listed.md +1 -0
- data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -2
- data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members.md +2 -2
- data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-what-each-needs-before-the-next-commit.md +1 -0
- data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
- data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
- data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +2 -1
- data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +2 -3
- data/lib/principles/views/prompts/start-a-session/raise-the-open-findings-waiting-on-no-one.md +1 -0
- data/lib/principles/views/request_logging_result.rb +62 -0
- data/lib/principles/views/request_part.rb +10 -4
- data/lib/principles/views/request_parts.rb +9 -0
- data/lib/principles/views/whole_file_elsewhere.rb +30 -0
- metadata +101 -4
- data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +0 -1
- data/lib/principles/views/prompts/report-after-a-commit/this-command-shows-each-one.md +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# The install of a plugin a session in the project loads, as one of its Claude Code registry rows: the first, in
|
|
8
|
+
# the host's order, that is a user install or one for the project's main checkout. A probe found the host chose so:
|
|
9
|
+
# by order, not by a ranking of scopes, and in a git worktree by its main checkout's row.
|
|
10
|
+
class PluginInstall
|
|
11
|
+
# The row that applies to the project whose main checkout is at main_checkout, or nil when none does.
|
|
12
|
+
#: (Array[Hash[String, String?]], main_checkout: String) -> PluginInstall?
|
|
13
|
+
def self.applying(rows, main_checkout:)
|
|
14
|
+
row = rows.find { |each| each["scope"] == "user" || each["project_path"] == main_checkout }
|
|
15
|
+
new(row) if row
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#: (Hash[String, String?]) -> void
|
|
19
|
+
def initialize(row)
|
|
20
|
+
@row = row
|
|
21
|
+
freeze
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The version the host installed, which it gives for the agent's information only.
|
|
25
|
+
#: () -> String?
|
|
26
|
+
def version = @row["version"]
|
|
27
|
+
|
|
28
|
+
# The folder the host installed this copy in.
|
|
29
|
+
#: () -> String?
|
|
30
|
+
def install_path = @row["install_path"]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# A plugin's install name as Claude Code records it, NAME@MARKETPLACE, which names the marketplace it came from.
|
|
8
|
+
class PluginName
|
|
9
|
+
#: (String) -> void
|
|
10
|
+
def initialize(name)
|
|
11
|
+
@name = name
|
|
12
|
+
freeze
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# The marketplace the plugin came from: what follows the first @, or the whole name when it has none.
|
|
16
|
+
#: () -> String
|
|
17
|
+
def marketplace = @name.split("@", 2).last.to_s
|
|
18
|
+
|
|
19
|
+
#: () -> String
|
|
20
|
+
def to_s = @name
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "plugin_component"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# A plugin member's path in its map, plugin://HOST/NAME@MARKETPLACE/COMPONENT: the host, the plugin's install name
|
|
10
|
+
# and the file's path inside the plugin, with no version, so its id stays the same across updates, and no machine
|
|
11
|
+
# path.
|
|
12
|
+
class PluginReference
|
|
13
|
+
# The host a plugin member's path names; Codex is not read yet.
|
|
14
|
+
HOST = "claude-code" #: String
|
|
15
|
+
|
|
16
|
+
# What every plugin member's path starts with.
|
|
17
|
+
PREFIX = "plugin://#{HOST}/".freeze #: String
|
|
18
|
+
|
|
19
|
+
# The plugin member path names, or nil when it names a project file.
|
|
20
|
+
#: (String) -> PluginReference?
|
|
21
|
+
def self.in(path)
|
|
22
|
+
return unless path.start_with?(PREFIX)
|
|
23
|
+
|
|
24
|
+
name, component = path.delete_prefix(PREFIX).split("/", 2)
|
|
25
|
+
new(name.to_s, PluginComponent.new(component.to_s))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The plugin's install name, NAME@MARKETPLACE.
|
|
29
|
+
#: String
|
|
30
|
+
attr_reader :name
|
|
31
|
+
|
|
32
|
+
#: PluginComponent
|
|
33
|
+
attr_reader :component
|
|
34
|
+
|
|
35
|
+
#: (String, PluginComponent) -> void
|
|
36
|
+
def initialize(name, component)
|
|
37
|
+
@name = name
|
|
38
|
+
@component = component
|
|
39
|
+
freeze
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#: () -> String
|
|
43
|
+
def to_s = "#{PREFIX}#{@name}/#{@component.path}"
|
|
44
|
+
|
|
45
|
+
# Where it comes from, at the version installed, as a result prints it: read-only, since the host replaces its
|
|
46
|
+
# files on update.
|
|
47
|
+
#: (String?) -> Hash[String, untyped]
|
|
48
|
+
def source(version)
|
|
49
|
+
{ "host" => HOST, "plugin" => @name, "version" => version, "component" => @component.path, "read_only" => true }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -46,6 +46,21 @@ module Principles
|
|
|
46
46
|
#: () -> Array[String]
|
|
47
47
|
def keys = @list.map(&:key)
|
|
48
48
|
|
|
49
|
+
# The members in the project's own files, which git holds, leaving out those a plugin gives.
|
|
50
|
+
#: () -> PrincipleMembers
|
|
51
|
+
def in_project = PrincipleMembers.new(@principle_id, @list.reject(&:plugin_reference))
|
|
52
|
+
|
|
53
|
+
# What the map pinned of each plugin member, by key: the version and the hash of its text when it was mapped.
|
|
54
|
+
#: () -> Hash[String, Hash[String, String]]
|
|
55
|
+
def pinned
|
|
56
|
+
pins = {} #: Hash[String, Hash[String, String]]
|
|
57
|
+
@list.each do |member|
|
|
58
|
+
pin = member.pinned
|
|
59
|
+
pins[member.key] = pin if pin
|
|
60
|
+
end
|
|
61
|
+
pins
|
|
62
|
+
end
|
|
63
|
+
|
|
49
64
|
# Each member by its id.
|
|
50
65
|
#: () -> Hash[String, Member]
|
|
51
66
|
def by_id = @list.to_h { |member| [member.id, member] }
|
|
@@ -124,7 +124,7 @@ module Principles
|
|
|
124
124
|
#: () -> bot
|
|
125
125
|
def unrecorded_deferral
|
|
126
126
|
invalid("deferring it needs recorded_at, or null when it is written up nowhere",
|
|
127
|
-
"Set recorded_at to where #{@id} is written up, as {
|
|
127
|
+
"Set recorded_at to where #{@id} is written up, as #{AnswerFields::WRITE_UP_FORMS}; or to null.")
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
# The action the finding keeps once decided, or nil when the decision closes it or raises it again.
|
|
@@ -26,7 +26,8 @@ module Principles
|
|
|
26
26
|
holding = of(["still_holds"]).map(&:kept)
|
|
27
27
|
DecidedPriorFindings.new(
|
|
28
28
|
{ "kept" => holding.map(&:to_h), "closed" => of(PriorFindingDecision::CLOSING).map(&:closed),
|
|
29
|
-
"inherited" => first_raised(of(["raised_again"])),
|
|
29
|
+
"inherited" => first_raised(of(["raised_again"])),
|
|
30
|
+
"deferrals_raised_again" => deferrals(of(["raised_again"])), **changed(holding) }
|
|
30
31
|
)
|
|
31
32
|
end
|
|
32
33
|
|
|
@@ -54,6 +55,16 @@ module Principles
|
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
|
|
58
|
+
# Where each deferral raised again was written up and whom it waited on, by the id of the new finding it became,
|
|
59
|
+
# so that finding's correction starts from them rather than from nothing.
|
|
60
|
+
#: (Array[PriorFindingDecision]) -> Hash[String, Hash[String, untyped]]
|
|
61
|
+
def deferrals(raised)
|
|
62
|
+
raised.select { |decision| decision.finding.action == "deferred" }.to_h do |decision|
|
|
63
|
+
[decision.raised_as, { "recorded_at" => decision.finding.recorded_at&.to_h,
|
|
64
|
+
"waits_on" => decision.finding.waits_on }]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
57
68
|
#: (String, Array[String]) -> void
|
|
58
69
|
def raised_once(as, ids)
|
|
59
70
|
return if ids.one?
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "../error"
|
|
5
|
+
require_relative "acknowledgements_to_offer"
|
|
5
6
|
require_relative "member_problems"
|
|
6
7
|
require_relative "missing_files"
|
|
7
8
|
|
|
@@ -52,7 +53,8 @@ module Principles
|
|
|
52
53
|
|
|
53
54
|
{ "members" => changed(&),
|
|
54
55
|
"counts" => @maps.flat_map(&:entries).map { |each| each.fetch("state") }.tally.sort.to_h,
|
|
55
|
-
"compared_with" => compared_with, **no_baseline_because, **awaiting_first_audit_field, **mapping_facts
|
|
56
|
+
"compared_with" => compared_with, **no_baseline_because, **awaiting_first_audit_field, **mapping_facts,
|
|
57
|
+
**plugin_unresolved }
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
# The principles that await their first full audit, in map order, which list-member-problems names in one
|
|
@@ -74,22 +76,10 @@ module Principles
|
|
|
74
76
|
#: () -> Hash[String, Integer]
|
|
75
77
|
def never_assessed = @maps.to_h { [it.principle_id, it.never_assessed] }.reject { |_, count| count.zero? }
|
|
76
78
|
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
#: (
|
|
80
|
-
def
|
|
81
|
-
@maps.to_h { |map| [map.principle_id, map.acknowledgeable_member_ids] }.reject { |_, ids| ids.empty? }
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# The acknowledgeable members, those of principles that share one joined in one acknowledgement across them:
|
|
85
|
-
# each set of principle ids, in id order, with the members they acknowledge together, leaving out the
|
|
86
|
-
# principles in except, whose records wait on an upgrade.
|
|
87
|
-
#: (?except: Array[String]) -> Hash[Array[String], Array[String]]
|
|
88
|
-
def acknowledgeable_together(except: [])
|
|
89
|
-
acknowledgeable.reduce({}) do |groups, (id, members)|
|
|
90
|
-
except.include?(id) ? groups : joining(groups, id, members)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
79
|
+
# The one-member audits list-member-problems offers, but for the principles in except, whose records wait on an
|
|
80
|
+
# upgrade.
|
|
81
|
+
#: (?except: Array[String]) -> AcknowledgementsToOffer
|
|
82
|
+
def acknowledgements(except: []) = AcknowledgementsToOffer.new(@maps, except:)
|
|
93
83
|
|
|
94
84
|
# For each map with members no baseline holds, its map file and the files those members are in, and in git
|
|
95
85
|
# only those of them that differ from HEAD or are untracked, since committing an unchanged file does nothing.
|
|
@@ -161,6 +151,13 @@ module Principles
|
|
|
161
151
|
"empty_maps" => @maps.select(&:empty_map?).map(&:principle_id) }.reject { |_key, ids| ids.empty? }
|
|
162
152
|
end
|
|
163
153
|
|
|
154
|
+
# Each plugin member no installed plugin gives, with why, which refuses nothing; none when every one resolves.
|
|
155
|
+
#: () -> Hash[String, Array[Hash[String, untyped]]]
|
|
156
|
+
def plugin_unresolved
|
|
157
|
+
unresolved = @maps.flat_map(&:entries).select { it.fetch("state") == "plugin_unresolved" }
|
|
158
|
+
unresolved.empty? ? {} : { "plugin_unresolved" => unresolved.map { it.slice("principle", "id", "reason") } }
|
|
159
|
+
end
|
|
160
|
+
|
|
164
161
|
#: (Array[Hash[String, untyped]]) -> bot
|
|
165
162
|
def refuse(broken)
|
|
166
163
|
named = broken.map { |each| [each["principle"], each["id"]].compact.join(" ") }
|
|
@@ -169,14 +166,6 @@ module Principles
|
|
|
169
166
|
rerun: "#{Error::EXECUTABLE} list-member-problems",
|
|
170
167
|
note: "A map listed as unreadable_map needs its own refusal's repair. ")
|
|
171
168
|
end
|
|
172
|
-
|
|
173
|
-
# groups with principle id's members joined into each group that shares one of them, as one group.
|
|
174
|
-
#: (Hash[Array[String], Array[String]], String, Array[String]) -> Hash[Array[String], Array[String]]
|
|
175
|
-
def joining(groups, id, members)
|
|
176
|
-
joined = groups.select { |_ids, others| others.intersect?(members) }
|
|
177
|
-
rest = groups.reject { |ids, _others| joined.key?(ids) }
|
|
178
|
-
rest.merge([*joined.keys.flatten, id].sort => [*joined.values.flatten, *members].uniq)
|
|
179
|
-
end
|
|
180
169
|
end
|
|
181
170
|
end
|
|
182
171
|
end
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "../data/project_files"
|
|
5
5
|
require_relative "../data/project_root"
|
|
6
|
-
require_relative "../data/
|
|
7
|
-
require_relative "../data/audit_files"
|
|
8
|
-
require_relative "../data/principles_subfolder"
|
|
6
|
+
require_relative "../data/principles_store"
|
|
9
7
|
require_relative "../data/repository"
|
|
8
|
+
require_relative "../data/claude_code_home"
|
|
10
9
|
require_relative "candidate_inventory"
|
|
11
10
|
require_relative "entry_files"
|
|
12
11
|
require_relative "member"
|
|
@@ -18,7 +17,6 @@ require_relative "member_loads"
|
|
|
18
17
|
require_relative "member_lines"
|
|
19
18
|
require_relative "mapped_principles"
|
|
20
19
|
require_relative "member_snapshots"
|
|
21
|
-
require_relative "missing_files"
|
|
22
20
|
require_relative "locate_refusal"
|
|
23
21
|
require_relative "audit_records"
|
|
24
22
|
require_relative "project_history"
|
|
@@ -26,15 +24,18 @@ require_relative "principle_history"
|
|
|
26
24
|
require_relative "principles_folder_move"
|
|
27
25
|
require_relative "sent_answer"
|
|
28
26
|
require_relative "guidance_search_paths"
|
|
27
|
+
require_relative "request_logging"
|
|
29
28
|
require_relative "survey_search_paths"
|
|
29
|
+
require_relative "installed_plugins"
|
|
30
|
+
require_relative "plugin_reference"
|
|
30
31
|
|
|
31
32
|
module Principles
|
|
32
33
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
33
34
|
module Models
|
|
34
35
|
# The user's project as this tool reads it: its instruction files, each member's text, the answers an
|
|
35
36
|
# agent hands in, and the maps, audit records and git history kept beside them. Controllers reach the
|
|
36
|
-
# project only through this model. It is handed its
|
|
37
|
-
# that meet the same contracts.
|
|
37
|
+
# project only through this model. It is handed its data adapters, this tool's own files under .principles as
|
|
38
|
+
# one store, so a spec can hand it stand-ins that meet the same contracts.
|
|
38
39
|
class Project
|
|
39
40
|
# An implicit invocation reuses its nearest established project; an explicit root uses .at directly.
|
|
40
41
|
#: (String) -> Project
|
|
@@ -44,20 +45,20 @@ module Principles
|
|
|
44
45
|
#: (String) -> Project
|
|
45
46
|
def self.at(root)
|
|
46
47
|
files = Data::ProjectFiles.new(root)
|
|
47
|
-
new(files: files,
|
|
48
|
-
|
|
49
|
-
repository: Data::Repository.new(files.root),
|
|
50
|
-
guidance_search_paths: Data::GuidanceSearchPathsFile.new(Data::PrinciplesDirectory.new(files.root)))
|
|
48
|
+
new(files: files, store: Data::PrinciplesStore.at(files.root), repository: Data::Repository.new(files.root),
|
|
49
|
+
claude_code: Data::ClaudeCodeHome.from_environment)
|
|
51
50
|
end
|
|
52
51
|
|
|
53
|
-
#: (files: Data::ProjectFiles,
|
|
54
|
-
#|
|
|
55
|
-
def initialize(files:,
|
|
52
|
+
#: (files: Data::ProjectFiles, store: Data::PrinciplesStore, repository: Data::Repository,
|
|
53
|
+
#| claude_code: Data::ClaudeCodeHome) -> void
|
|
54
|
+
def initialize(files:, store:, repository:, claude_code:)
|
|
56
55
|
@files = files
|
|
57
|
-
@maps = maps
|
|
58
|
-
@audits = audits
|
|
56
|
+
@maps = store.maps #: Data::MapFiles
|
|
57
|
+
@audits = store.audits #: Data::AuditFiles
|
|
59
58
|
@repository = repository
|
|
60
|
-
@guidance_search_paths = guidance_search_paths
|
|
59
|
+
@guidance_search_paths = store.guidance_search_paths #: Data::GuidanceSearchPathsFile
|
|
60
|
+
@request_logging = store.request_logging #: Data::RequestLoggingFolder
|
|
61
|
+
@claude_code = claude_code
|
|
61
62
|
@history = nil #: ProjectHistory?
|
|
62
63
|
@principle_histories = {} #: Hash[[String, PrincipleMappingHistory?], PrincipleHistory]
|
|
63
64
|
end
|
|
@@ -86,9 +87,13 @@ module Principles
|
|
|
86
87
|
GuidanceSearchPaths.read(@guidance_search_paths)
|
|
87
88
|
end
|
|
88
89
|
|
|
89
|
-
# The
|
|
90
|
-
#: () ->
|
|
91
|
-
def
|
|
90
|
+
# The requests the host sent, captured into a folder git must ignore.
|
|
91
|
+
#: () -> RequestLogging
|
|
92
|
+
def request_logging = RequestLogging.new(@request_logging, @files)
|
|
93
|
+
|
|
94
|
+
# The plugins Claude Code installed that a session in the project loads, as installed for its main checkout.
|
|
95
|
+
#: () -> InstalledPlugins
|
|
96
|
+
def installed_plugins = InstalledPlugins.new(@claude_code, main_checkout: @repository.main_checkout_root)
|
|
92
97
|
|
|
93
98
|
# The project's history, one for the whole command, so every read names the HEAD it first read.
|
|
94
99
|
#: () -> ProjectHistory
|
|
@@ -148,10 +153,13 @@ module Principles
|
|
|
148
153
|
member_lines(locator, since: since) || MemberLinesNotFoundAtLastAudit.new
|
|
149
154
|
end
|
|
150
155
|
|
|
151
|
-
# The
|
|
152
|
-
# tracks it only in another case.
|
|
156
|
+
# The file at path as the type that finds a member in it: an installed plugin's file, as InstalledPlugins
|
|
157
|
+
# refuses it, or the project's, refused when it cannot be read, or while git tracks it only in another case.
|
|
153
158
|
#: (String) -> MemberFile
|
|
154
159
|
def member_file(path)
|
|
160
|
+
plugin = PluginReference.in(path)
|
|
161
|
+
return installed_plugins.member_file(plugin) if plugin
|
|
162
|
+
|
|
155
163
|
MemberFile.for(path: history.tracked_paths.spelt_as_tracked(path), text: @files.read_text(path))
|
|
156
164
|
end
|
|
157
165
|
|
|
@@ -180,21 +188,19 @@ module Principles
|
|
|
180
188
|
end
|
|
181
189
|
end
|
|
182
190
|
|
|
183
|
-
#: (String, Array[Hash[String, untyped]]) -> bot
|
|
184
|
-
def refuse_broken(map_id, broken)
|
|
185
|
-
ids = broken.map { |member| member.fetch("id") }.join(", ")
|
|
186
|
-
missing = MissingFiles.new(broken, principle: map_id, history: history)
|
|
187
|
-
raise missing.refusal("#{broken.length} of #{map_id}'s members cannot be found or read: #{ids}")
|
|
188
|
-
end
|
|
189
|
-
|
|
190
191
|
# A member's text now and how fresh it is, which the block says from its hash. A member whose place
|
|
191
192
|
# in its file is gone is locator_lost; one whose file cannot be read is unavailable. Both keep the
|
|
192
|
-
# refusal.
|
|
193
|
+
# refusal. A plugin member no installed plugin gives, for any reason, is plugin_unresolved with that reason, a
|
|
194
|
+
# quiet state and not a broken one, as list-member-problems lists it, so nothing offers to move or remove it.
|
|
193
195
|
#: (Locator) { (String) -> String } -> Hash[String, untyped]
|
|
194
196
|
def freshness(locator, &)
|
|
195
197
|
now = located_text(locator)
|
|
196
198
|
{ "snapshot" => now.to_h, "freshness" => yield(now.sha256) }
|
|
197
199
|
rescue Error => e
|
|
200
|
+
if PluginReference.in(locator.path)
|
|
201
|
+
return { "freshness" => "plugin_unresolved", "reason" => e.payload.fetch("code"), "error" => e.payload }
|
|
202
|
+
end
|
|
203
|
+
|
|
198
204
|
{ "freshness" => LocateRefusal.new(e.payload).member_state, "error" => e.payload }
|
|
199
205
|
end
|
|
200
206
|
|
|
@@ -49,6 +49,19 @@ module Principles
|
|
|
49
49
|
#: (String) -> bool
|
|
50
50
|
def tracks?(path) = !@repository.inside? || @repository.untracked_including_ignored(through_links([path])).empty?
|
|
51
51
|
|
|
52
|
+
# The project's tmp/ folder, by its full path, when it is there and git ignores a file named answer_name in it,
|
|
53
|
+
# so an answer saved there is never committed; nil otherwise, outside git too. Git is asked about the file, not
|
|
54
|
+
# the folder: a project that ignores tmp/'s contents but tracks a file there, as "/tmp/*" does, has git ignore
|
|
55
|
+
# the file but not tmp/. Asked once for the command, and kept for any later answer_name, since an ignore rule
|
|
56
|
+
# for tmp/ does not turn on one answer file's name.
|
|
57
|
+
#: (String) -> String?
|
|
58
|
+
def ignored_tmp_folder(answer_name)
|
|
59
|
+
return @ignored_tmp_folder if defined?(@ignored_tmp_folder)
|
|
60
|
+
|
|
61
|
+
ignored = @files.folder?("tmp") && @repository.ignores?("tmp/#{answer_name}")
|
|
62
|
+
@ignored_tmp_folder = ("#{@files.root}/tmp" if ignored) #: String?
|
|
63
|
+
end
|
|
64
|
+
|
|
52
65
|
# Whether the project is in git, so it has a history at all.
|
|
53
66
|
#: () -> bool
|
|
54
67
|
def inside_git? = @repository.inside?
|
|
@@ -103,6 +116,11 @@ module Principles
|
|
|
103
116
|
#: (String) -> ProjectAtCommit
|
|
104
117
|
def at(commit) = ProjectAtCommit.new(@repository, @files, commit)
|
|
105
118
|
|
|
119
|
+
# Each of paths that a local branch's commits not on HEAD bring in, with the branches that do: where a member's
|
|
120
|
+
# file may be waiting to merge. None outside git.
|
|
121
|
+
#: (Array[String]) -> Hash[String, Array[String]]
|
|
122
|
+
def branches_bringing_in(paths) = @repository.inside? ? @repository.branches_bringing_in(paths) : {}
|
|
123
|
+
|
|
106
124
|
# The rename git detects for path, a file absent from the working tree, as {"to", "similarity",
|
|
107
125
|
# "deleted_in"}: the last commit that touched path, or nil while the move is not yet committed. It is
|
|
108
126
|
# git's similarity match, which can pair a deleted file with an unrelated similar one, so the agent checks
|
|
@@ -151,6 +169,11 @@ module Principles
|
|
|
151
169
|
@repository.commits_touching(through_links(paths), since: since, up_to: head || "HEAD")
|
|
152
170
|
end
|
|
153
171
|
|
|
172
|
+
# The newest commit on at's first-parent line that changed any of paths, a link on the way to one or the file they
|
|
173
|
+
# lead to; nil when none did.
|
|
174
|
+
#: (Array[String], at: String) -> String?
|
|
175
|
+
def last_change(paths, at:) = @repository.last_change(through_links(paths), at: at)
|
|
176
|
+
|
|
154
177
|
# Reads the commits on head's first-parent line touching each of path_sets, and the links and files they lead
|
|
155
178
|
# through, in one git log, so commits_touching asks git no more for any of them. Nothing outside git.
|
|
156
179
|
#: (Array[Array[String]]) -> void
|
|
@@ -51,6 +51,13 @@ module Principles
|
|
|
51
51
|
waiting:)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
# The hash the record assessed for each plugin member of members, by id, which no commit holds; a member it
|
|
55
|
+
# assessed no hash for is left out.
|
|
56
|
+
#: (PrincipleMembers) -> Hash[String, String]
|
|
57
|
+
def plugin_hashes(members)
|
|
58
|
+
members.select(&:plugin_reference).to_h { [it.id, hash_for(it.key)] }.compact
|
|
59
|
+
end
|
|
60
|
+
|
|
54
61
|
# The hash the record assessed for the member known by key, or nil when it assessed no such member.
|
|
55
62
|
#: (String) -> String?
|
|
56
63
|
def hash_for(key)
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../data/request_logging_folder"
|
|
6
|
+
require_relative "../data/project_files"
|
|
7
|
+
require_relative "captured_sessions"
|
|
8
|
+
require_relative "logged_request_scan_completeness"
|
|
9
|
+
require_relative "logged_request_reach"
|
|
10
|
+
require_relative "member_reach"
|
|
11
|
+
require_relative "kept_sessions"
|
|
12
|
+
require_relative "members_in_logged_requests"
|
|
13
|
+
|
|
14
|
+
module Principles
|
|
15
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
16
|
+
module Models
|
|
17
|
+
# The project's logged requests: each request the host sends, written into a folder git must ignore, since a
|
|
18
|
+
# request holds the session's whole working context. Each command here checks first that git ignores the folder
|
|
19
|
+
# and every file in it, and refuses otherwise; this is the one guard they share.
|
|
20
|
+
class RequestLogging
|
|
21
|
+
FOLDER = Data::RequestLoggingFolder
|
|
22
|
+
IGNORE_EVERYTHING = "*\n"
|
|
23
|
+
# The paths each command checks git ignores, beside every file already in the folder.
|
|
24
|
+
GUARDED = [FOLDER::IGNORE, FOLDER::SETTINGS, "#{FOLDER::REQUESTS}/"].freeze #: Array[String]
|
|
25
|
+
|
|
26
|
+
#: (Data::RequestLoggingFolder, Data::ProjectFiles) -> void
|
|
27
|
+
def initialize(folder, files)
|
|
28
|
+
@folder = folder
|
|
29
|
+
@files = files
|
|
30
|
+
freeze
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Writes the .gitignore that has git ignore the folder, and once git confirms it does, the launch file that
|
|
34
|
+
# switches capture on, and gives the paths it wrote; when git does not ignore it, removes what it wrote and
|
|
35
|
+
# refuses.
|
|
36
|
+
#: () -> Array[String]
|
|
37
|
+
def turn_on
|
|
38
|
+
created = !@folder.exist?
|
|
39
|
+
written = @folder.files.include?(FOLDER::IGNORE) ? [] : [FOLDER::IGNORE]
|
|
40
|
+
written.each { |name| @folder.write(name, IGNORE_EVERYTHING) }
|
|
41
|
+
refuse_unignored(written, created)
|
|
42
|
+
@folder.write_settings("env" => capturing)
|
|
43
|
+
[*written, FOLDER::SETTINGS].map { |name| @folder.relative(name) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The launch file, by its absolute path, as the host is started with it.
|
|
47
|
+
#: () -> String
|
|
48
|
+
def launch_file = @folder.absolute(FOLDER::SETTINGS)
|
|
49
|
+
|
|
50
|
+
# Empties the launch file's env, so a launch with it captures nothing, and gives the paths it wrote: none where
|
|
51
|
+
# request logging was never turned on. Every logged request stays.
|
|
52
|
+
#: () -> Array[String]
|
|
53
|
+
def turn_off
|
|
54
|
+
refuse_while_unguarded
|
|
55
|
+
return [] unless @folder.files.include?(FOLDER::SETTINGS)
|
|
56
|
+
|
|
57
|
+
@folder.write_settings("env" => {})
|
|
58
|
+
[@folder.relative(FOLDER::SETTINGS)]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Whether no request is captured, so nothing shows which members reach the context: the folder is not there, or
|
|
62
|
+
# holds no request yet. Refuses while the folder is unguarded.
|
|
63
|
+
#: () -> bool
|
|
64
|
+
def none_captured? = !@folder.exist? || captured.none?
|
|
65
|
+
|
|
66
|
+
# Whether request logging is in use here: its folder is, turned on or holding requests kept from before.
|
|
67
|
+
#: () -> bool
|
|
68
|
+
def in_use? = @folder.exist?
|
|
69
|
+
|
|
70
|
+
# What the host captured, once the guard passes.
|
|
71
|
+
#: () -> CapturedSessions
|
|
72
|
+
def captured
|
|
73
|
+
refuse_while_unguarded
|
|
74
|
+
CapturedSessions.new(@folder.captured_files, @folder.index_lines)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Removes the host's files of every session but the newest keep_sessions, 5 unless given, and gives the paths it
|
|
78
|
+
# removed. Refuses while the folder is unguarded, and a count that is not a whole number, before removing any.
|
|
79
|
+
#: (keep_sessions: String?) -> Array[String]
|
|
80
|
+
def remove(keep_sessions:)
|
|
81
|
+
refuse_while_unguarded
|
|
82
|
+
names = captured.older_than_newest(KeptSessions.new(keep_sessions).count)
|
|
83
|
+
names.each { |name| @folder.remove_request(name) }
|
|
84
|
+
names.map { |name| @folder.relative("#{Data::RequestLoggingFolder::REQUESTS}/#{name}") }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Refuses while the folder exists unguarded: its .gitignore gone, or git not ignoring every path there. Every
|
|
88
|
+
# read of the folder asks this first, since a logged request git does not ignore can be committed.
|
|
89
|
+
#: () -> void
|
|
90
|
+
def refuse_while_unguarded
|
|
91
|
+
refusal = unguarded_refusal
|
|
92
|
+
raise refusal if refusal
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The refusal every read of the folder gives while it exists unguarded, or nil while git ignores it or it is
|
|
96
|
+
# not there; for a read that carries on without the logged requests, such as a full audit's request.
|
|
97
|
+
#: () -> Error?
|
|
98
|
+
def unguarded_refusal
|
|
99
|
+
return unless @folder.exist?
|
|
100
|
+
return unguarded unless @folder.files.include?(FOLDER::IGNORE)
|
|
101
|
+
|
|
102
|
+
not_ignored unless ignored?
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Where each of members' text was seen in the captured requests, scanned by jq and rg, once the folder is
|
|
106
|
+
# guarded.
|
|
107
|
+
# Each request that is not whole JSON is named under unreadable, with its reason, since what it held is unknown,
|
|
108
|
+
# and completeness says how many requests and strings the scan read, and whether it read every request through.
|
|
109
|
+
#: (MembersInLoggedRequests)
|
|
110
|
+
#| -> { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
|
|
111
|
+
#| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
|
|
112
|
+
#| completeness: Hash[String, untyped] }
|
|
113
|
+
def members_seen(members) = scanned(members).first
|
|
114
|
+
|
|
115
|
+
# The report members_seen gives, but each member's reach in place of its places, as MemberReach lists it, so
|
|
116
|
+
# the report is bounded by the members mapped rather than growing with every request that holds them.
|
|
117
|
+
#: (MembersInLoggedRequests)
|
|
118
|
+
#| -> { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
|
|
119
|
+
#| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
|
|
120
|
+
#| completeness: Hash[String, untyped] }
|
|
121
|
+
def members_reached(members)
|
|
122
|
+
seen = members_seen(members)
|
|
123
|
+
seen.merge(members: seen[:members].map { MemberReach.new(it).listed })
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# How far each of members' text reached the captured requests, compactly, from one scan, once the folder is
|
|
127
|
+
# guarded; carried names the members an audit carries forward.
|
|
128
|
+
#: (MembersInLoggedRequests, ?carried: Array[String]) -> LoggedRequestReach
|
|
129
|
+
def reach(members, carried: [])
|
|
130
|
+
seen, read_whole = scanned(members)
|
|
131
|
+
LoggedRequestReach.new(seen[:members], scanned: read_whole, unreadable: seen[:unreadable].size, carried:)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
# Where each of members' text was seen, as members_seen gives it, and how many requests the scan read whole.
|
|
137
|
+
#: (MembersInLoggedRequests)
|
|
138
|
+
#| -> [{ members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
|
|
139
|
+
#| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
|
|
140
|
+
#| completeness: Hash[String, untyped] }, Integer]
|
|
141
|
+
def scanned(members)
|
|
142
|
+
refuse_while_unguarded
|
|
143
|
+
scan = @folder.scan
|
|
144
|
+
requests = scan.requests
|
|
145
|
+
matched = scan.matches(members.patterns)
|
|
146
|
+
read = LoggedRequestScanCompleteness.of(scan, matched)
|
|
147
|
+
report = members.report(requests, matched.found, scan.deferred_tools)
|
|
148
|
+
[{ **report, unreadable: read.unreadable, completeness: read.to_h }, requests.size - read.unreadable.size]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# What has the host write each request's body to the folder: telemetry on, so it logs request bodies, with no
|
|
152
|
+
# exporter, so nothing leaves the machine.
|
|
153
|
+
#: () -> Hash[String, String]
|
|
154
|
+
def capturing
|
|
155
|
+
{ "CLAUDE_CODE_ENABLE_TELEMETRY" => "1", "OTEL_METRICS_EXPORTER" => "none", "OTEL_LOGS_EXPORTER" => "none",
|
|
156
|
+
"OTEL_TRACES_EXPORTER" => "none", "OTEL_LOG_RAW_API_BODIES" => "file:#{@folder.absolute(FOLDER::REQUESTS)}" }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
#: (Array[String], bool) -> void
|
|
160
|
+
def refuse_unignored(written, created)
|
|
161
|
+
return if ignored?
|
|
162
|
+
|
|
163
|
+
written.each { |name| @folder.remove(name) }
|
|
164
|
+
@folder.remove_if_empty if created
|
|
165
|
+
raise not_ignored
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Whether git confirms it ignores the folder's own paths and every file already in it.
|
|
169
|
+
#: () -> bool
|
|
170
|
+
def ignored?
|
|
171
|
+
paths = (GUARDED | @folder.files).map { |name| @folder.relative(name) }
|
|
172
|
+
ignored = @files.ignored_paths(paths)
|
|
173
|
+
!ignored.nil? && (paths - ignored).empty?
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
#: () -> Error
|
|
177
|
+
def unguarded
|
|
178
|
+
Error.new("request_logging_unguarded",
|
|
179
|
+
"#{@folder.relative(FOLDER::IGNORE)} is missing, so git may not ignore the logged requests beside it",
|
|
180
|
+
"A logged request holds the session's whole working context, so it must never reach git. Restore " \
|
|
181
|
+
"#{@folder.relative(FOLDER::IGNORE)} holding the one line *, then run this again.")
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
#: () -> Error
|
|
185
|
+
def not_ignored
|
|
186
|
+
Error.new("request_logging_not_ignored",
|
|
187
|
+
"git does not confirm that it ignores #{FOLDER::FOLDER}/, so logged requests there could be " \
|
|
188
|
+
"committed",
|
|
189
|
+
"A logged request holds the session's whole working context, so it must never reach git. Make this " \
|
|
190
|
+
"project a git repository with git init if it is not one. If git tracks a file under " \
|
|
191
|
+
"#{FOLDER::FOLDER}/, stop tracking it with git rm -r --cached #{FOLDER::FOLDER}. Then run this " \
|
|
192
|
+
"command again.")
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
@@ -27,11 +27,6 @@ module Principles
|
|
|
27
27
|
#: () -> bool
|
|
28
28
|
def session_start_hook_in_this_session? = plugin?
|
|
29
29
|
|
|
30
|
-
# Whether the principles skill, /principles, is installed for the session this run is part of, which only the
|
|
31
|
-
# plugin installs; an installed gem or a checkout has none.
|
|
32
|
-
#: () -> bool
|
|
33
|
-
def principles_skill_in_this_session? = plugin?
|
|
34
|
-
|
|
35
30
|
private
|
|
36
31
|
|
|
37
32
|
#: () -> bool
|