principles 0.0.4 → 0.0.6
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/lib/principles/after_commit_hook_options.rb +4 -1
- data/lib/principles/cli.rb +3 -1
- data/lib/principles/command_line.rb +38 -26
- data/lib/principles/command_routes.rb +11 -4
- data/lib/principles/controllers/acknowledgement.rb +93 -17
- data/lib/principles/controllers/answer.rb +45 -76
- data/lib/principles/controllers/answer_phase.rb +54 -0
- data/lib/principles/controllers/assessment.rb +46 -11
- data/lib/principles/controllers/audit.rb +17 -6
- data/lib/principles/controllers/audit_completion.rb +9 -5
- data/lib/principles/controllers/command.rb +5 -4
- data/lib/principles/controllers/correction.rb +22 -10
- data/lib/principles/controllers/full_audit_request.rb +11 -1
- data/lib/principles/controllers/guidance_search_paths.rb +31 -0
- data/lib/principles/controllers/inventory.rb +15 -29
- data/lib/principles/controllers/mapping.rb +9 -1
- data/lib/principles/controllers/member_addition.rb +65 -0
- data/lib/principles/controllers/member_entries.rb +6 -24
- data/lib/principles/controllers/member_problems_report.rb +13 -6
- data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
- data/lib/principles/controllers/members_to_assess.rb +21 -13
- data/lib/principles/controllers/meta_principle_setup.rb +1 -1
- data/lib/principles/controllers/repoint.rb +22 -23
- data/lib/principles/controllers/survey.rb +60 -0
- data/lib/principles/data/audit_files.rb +4 -0
- data/lib/principles/data/bounded_file.rb +9 -4
- data/lib/principles/data/candidate_files_found.rb +48 -13
- data/lib/principles/data/command-steps.json +85 -24
- data/lib/principles/data/committed_tree.rb +84 -0
- data/lib/principles/data/first_parent_log.rb +48 -0
- data/lib/principles/data/first_parent_range.rb +122 -0
- data/lib/principles/data/git_command.rb +37 -0
- data/lib/principles/data/guidance_search_paths_file.rb +107 -0
- data/lib/principles/data/map_files.rb +35 -10
- data/lib/principles/data/principles_directory.rb +40 -0
- data/lib/principles/data/principles_subfolder.rb +39 -16
- data/lib/principles/data/project_files.rb +22 -11
- data/lib/principles/data/repository.rb +55 -29
- data/lib/principles/data/requested_candidate_files.rb +43 -0
- data/lib/principles/data/running_version.rb +3 -5
- data/lib/principles/data/schema_check.rb +16 -6
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +18 -5
- data/lib/principles/data/schemas/answer-guide.schema.json +255 -68
- data/lib/principles/data/schemas/audit-record.schema.json +10 -1
- data/lib/principles/data/schemas/command-steps.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
- data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
- data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
- data/lib/principles/data/verified_head.rb +162 -0
- data/lib/principles/invocation_options.rb +3 -3
- data/lib/principles/models/acknowledgement.rb +95 -84
- data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
- data/lib/principles/models/acknowledgement_refusal.rb +90 -0
- data/lib/principles/models/answer_place.rb +4 -0
- data/lib/principles/models/assessment_answer.rb +0 -45
- data/lib/principles/models/assessment_left_as_printed.rb +81 -0
- data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
- data/lib/principles/models/audit_record.rb +12 -16
- data/lib/principles/models/audit_records.rb +52 -23
- data/lib/principles/models/candidate_files.rb +44 -10
- data/lib/principles/models/candidate_inventory.rb +69 -8
- data/lib/principles/models/candidate_outline.rb +195 -0
- data/lib/principles/models/captured_head.rb +72 -0
- data/lib/principles/models/carried_member.rb +42 -0
- data/lib/principles/models/check_since_last_audit.rb +20 -11
- data/lib/principles/models/command_steps.rb +17 -1
- data/lib/principles/models/declared_map_changes.rb +29 -12
- data/lib/principles/models/declared_member_removals.rb +75 -0
- data/lib/principles/models/disposition.rb +4 -2
- data/lib/principles/models/fix_only_fields.rb +12 -0
- data/lib/principles/models/frontmatter_fields.rb +9 -8
- data/lib/principles/models/guidance_search_path.rb +26 -0
- data/lib/principles/models/guidance_search_paths.rb +57 -0
- data/lib/principles/models/instruction_named.rb +35 -0
- data/lib/principles/models/left_as_printed.rb +39 -0
- data/lib/principles/models/line_span.rb +6 -0
- data/lib/principles/models/loaded_files.rb +1 -2
- data/lib/principles/models/loading_scope.rb +61 -0
- data/lib/principles/models/locator.rb +6 -0
- data/lib/principles/models/mapped_principles.rb +39 -37
- data/lib/principles/models/member_assessments.rb +9 -31
- data/lib/principles/models/member_file.rb +20 -47
- data/lib/principles/models/member_hashes_as_written.rb +10 -6
- data/lib/principles/models/member_history.rb +7 -5
- data/lib/principles/models/member_lines.rb +63 -15
- data/lib/principles/models/member_loading_scopes.rb +49 -0
- data/lib/principles/models/member_loads.rb +4 -0
- data/lib/principles/models/member_mapping_run.rb +30 -0
- data/lib/principles/models/member_moves.rb +4 -0
- data/lib/principles/models/member_problems.rb +63 -33
- data/lib/principles/models/member_region.rb +129 -0
- data/lib/principles/models/member_repair_moves.rb +52 -0
- data/lib/principles/models/member_snapshots.rb +14 -1
- data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
- data/lib/principles/models/meta_principle.rb +14 -0
- data/lib/principles/models/missing_files.rb +2 -2
- data/lib/principles/models/open_findings_elsewhere.rb +4 -0
- data/lib/principles/models/other_templates_placeholders.rb +81 -42
- data/lib/principles/models/outline_budget.rb +142 -0
- data/lib/principles/models/outline_group.rb +31 -0
- data/lib/principles/models/outline_section.rb +56 -0
- data/lib/principles/models/principle.rb +14 -7
- data/lib/principles/models/principle_file_revision.rb +48 -0
- data/lib/principles/models/principle_history.rb +46 -19
- data/lib/principles/models/principle_lineage.rb +118 -0
- data/lib/principles/models/principle_map_revision.rb +39 -0
- data/lib/principles/models/principle_mapping_history.rb +132 -0
- data/lib/principles/models/principle_members.rb +25 -0
- data/lib/principles/models/principle_predecessor.rb +45 -0
- data/lib/principles/models/principle_publication.rb +177 -0
- data/lib/principles/models/principle_revision.rb +104 -0
- data/lib/principles/models/prior_decision_fields.rb +3 -2
- data/lib/principles/models/prior_finding_decision.rb +14 -4
- data/lib/principles/models/problem_report.rb +17 -5
- data/lib/principles/models/project.rb +46 -39
- data/lib/principles/models/project_history.rb +45 -25
- data/lib/principles/models/quoted_change.rb +137 -0
- data/lib/principles/models/record_format.rb +12 -2
- data/lib/principles/models/recorded_entry.rb +6 -0
- data/lib/principles/models/recorded_hashes.rb +7 -3
- data/lib/principles/models/recorded_members.rb +27 -15
- data/lib/principles/models/refusal_before_shape.rb +21 -0
- data/lib/principles/models/repoint.rb +13 -0
- data/lib/principles/models/reported_check.rb +5 -14
- data/lib/principles/models/sent_answer.rb +61 -0
- data/lib/principles/models/shape_problems_beside.rb +40 -0
- data/lib/principles/models/submitted_answer.rb +34 -0
- data/lib/principles/models/survey_search_paths.rb +26 -0
- data/lib/principles/models/template_placeholders.rb +34 -4
- data/lib/principles/models/text_within.rb +55 -0
- data/lib/principles/models/unchecked_members.rb +76 -0
- data/lib/principles/models/uncommitted_files.rb +50 -0
- data/lib/principles/models/unknown_principle.rb +29 -0
- data/lib/principles/models/write_up_opening.rb +21 -4
- data/lib/principles/positional_arguments.rb +37 -0
- data/lib/principles/session_start_options.rb +2 -2
- data/lib/principles/start_audit_options.rb +19 -4
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +23 -11
- data/lib/principles/views/added_member.rb +41 -0
- data/lib/principles/views/answered_request.rb +21 -0
- data/lib/principles/views/assessed_members.rb +43 -10
- data/lib/principles/views/assessment_request.rb +91 -31
- data/lib/principles/views/audit_result.rb +40 -28
- data/lib/principles/views/candidate_files_result.rb +85 -19
- data/lib/principles/views/candidate_outlines_result.rb +25 -0
- data/lib/principles/views/check_notes.rb +44 -0
- data/lib/principles/views/check_result_template.rb +14 -23
- data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
- data/lib/principles/views/correction_request.rb +32 -1
- data/lib/principles/views/guidance_search_paths_result.rb +26 -0
- data/lib/principles/views/instruction.rb +74 -0
- data/lib/principles/views/json_with_entries_on_lines.rb +59 -0
- data/lib/principles/views/loads_to_check_result.rb +2 -2
- data/lib/principles/views/map_added_to.rb +56 -2
- data/lib/principles/views/map_result.rb +23 -43
- data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
- data/lib/principles/views/member_change_since_baseline.rb +23 -5
- data/lib/principles/views/member_repairs.rb +22 -52
- data/lib/principles/views/members_a_commit_changed.rb +16 -6
- data/lib/principles/views/new_loading_scope.rb +31 -0
- data/lib/principles/views/one_member_check_result_template.rb +47 -0
- data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
- data/lib/principles/views/open_findings_line.rb +77 -23
- data/lib/principles/views/principle_read_result.rb +24 -29
- data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
- data/lib/principles/views/prior_findings_result.rb +23 -15
- data/lib/principles/views/problem_lines.rb +3 -1
- data/lib/principles/views/problem_result.rb +8 -3
- data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
- data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -48
- data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
- data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
- data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
- data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
- data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
- data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -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 +16 -3
- data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +11 -5
- data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
- data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +55 -7
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +9 -8
- 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/list-principles.md +1 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +27 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
- data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
- data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
- data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
- data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
- data/lib/principles/views/request_part.rb +16 -8
- data/lib/principles/views/request_parts.rb +4 -0
- metadata +92 -7
- data/lib/principles/models/candidate_listing.rb +0 -32
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
- data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
- data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "command"
|
|
5
|
+
require_relative "../models/carried_member"
|
|
5
6
|
require_relative "../models/check_since_last_audit"
|
|
6
7
|
require_relative "../models/open_findings_elsewhere"
|
|
7
8
|
require_relative "../views/acknowledged_since_last_audit"
|
|
@@ -38,7 +39,7 @@ module Principles
|
|
|
38
39
|
@principle_id = principle_id
|
|
39
40
|
@record = @audit_records.find(principle_id) #: Models::AuditRecord?
|
|
40
41
|
@completed = @record&.last_completed #: Models::AuditRecord?
|
|
41
|
-
@checks = Models::CheckSinceLastAudit.new(
|
|
42
|
+
@checks = Models::CheckSinceLastAudit.new(principle_history: principle_history(principle_id),
|
|
42
43
|
record: @record) #: Models::CheckSinceLastAudit
|
|
43
44
|
end
|
|
44
45
|
|
|
@@ -65,7 +66,7 @@ module Principles
|
|
|
65
66
|
#| -> Hash[String, untyped]
|
|
66
67
|
def member_listed(fields, carried, elsewhere, current)
|
|
67
68
|
member = Models::Member.new(fields)
|
|
68
|
-
judged = carried(member, carried)
|
|
69
|
+
judged = carried(member, carried, elsewhere)
|
|
69
70
|
located(member, current).merge(checked(member), acknowledged(fields), judged,
|
|
70
71
|
changed_since(fields, judged), shared_lines(member, elsewhere))
|
|
71
72
|
end
|
|
@@ -99,16 +100,25 @@ module Principles
|
|
|
99
100
|
|
|
100
101
|
# The member's last assessment carried forward, with whether any evidence it cited changed since and, in git,
|
|
101
102
|
# whether its file changed since the last full audit's base commit, outside the member, whose own text did not;
|
|
102
|
-
# or why it is judged again. These are facts: the agent may re-judge any carried member (D49).
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
# or why it is judged again. These are facts: the agent may re-judge any carried member (D49). flagged says
|
|
104
|
+
# whether any fires, or another principle leaves a finding open on its lines, so the request prints the member
|
|
105
|
+
# whole rather than compactly (D93).
|
|
106
|
+
#: (Models::Member, Models::CarriedAssessments, Models::OpenFindingsElsewhere) -> Hash[String, untyped]
|
|
107
|
+
def carried(member, carried, elsewhere)
|
|
105
108
|
shown = carried.shown(member.id) { |locator, sha| evidence_changed?(locator, sha) }
|
|
106
|
-
kept = shown["carried_forward"]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
kept = shown["carried_forward"] or return shown
|
|
110
|
+
|
|
111
|
+
Models::CarriedMember.new(kept, file_changed_outside_member: file_changed_outside(member),
|
|
112
|
+
open_elsewhere: elsewhere.open_beside?(member.id),
|
|
113
|
+
open_here: @record&.open_ids_on(member.key) || []).shown
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Whether member's file changed since the last full audit's base commit; nil with no such commit, as outside git.
|
|
117
|
+
#: (Models::Member) -> bool?
|
|
118
|
+
def file_changed_outside(member)
|
|
119
|
+
base = @completed&.base_commit or return
|
|
109
120
|
|
|
110
|
-
|
|
111
|
-
@history.commits_since(base, member.path).any?) }
|
|
121
|
+
@history.commits_since(base, member.path).any?
|
|
112
122
|
end
|
|
113
123
|
|
|
114
124
|
# Whether the evidence at locator no longer hashes to sha, or can no longer be found.
|
|
@@ -157,10 +167,8 @@ module Principles
|
|
|
157
167
|
|
|
158
168
|
#: (Models::Member) -> Hash[String, untyped]
|
|
159
169
|
def checked(member)
|
|
160
|
-
check = member.check or return {}
|
|
161
170
|
hidden = member.check_hidden_characters
|
|
162
|
-
{
|
|
163
|
-
.merge(hidden.empty? ? {} : { "check_hidden_characters" => hidden })
|
|
171
|
+
@checks.entry(member).merge(hidden.empty? ? {} : { "check_hidden_characters" => hidden })
|
|
164
172
|
end
|
|
165
173
|
end
|
|
166
174
|
end
|
|
@@ -43,7 +43,7 @@ module Principles
|
|
|
43
43
|
#: (Models::Principle) -> Views::MetaPrincipleResult::MapInProject
|
|
44
44
|
def map_in_project(map)
|
|
45
45
|
Views::MetaPrincipleResult::MapInProject.new(
|
|
46
|
-
already_mapped: @principles.mapped?(map.id), members_in_entry_files: map.members_in(Models::EntryFiles::PATHS),
|
|
46
|
+
already_mapped: @principles.mapped?(map.id), members_in_entry_files: map.members.members_in(Models::EntryFiles::PATHS),
|
|
47
47
|
set_up: @principles.set_up?
|
|
48
48
|
)
|
|
49
49
|
end
|
|
@@ -2,45 +2,53 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "time"
|
|
5
|
-
require_relative "
|
|
5
|
+
require_relative "answer_phase"
|
|
6
6
|
require_relative "../models/finding_write_ups"
|
|
7
|
-
require_relative "../models/last_completed_revision"
|
|
8
7
|
require_relative "../models/repoint"
|
|
9
8
|
require_relative "../views/repoint_result"
|
|
10
9
|
|
|
10
|
+
require_relative "../views/answered_request"
|
|
11
|
+
|
|
11
12
|
module Principles
|
|
12
13
|
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
13
14
|
# controllers/CLAUDE.md owns the boundary.
|
|
14
15
|
module Controllers
|
|
15
16
|
# A repoint of a principle's open findings' write-ups (D59): start-audit ID --write-ups lists each open finding
|
|
16
17
|
# with where its write-up is now, and submit-answer points the recorded_at the agent gives in the audit record.
|
|
17
|
-
class Repoint <
|
|
18
|
+
class Repoint < AnswerPhase
|
|
18
19
|
# The request for principle id's open findings.
|
|
19
20
|
#: (String) -> Hash[String, untyped]
|
|
20
21
|
def start(id)
|
|
21
22
|
naming_the_executable do
|
|
22
23
|
record = @audit_records.find(id)
|
|
23
|
-
repoint =
|
|
24
|
+
repoint = repoint_of(id, record)
|
|
24
25
|
findings = Models::FindingWriteUps.of(@project, [record].compact).listed
|
|
25
26
|
view.request(request_id: repoint.request_id.to_s, principle_id: id, revision: repoint.revision,
|
|
26
27
|
findings: findings).merge("wrote" => [])
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
# The result of answering
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
changes =
|
|
39
|
-
|
|
31
|
+
# The result of answering, and the record it changes, not yet written, which the repoint refuses once the last
|
|
32
|
+
# completed record changed after the request was printed, unless it writes nothing.
|
|
33
|
+
# @override
|
|
34
|
+
#: (Models::SubmittedAnswer) -> [Views::AnsweredRequest, Array[Models::AuditRecord]]
|
|
35
|
+
def answered(submitted)
|
|
36
|
+
id = submitted.request_id.principle_id
|
|
37
|
+
response = submitted.response
|
|
38
|
+
repoint = repoint_of(id, @audit_records.find(id))
|
|
39
|
+
repointed, changes = repoint.writable(response, records: @audit_records, at: Time.now.utc.iso8601) do |locator|
|
|
40
|
+
snapshot(locator)
|
|
41
|
+
end
|
|
42
|
+
[Views::AnsweredRequest.new(view.repointed(principle_id: id, file: @audit_records.file(id),
|
|
43
|
+
outcome: outcome(repoint, repointed))), changes]
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
private
|
|
43
47
|
|
|
48
|
+
# The repoint of principle id's open findings, as its record holds them.
|
|
49
|
+
#: (String, Models::AuditRecord?) -> Models::Repoint
|
|
50
|
+
def repoint_of(id, record) = Models::Repoint.new(principle_id: id, record: record, history: @history)
|
|
51
|
+
|
|
44
52
|
# What the repoint did, and each other principle's open finding whose write-up cannot be found (T16).
|
|
45
53
|
#: (Models::Repoint, Models::AuditRecord) -> Views::RepointResult::Outcome
|
|
46
54
|
def outcome(repoint, repointed)
|
|
@@ -50,15 +58,6 @@ module Principles
|
|
|
50
58
|
not_found_elsewhere: Models::FindingWriteUps.of(@project, others).not_found)
|
|
51
59
|
end
|
|
52
60
|
|
|
53
|
-
# The records repointed changes from record. Refused once record changed after the request, whose revision the
|
|
54
|
-
# answer quotes back, was printed, unless there are none.
|
|
55
|
-
#: (Models::AuditRecord?, Models::AuditRecord, String?) -> Array[Models::AuditRecord]
|
|
56
|
-
def writable_changes(record, repointed, revision)
|
|
57
|
-
changes = @audit_records.changes(repointed)
|
|
58
|
-
Models::LastCompletedRevision.new(revision).confirm_writable(repointed.principle_id, record, changes)
|
|
59
|
-
changes
|
|
60
|
-
end
|
|
61
|
-
|
|
62
61
|
#: () -> Views::RepointResult
|
|
63
62
|
def view
|
|
64
63
|
Views::RepointResult.new(invocation)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "command"
|
|
5
|
+
require_relative "../views/candidate_files_result"
|
|
6
|
+
require_relative "../views/candidate_outlines_result"
|
|
7
|
+
require_relative "../views/json_with_entries_on_lines"
|
|
8
|
+
|
|
9
|
+
module Principles
|
|
10
|
+
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
11
|
+
# controllers/CLAUDE.md owns the boundary.
|
|
12
|
+
module Controllers
|
|
13
|
+
# list-candidate-files: the survey of the files that look like agent guidance, with their outlines within the
|
|
14
|
+
# budget, and the question of which principle they carry. It changes nothing on disk, and changes for the survey's
|
|
15
|
+
# reasons alone, apart from the reads of what is already mapped (#1015).
|
|
16
|
+
class Survey < Command
|
|
17
|
+
#: (String, String?, Hash[String, untyped]) -> untyped
|
|
18
|
+
def call(command, _id, options)
|
|
19
|
+
naming_the_executable do
|
|
20
|
+
case command
|
|
21
|
+
when "list-candidate-files" then list_candidate_files(options)
|
|
22
|
+
when "show-candidate-outlines" then show_candidate_outlines(options.fetch("path"))
|
|
23
|
+
else unknown(command)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
#: (Array[String]) -> Views::JsonWithEntriesOnLines
|
|
31
|
+
def show_candidate_outlines(paths)
|
|
32
|
+
found = @project.candidate_outlines(paths)
|
|
33
|
+
.within_budget { |inventory| Views::CandidateOutlinesResult.new(inventory.to_h).result.text.bytesize }
|
|
34
|
+
Views::CandidateOutlinesResult.new(found.to_h).result
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The survey; with a revision, only once it names a commit in git (#1171).
|
|
38
|
+
#: (Hash[String, untyped]) -> untyped
|
|
39
|
+
def list_candidate_files(options)
|
|
40
|
+
after = options["commits_after"]
|
|
41
|
+
mapped = @principles.descriptions
|
|
42
|
+
commit = @history.commit_named(after) if after
|
|
43
|
+
found = @project.candidate_files(after: commit, also: options.fetch("also", []))
|
|
44
|
+
.within_budget { |inventory| candidate_files_result(inventory, mapped).text.bytesize }
|
|
45
|
+
candidate_files_result(found, mapped)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# list-candidate-files' result for one inventory, as it prints.
|
|
49
|
+
#: (Models::CandidateInventory, Array[Hash[String, untyped]]) -> Views::JsonWithEntriesOnLines
|
|
50
|
+
def candidate_files_result(found, mapped)
|
|
51
|
+
listed = Views::CandidateFilesResult::Found.new(inventory: found.to_h, untracked: found.untracked,
|
|
52
|
+
owner_asks: found.owner_asks)
|
|
53
|
+
question = Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
|
|
54
|
+
map_file: @principles.file("ID"),
|
|
55
|
+
mapped_principles: mapped)
|
|
56
|
+
Views::JsonWithEntriesOnLines.new(question.merge("wrote" => []), under: "inventory", key: "files")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -33,6 +33,10 @@ module Principles
|
|
|
33
33
|
@directory.exist?(id)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Any current entry, including an unreadable record or dangling link, protects a map from removal.
|
|
37
|
+
#: (String) -> bool
|
|
38
|
+
def entry?(id) = @directory.entry?(id, shown_as: relative(id))
|
|
39
|
+
|
|
36
40
|
# The record of id's last audit, or nil when it has none, checked against its schema (D29), handing the block
|
|
37
41
|
# a record the schema refuses, as parse does.
|
|
38
42
|
#: (String) ?{ (untyped) -> void } -> Hash[String, untyped]?
|
|
@@ -12,18 +12,23 @@ module Principles
|
|
|
12
12
|
# Far above any instruction file, map, audit record or answer, and far below what exhausts memory.
|
|
13
13
|
LIMIT = 4 * 1024 * 1024 #: Integer
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
# shown_as is the path a refusal gives; named is what its message calls the file, such as "The answer" for a
|
|
16
|
+
# file the agent named and holds the path of (#1118).
|
|
17
|
+
#: (String, ?shown_as: String, ?named: String) -> void
|
|
18
|
+
def initialize(path, shown_as: path, named: shown_as)
|
|
17
19
|
@path = path
|
|
18
20
|
@shown_as = shown_as
|
|
21
|
+
@named = named
|
|
19
22
|
freeze
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
# The file's text, read once it is known to be a regular file within LIMIT.
|
|
23
26
|
#: (?encoding: String) -> String
|
|
24
27
|
def read(encoding: "UTF-8")
|
|
28
|
+
raise Error.new("unreadable_file", "#{@named} does not exist", "Name a file that exists.", @shown_as) unless
|
|
29
|
+
File.exist?(@path)
|
|
25
30
|
unless File.file?(@path)
|
|
26
|
-
raise Error.new("not_a_file", "#{@
|
|
31
|
+
raise Error.new("not_a_file", "#{@named} is not a regular file", "Name a regular file.", @shown_as)
|
|
27
32
|
end
|
|
28
33
|
|
|
29
34
|
refuse_larger(File.size(@path))
|
|
@@ -47,7 +52,7 @@ module Principles
|
|
|
47
52
|
def refuse_larger(bytes)
|
|
48
53
|
return if bytes <= LIMIT
|
|
49
54
|
|
|
50
|
-
raise Error.new("file_too_large", "#{@
|
|
55
|
+
raise Error.new("file_too_large", "#{@named} holds #{bytes} bytes, more than the #{LIMIT} bytes " \
|
|
51
56
|
"read at most",
|
|
52
57
|
"Name a smaller file, or map a smaller part of it.", @shown_as)
|
|
53
58
|
end
|
|
@@ -15,7 +15,7 @@ module Principles
|
|
|
15
15
|
# Folders the inventory never enters: version control, this tool's own records, and installed packages.
|
|
16
16
|
PRUNED_FOLDERS = %w[.git .principles .memeplex .coord node_modules vendor .bundle].freeze
|
|
17
17
|
|
|
18
|
-
# The instruction files an agent host loads by convention
|
|
18
|
+
# The instruction files an agent host loads by convention, beside any explicitly selected paths.
|
|
19
19
|
CANDIDATE_NAMES = %w[CLAUDE.md AGENTS.md].freeze
|
|
20
20
|
CANDIDATE_PATH = %r{(?:\A|/)\.claude/(?:rules/|skills/|agents/|settings[^/]*\.json\z)}
|
|
21
21
|
|
|
@@ -32,39 +32,73 @@ module Principles
|
|
|
32
32
|
leads_to == path ? entry : entry.merge("symlink_to" => leads_to)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# also names more files to list, inside the project, beside those hosts load by convention.
|
|
36
|
+
#: (ProjectFiles, ?also: Array[String], ?matching: Array[String]) -> void
|
|
37
|
+
def initialize(files, also: [], matching: [])
|
|
37
38
|
@files = files
|
|
39
|
+
@also = also
|
|
40
|
+
@matching = matching
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
#: () -> Hash[String, untyped]
|
|
41
44
|
def to_h
|
|
42
|
-
|
|
45
|
+
walked = candidate_paths
|
|
46
|
+
candidates = walked | @also
|
|
43
47
|
ignored = IgnoredByGit.new(@files.root, candidates).facts
|
|
44
|
-
|
|
45
|
-
entries = entries.sort_by { |entry| entry.fetch("path") }
|
|
46
|
-
listed = { "files" => entries, "unreadable" => skipped,
|
|
47
|
-
"possibly_test_data" => entries.filter_map { |entry| test_data_hint(entry.fetch("path")) } }
|
|
48
|
+
listed = listing(candidates - (ignored&.fetch("ignored") || [])).merge(additional_search_paths(walked))
|
|
48
49
|
ignored ? listed.merge(ignored) : listed
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
private
|
|
52
53
|
|
|
54
|
+
# Explicit matches before ignore/readability filtering; counts of zero remain observable.
|
|
55
|
+
#: (Array[String]) -> Hash[String, untyped]
|
|
56
|
+
def additional_search_paths(paths)
|
|
57
|
+
return { "selected_files" => @also.uniq.sort } if @matching.empty?
|
|
58
|
+
|
|
59
|
+
matches = @matching.to_h { |glob| [glob, paths.select { |path| matches?(glob, path) }] }
|
|
60
|
+
{ "selected_files" => (@also | matches.values.flatten).sort,
|
|
61
|
+
"additional_search_paths" => matches.map do |glob, found|
|
|
62
|
+
{ "glob" => glob, "matched_files" => found.length }
|
|
63
|
+
end }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#: (String, String) -> bool
|
|
67
|
+
def matches?(glob, path)
|
|
68
|
+
File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Readable file entries and per-path refusals, with the test-data hints for readable entries.
|
|
72
|
+
#: (Array[String]) -> Hash[String, untyped]
|
|
73
|
+
def listing(paths)
|
|
74
|
+
entries, skipped = readable(paths)
|
|
75
|
+
entries = entries.sort_by { |entry| entry.fetch("path") }
|
|
76
|
+
{ "files" => entries, "unreadable" => skipped,
|
|
77
|
+
"possibly_test_data" => entries.filter_map { |entry| test_data_hint(entry.fetch("path")) } }
|
|
78
|
+
end
|
|
79
|
+
|
|
53
80
|
# Each candidate's path relative to the root, in the order the walk finds them.
|
|
54
81
|
#: () -> Array[String]
|
|
55
82
|
def candidate_paths
|
|
56
83
|
paths = [] #: Array[String]
|
|
57
84
|
Find.find(@files.root) do |absolute|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
next
|
|
61
|
-
end
|
|
85
|
+
next unless file_in_walk?(absolute)
|
|
86
|
+
|
|
62
87
|
relative = absolute.delete_prefix("#{@files.root}/")
|
|
63
88
|
paths << relative if candidate?(relative)
|
|
64
89
|
end
|
|
65
90
|
paths
|
|
66
91
|
end
|
|
67
92
|
|
|
93
|
+
# Whether this walk visits a file, pruning internal folders and other projects before descending.
|
|
94
|
+
#: (String) -> bool
|
|
95
|
+
def file_in_walk?(absolute)
|
|
96
|
+
return File.basename(absolute) != ".git" unless File.directory?(absolute)
|
|
97
|
+
|
|
98
|
+
Find.prune if PRUNED_FOLDERS.include?(File.basename(absolute)) || nested_repository?(absolute)
|
|
99
|
+
false
|
|
100
|
+
end
|
|
101
|
+
|
|
68
102
|
# A folder below the root holding its own .git, a worktree's file or a clone's folder, is another project,
|
|
69
103
|
# as git treats it (#376). The root may hold one too: this tool runs in a worktree.
|
|
70
104
|
#: (String) -> bool
|
|
@@ -98,7 +132,8 @@ module Principles
|
|
|
98
132
|
|
|
99
133
|
#: (String) -> bool
|
|
100
134
|
def candidate?(relative)
|
|
101
|
-
CANDIDATE_NAMES.include?(File.basename(relative)) || relative.match?(CANDIDATE_PATH)
|
|
135
|
+
CANDIDATE_NAMES.include?(File.basename(relative)) || relative.match?(CANDIDATE_PATH) ||
|
|
136
|
+
@matching.any? { |glob| matches?(glob, relative) }
|
|
102
137
|
end
|
|
103
138
|
end
|
|
104
139
|
end
|