principles 0.0.5 → 0.0.7
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 +9 -0
- data/lib/principles/command_line.rb +31 -30
- data/lib/principles/command_routes.rb +9 -3
- data/lib/principles/controllers/acknowledgement.rb +82 -95
- data/lib/principles/controllers/answer.rb +14 -11
- data/lib/principles/controllers/assessment.rb +27 -24
- data/lib/principles/controllers/audit.rb +24 -4
- data/lib/principles/controllers/audit_completion.rb +10 -4
- data/lib/principles/controllers/command.rb +2 -2
- data/lib/principles/controllers/correction.rb +16 -7
- data/lib/principles/controllers/full_audit_request.rb +8 -3
- data/lib/principles/controllers/guidance_search_paths.rb +31 -0
- data/lib/principles/controllers/inventory.rb +3 -22
- data/lib/principles/controllers/mapping.rb +9 -1
- data/lib/principles/controllers/member_acknowledgement.rb +137 -0
- 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 +33 -25
- data/lib/principles/controllers/members_to_assess.rb +1 -1
- data/lib/principles/controllers/meta_principle_setup.rb +1 -1
- data/lib/principles/controllers/repoint.rb +5 -2
- data/lib/principles/controllers/survey.rb +60 -0
- data/lib/principles/data/audit_files.rb +4 -0
- data/lib/principles/data/candidate_files_found.rb +48 -13
- data/lib/principles/data/command-steps.json +86 -25
- 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 +11 -3
- 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/schemas/acknowledgement-answer.schema.json +6 -6
- data/lib/principles/data/schemas/acknowledgements-answer.schema.json +88 -0
- data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
- data/lib/principles/data/schemas/assessment-answer.schema.json +15 -1
- 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 +12 -54
- 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 +5 -4
- data/lib/principles/list_open_findings_options.rb +23 -0
- data/lib/principles/models/acknowledged_check.rb +94 -0
- data/lib/principles/models/acknowledgement.rb +40 -36
- data/lib/principles/models/acknowledgement_left_as_printed.rb +72 -0
- data/lib/principles/models/acknowledgements.rb +99 -0
- data/lib/principles/models/answered_time.rb +9 -0
- data/lib/principles/models/assessment_report.rb +13 -13
- data/lib/principles/models/audit.rb +17 -4
- data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
- data/lib/principles/models/audit_record.rb +9 -0
- data/lib/principles/models/audit_records.rb +34 -8
- data/lib/principles/models/candidate_files.rb +17 -6
- data/lib/principles/models/candidate_inventory.rb +51 -7
- data/lib/principles/models/captured_head.rb +72 -0
- data/lib/principles/models/check_since_last_audit.rb +4 -8
- data/lib/principles/models/correction_basis.rb +14 -5
- data/lib/principles/models/declared_map_changes.rb +25 -9
- 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/guidance_search_path.rb +26 -0
- data/lib/principles/models/guidance_search_paths.rb +57 -0
- data/lib/principles/models/line_span.rb +6 -0
- data/lib/principles/models/list_member_problems_check.rb +80 -0
- data/lib/principles/models/listed_members.rb +49 -0
- data/lib/principles/models/loaded_files.rb +1 -2
- data/lib/principles/models/loading_decision.rb +17 -8
- data/lib/principles/models/loading_scope.rb +61 -0
- data/lib/principles/models/loads_to_check.rb +0 -1
- data/lib/principles/models/locator.rb +6 -0
- data/lib/principles/models/mapped_principles.rb +39 -37
- data/lib/principles/models/member_assessments.rb +11 -2
- data/lib/principles/models/member_file.rb +20 -71
- data/lib/principles/models/member_history.rb +7 -5
- 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 +57 -29
- data/lib/principles/models/member_region.rb +129 -0
- data/lib/principles/models/member_repair_moves.rb +9 -11
- data/lib/principles/models/member_sighting.rb +5 -8
- 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/other_templates_placeholders.rb +1 -1
- data/lib/principles/models/outline_budget.rb +29 -14
- 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 +14 -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/problem_report.rb +36 -9
- data/lib/principles/models/project.rb +47 -30
- data/lib/principles/models/project_history.rb +45 -25
- data/lib/principles/models/record_format.rb +6 -0
- data/lib/principles/models/reported_check.rb +16 -12
- data/lib/principles/models/request_id.rb +1 -1
- data/lib/principles/models/sent_answer.rb +35 -5
- data/lib/principles/models/survey_search_paths.rb +26 -0
- data/lib/principles/models/uncommitted_files.rb +50 -0
- data/lib/principles/models/unknown_principle.rb +29 -0
- data/lib/principles/positional_arguments.rb +38 -0
- data/lib/principles/session_start_options.rb +3 -3
- data/lib/principles/start_audit_options.rb +10 -2
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +54 -16
- 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 +26 -5
- data/lib/principles/views/assessment_request.rb +24 -4
- data/lib/principles/views/audit_result.rb +30 -27
- data/lib/principles/views/candidate_files_result.rb +56 -12
- data/lib/principles/views/candidate_outlines_result.rb +25 -0
- data/lib/principles/views/check_result_template.rb +18 -17
- data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
- data/lib/principles/views/correction_request.rb +38 -10
- data/lib/principles/views/findings_result.rb +21 -0
- data/lib/principles/views/guidance_search_paths_result.rb +26 -0
- data/lib/principles/views/invocation.rb +19 -4
- data/lib/principles/views/json_with_entries_on_lines.rb +12 -4
- data/lib/principles/views/loads_to_check_result.rb +3 -2
- data/lib/principles/views/map_added_to.rb +56 -2
- data/lib/principles/views/map_result.rb +22 -42
- data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
- data/lib/principles/views/member_change_since_baseline.rb +2 -1
- data/lib/principles/views/member_repairs.rb +2 -1
- data/lib/principles/views/member_row.rb +61 -0
- data/lib/principles/views/members_a_commit_changed.rb +2 -1
- data/lib/principles/views/members_with_no_baseline.rb +8 -1
- data/lib/principles/views/new_loading_scope.rb +31 -0
- data/lib/principles/views/one_member_check_result_template.rb +37 -21
- data/lib/principles/views/open_findings_line.rb +2 -1
- data/lib/principles/views/principle_read_result.rb +4 -1
- data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
- data/lib/principles/views/problem_lines.rb +50 -45
- data/lib/principles/views/problem_result.rb +59 -25
- data/lib/principles/views/prompts/acknowledge-a-change/report-the-exit-status-its-own-listing-gives.md +3 -0
- data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -3
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-each-change-keeps-its-meaning.md +8 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -6
- data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -43
- data/lib/principles/views/prompts/assess-every-member/decide-each-member-loading.md +2 -1
- data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
- data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +5 -3
- 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 +12 -0
- 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/choose-an-existing-or-new-principle.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +4 -2
- 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/read-left-out-files.md +2 -2
- 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/every-command-and-how-they-chain.md +1 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +37 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +20 -19
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +65 -61
- 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 +33 -7
- 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/start-audit.md +10 -10
- 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/start-a-session/act-on-the-open-findings.md +1 -1
- data/lib/principles/views/prompts/start-a-session/every-loaded-line-costs-every-session.md +1 -0
- data/lib/principles/views/prompts/start-a-session/start-with-the-principles-skill.md +1 -0
- metadata +67 -4
- data/lib/principles/models/candidate_listing.rb +0 -41
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "principle"
|
|
6
6
|
require_relative "member_moves"
|
|
7
|
+
require_relative "declared_member_removals"
|
|
7
8
|
|
|
8
9
|
module Principles
|
|
9
10
|
# The domain: maps, audits and command steps, with every rule a schema cannot express.
|
|
@@ -11,11 +12,12 @@ module Principles
|
|
|
11
12
|
module Models
|
|
12
13
|
# The changes a correction declares it made to the map after the audit began: the members it moved (D28),
|
|
13
14
|
# and the members whose role or check a fix changed, which each fixed disposition lists in
|
|
14
|
-
# changed_map_entries (D40). This tool checks them against the
|
|
15
|
+
# changed_map_entries (D40), and the members fixed dispositions removed. This tool checks them against the
|
|
16
|
+
# map at the base commit, which may also hold
|
|
15
17
|
# members added since, needing no declaration, as a fix maps a member a finding said was missing (T69); whether a
|
|
16
18
|
# change fixes its finding is the agent's judgement.
|
|
17
19
|
class DeclaredMapChanges
|
|
18
|
-
# The
|
|
20
|
+
# The answer's moved_members and each disposition's changed_map_entries and removed_members.
|
|
19
21
|
#: (untyped) -> DeclaredMapChanges
|
|
20
22
|
def self.declared_in(response)
|
|
21
23
|
new(MemberMoves.new(response["moved_members"]), response["dispositions"])
|
|
@@ -25,12 +27,13 @@ module Principles
|
|
|
25
27
|
def initialize(moves, dispositions)
|
|
26
28
|
@moves = moves
|
|
27
29
|
@entries = claimed(dispositions) #: Array[String]
|
|
30
|
+
@removals = DeclaredMemberRemovals.new(dispositions) #: DeclaredMemberRemovals
|
|
28
31
|
freeze
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
#: () -> bool
|
|
32
35
|
def empty?
|
|
33
|
-
@moves.empty? && @entries.empty?
|
|
36
|
+
@moves.empty? && @entries.empty? && @removals.empty?
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
# The base commit, to read there the map the audit began from, or nil when nothing is declared and current is
|
|
@@ -52,19 +55,22 @@ module Principles
|
|
|
52
55
|
return base if base
|
|
53
56
|
|
|
54
57
|
raise Error.new("map_entries_need_git",
|
|
55
|
-
"
|
|
58
|
+
"Declared role/check changes and member removals need git, to read the map " \
|
|
59
|
+
"#{principle_id} began from",
|
|
56
60
|
"Outside git, defer the finding, commit nothing, and start a fresh audit: " \
|
|
57
61
|
"#{Error::EXECUTABLE} start-audit #{principle_id}")
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
# Refuses unless base is the map the audit began from and current is base with exactly the declared
|
|
61
|
-
# members moved, the claimed members' role and check changed, and any members added (T69).
|
|
65
|
+
# members removed or moved, the claimed members' role and check changed, and any members added (T69).
|
|
62
66
|
#: (Principle, Principle, map_version: String, map_file: String) -> void
|
|
63
67
|
def check(base, current, map_version:, map_file:)
|
|
64
68
|
raise unexplained(current.id, map_file) unless base.version == map_version
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
raise unexplained(current.id, map_file) unless
|
|
70
|
+
@removals.check_conflicts(@moves, @entries)
|
|
71
|
+
raise unexplained(current.id, map_file) unless reconstructed(base, current).version == current.version
|
|
72
|
+
|
|
73
|
+
@removals.check_endpoint(current)
|
|
68
74
|
end
|
|
69
75
|
|
|
70
76
|
# Each claimed member's role and check, as was and now, where they differ between the base map with the
|
|
@@ -80,7 +86,7 @@ module Principles
|
|
|
80
86
|
end
|
|
81
87
|
|
|
82
88
|
# The map file, when the correction moved a member in it, even under its own id (#1100), a fix changed a
|
|
83
|
-
# member's role or check in it, or
|
|
89
|
+
# member's role or check in it, or added/removed members in it, so the agent commits it too (T69, #1178).
|
|
84
90
|
#: (String, ?added: Array[String]) -> Array[String]
|
|
85
91
|
def files_to_commit(map_file, added: [])
|
|
86
92
|
empty? && added.empty? ? [] : [map_file]
|
|
@@ -88,6 +94,14 @@ module Principles
|
|
|
88
94
|
|
|
89
95
|
private
|
|
90
96
|
|
|
97
|
+
# Replay removals, then moves and role/check changes, then include members added during the correction.
|
|
98
|
+
#: (Principle, Principle) -> Principle
|
|
99
|
+
def reconstructed(base, current)
|
|
100
|
+
retained = @removals.applied(base, current)
|
|
101
|
+
expected = @entries.reduce(@moves.applied(retained, current)) { |map, id| claimed_entry(map, current, id) }
|
|
102
|
+
with_added(expected, current)
|
|
103
|
+
end
|
|
104
|
+
|
|
91
105
|
# expected with each member of current whose id it lacks added, as add-member adds it.
|
|
92
106
|
#: (Principle, Principle) -> Principle
|
|
93
107
|
def with_added(expected, current)
|
|
@@ -148,7 +162,9 @@ module Principles
|
|
|
148
162
|
"If you moved a member to fix a finding, declare it in the answer's moved_members as " \
|
|
149
163
|
"{\"from\": OLD_ID, \"to\": NEW_ID}, and a move that kept its id, as narrowing or widening a " \
|
|
150
164
|
"passage, as {\"from\": ID, \"to\": ID}; if a fix changed a member's role or check, list the " \
|
|
151
|
-
"member's id in that fixed disposition's changed_map_entries.
|
|
165
|
+
"member's id in that fixed disposition's changed_map_entries. If a fix removed a member with " \
|
|
166
|
+
"remove-member, list its original id in that fixed disposition's removed_members. " \
|
|
167
|
+
"In git, a member you added with " \
|
|
152
168
|
"add-member needs no declaration, as long as nothing else changed.\n" \
|
|
153
169
|
"Otherwise, start a fresh audit: #{Error::EXECUTABLE} start-audit #{principle_id}", map_file)
|
|
154
170
|
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "member_moves"
|
|
6
|
+
require_relative "principle"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# The set of members fixed dispositions say they removed from the map, never from their source files.
|
|
12
|
+
class DeclaredMemberRemovals
|
|
13
|
+
#: (untyped) -> void
|
|
14
|
+
def initialize(dispositions)
|
|
15
|
+
claimed = Array(dispositions).flat_map { |each| claimed(each) }
|
|
16
|
+
@ids = claimed.uniq.map { |id| id.dup.freeze }.freeze #: Array[String]
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#: () -> bool
|
|
21
|
+
def empty? = @ids.empty?
|
|
22
|
+
|
|
23
|
+
# A removal cannot simultaneously claim to move or edit that same map entry.
|
|
24
|
+
#: (MemberMoves, Array[String]) -> void
|
|
25
|
+
def check_conflicts(moves, entries)
|
|
26
|
+
return unless moves.involving_any?(@ids) || @ids.intersect?(entries)
|
|
27
|
+
|
|
28
|
+
raise invalid("A removed member also appears in moved_members or changed_map_entries")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Apply only removals that really existed in the original map and are absent from the current one.
|
|
32
|
+
#: (Principle, Principle) -> Principle
|
|
33
|
+
def applied(base, current)
|
|
34
|
+
unless (@ids - base.members.ids).empty? && !@ids.intersect?(current.members.ids)
|
|
35
|
+
raise invalid("Each removed_members id must exist at the audit base and be absent now")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@ids.reduce(base) { |map, id| map.removing(id) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Called after complete map equality, so an unexplained removal retains its ordinary stale-map refusal.
|
|
42
|
+
#: (Principle) -> void
|
|
43
|
+
def check_endpoint(current)
|
|
44
|
+
return if empty? || current.members.ids.any?
|
|
45
|
+
|
|
46
|
+
raise Error.new("empty_correction_map", "A declared-removal correction must leave a mapped member",
|
|
47
|
+
"Keep a survivor or add a replacement. Restore the removed map entries before " \
|
|
48
|
+
"reconsidering or deferring the correction. Preserve the correction packet; " \
|
|
49
|
+
"it has not been submitted. Explicit deactivation retains the previous audit history:\n" \
|
|
50
|
+
"#{Error::EXECUTABLE} remove-principle #{current.id}")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
#: (untyped) -> Array[String]
|
|
56
|
+
def claimed(disposition)
|
|
57
|
+
return [] unless disposition.is_a?(Hash)
|
|
58
|
+
|
|
59
|
+
ids = disposition.fetch("removed_members", [])
|
|
60
|
+
if !ids.empty? && disposition["action"] != "fixed"
|
|
61
|
+
raise Error.new("invalid_disposition", "Only a fixed disposition may list removed_members",
|
|
62
|
+
"Mark it fixed with evidence and a reassessment, or omit removed_members.")
|
|
63
|
+
end
|
|
64
|
+
ids
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#: (String) -> Error
|
|
68
|
+
def invalid(message)
|
|
69
|
+
Error.new("invalid_removed_members", message,
|
|
70
|
+
"List only actual map removals in each fixed disposition's removed_members; " \
|
|
71
|
+
"keep them disjoint from moves and changed_map_entries. Source files are never removed.")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -85,7 +85,8 @@ module Principles
|
|
|
85
85
|
# What action takes, said where it is written when the correction's answer is printed with no answer guide
|
|
86
86
|
# beside it, as show-answer-check prints it (D81 step 3). It is help, never an action, so it is left unchosen.
|
|
87
87
|
ACTION_PLACEHOLDER = "One of fixed, deferred, accepted or disagreed, each with a reason: fixed lists " \
|
|
88
|
-
"changed_members
|
|
88
|
+
"changed_members for current text changes, optional removed_members for map removals, " \
|
|
89
|
+
"and evidence and gives a reassessment; deferred gives recorded_at, " \
|
|
89
90
|
"where the write-up is, and may give waits_on; any other action leaves changed_members, " \
|
|
90
91
|
"evidence and reassessment as printed" #: String
|
|
91
92
|
# Every placeholder a correction's template prints: each text field's, and the action's.
|
|
@@ -153,7 +154,7 @@ module Principles
|
|
|
153
154
|
action = @disposition["action"]
|
|
154
155
|
checked_fields
|
|
155
156
|
members = @fields.array(fix_fields.list("changed_members"), "changed_members")
|
|
156
|
-
entries = @disposition.fetch("changed_map_entries", [])
|
|
157
|
+
entries = @disposition.fetch("changed_map_entries", []) + @disposition.fetch("removed_members", [])
|
|
157
158
|
action == "fixed" ? fixed_members(members, entries, changed) : fix_fields.unclaimed(members, entries)
|
|
158
159
|
end
|
|
159
160
|
|
|
@@ -220,6 +221,7 @@ module Principles
|
|
|
220
221
|
# Each piece of evidence, and where the finding is written up, located in the project.
|
|
221
222
|
#: () -> void
|
|
222
223
|
def locate_pointers
|
|
224
|
+
fix_fields.check_removal_evidence if fixed?
|
|
223
225
|
@fields.evidence(fix_fields.list("evidence"), @place.child("evidence"))
|
|
224
226
|
@fields.pointer(@disposition["recorded_at"], @place.child("recorded_at")) if @disposition["recorded_at"]
|
|
225
227
|
end
|
|
@@ -25,6 +25,18 @@ module Principles
|
|
|
25
25
|
#: (String) -> untyped
|
|
26
26
|
def list(name) = @disposition.fetch(name) { fixed? ? missing_from_fix(name) : [] }
|
|
27
27
|
|
|
28
|
+
# A removal without current text or role/check changes needs located evidence about what remains.
|
|
29
|
+
#: () -> void
|
|
30
|
+
def check_removal_evidence
|
|
31
|
+
return if @disposition.fetch("removed_members", []).empty?
|
|
32
|
+
return unless list("changed_members").empty? && @disposition.fetch("changed_map_entries", []).empty?
|
|
33
|
+
return unless list("evidence").empty?
|
|
34
|
+
|
|
35
|
+
raise Error.new("invalid_disposition", "A removal-only fix needs evidence about the remaining guidance",
|
|
36
|
+
"Give at least one located evidence pointer about the remaining guidance and " \
|
|
37
|
+
"write a substantive reassessment.")
|
|
38
|
+
end
|
|
39
|
+
|
|
28
40
|
# The members a disposition not fixed claims, none, refusing one that lists changed members or map entries,
|
|
29
41
|
# writes a reassessment or lists evidence, each of which it would drop unread though the agent may have meant
|
|
30
42
|
# a fix.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
8
|
+
module Models
|
|
9
|
+
# A glob the agent names for additional guidance inside this project, never a path outside it.
|
|
10
|
+
class GuidanceSearchPath
|
|
11
|
+
#: String
|
|
12
|
+
attr_reader :glob
|
|
13
|
+
|
|
14
|
+
#: (String) -> void
|
|
15
|
+
def initialize(glob)
|
|
16
|
+
@glob = glob.sub(%r{\A(?:\./)+}, "").freeze #: String
|
|
17
|
+
if @glob.strip.empty? || @glob.start_with?("/") || @glob.include?("\u0000") || @glob.split("/").include?("..")
|
|
18
|
+
raise Error.new("invalid_guidance_search_path", "Guidance search paths must stay inside this project",
|
|
19
|
+
"Give a quoted root-relative glob, such as 'guides/**/*.md', with no parent segments.", glob)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../data/guidance_search_paths_file"
|
|
5
|
+
require_relative "guidance_search_path"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# The additional guidance globs this project records, with one owner for normalized additions and removals.
|
|
11
|
+
class GuidanceSearchPaths
|
|
12
|
+
#: Array[String]
|
|
13
|
+
attr_reader :globs
|
|
14
|
+
|
|
15
|
+
#: (Data::GuidanceSearchPathsFile) -> GuidanceSearchPaths
|
|
16
|
+
def self.read(file) = new(file.read, file)
|
|
17
|
+
|
|
18
|
+
#: (Hash[String, untyped], Data::GuidanceSearchPathsFile) -> void
|
|
19
|
+
def initialize(fields, file)
|
|
20
|
+
@file = file
|
|
21
|
+
normalized = fields.fetch("globs").map { |glob| GuidanceSearchPath.new(glob).glob }
|
|
22
|
+
@globs = normalized.uniq.sort.freeze #: Array[String]
|
|
23
|
+
freeze
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#: (String) -> GuidanceSearchPaths
|
|
27
|
+
def adding(glob) = with(@globs | [GuidanceSearchPath.new(glob).glob])
|
|
28
|
+
|
|
29
|
+
#: (String) -> GuidanceSearchPaths
|
|
30
|
+
def removing(glob)
|
|
31
|
+
normalized = GuidanceSearchPath.new(glob).glob
|
|
32
|
+
unless @globs.include?(normalized)
|
|
33
|
+
raise Error.new("unknown_guidance_search_path",
|
|
34
|
+
"#{normalized.inspect} is not a recorded guidance search path",
|
|
35
|
+
"Remove an exact glob listed in recorded_guidance_search_paths.", @file.relative)
|
|
36
|
+
.including("recorded_guidance_search_paths" => @globs)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
with(@globs - [normalized])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#: (GuidanceSearchPaths) -> bool
|
|
43
|
+
def same_as?(other) = @globs == other.globs
|
|
44
|
+
|
|
45
|
+
#: () -> String
|
|
46
|
+
def save
|
|
47
|
+
@file.write("format" => Data::GuidanceSearchPathsFile::FORMAT, "globs" => @globs)
|
|
48
|
+
@file.relative
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
#: (Array[String]) -> GuidanceSearchPaths
|
|
54
|
+
def with(globs) = GuidanceSearchPaths.new({ "globs" => globs }, @file)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -24,6 +24,12 @@ module Principles
|
|
|
24
24
|
first_line <= other.last_line && other.first_line <= last_line
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Inclusive spans meet at consecutive lines in either order, without an overlap or a gap.
|
|
28
|
+
#: (LineSpan) -> bool
|
|
29
|
+
def consecutive_with?(other)
|
|
30
|
+
last_line + 1 == other.first_line || other.last_line + 1 == first_line
|
|
31
|
+
end
|
|
32
|
+
|
|
27
33
|
# Whether every line of other is one of this span's lines. Lines are not text: where the two share a first or
|
|
28
34
|
# last line, a passage can start or end partway through it, so this span may not hold all of other's text.
|
|
29
35
|
#: (LineSpan) -> bool
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "shellwords"
|
|
5
|
+
require_relative "listed_members"
|
|
6
|
+
require_relative "problem_report"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# A member's check that is this tool's own list-member-problems --short, which exits 3 while it lists the member
|
|
12
|
+
# itself, until the acknowledgement of its edit is committed (dogfooding D28b, #1276). Only a check whose words
|
|
13
|
+
# map exactly to that command's is one: any other check passes on exit 0 alone.
|
|
14
|
+
class ListMemberProblemsCheck
|
|
15
|
+
COMMAND = "list-member-problems"
|
|
16
|
+
SHORT = "--short"
|
|
17
|
+
# Characters a shell reads as more than one command's words, or as a redirection or substitution, which leave
|
|
18
|
+
# what ran no longer this command alone.
|
|
19
|
+
SHELL_CONTROL = /[;&|<>()`$]/
|
|
20
|
+
# The words that may run this tool before its executable, which is any path to `principles`.
|
|
21
|
+
RUNNERS = [[], ["ruby"], %w[bundle exec]].freeze #: Array[Array[String]]
|
|
22
|
+
|
|
23
|
+
# The check command reads as, or nil when its words do not map exactly to list-member-problems --short with at
|
|
24
|
+
# most one principle id, run as this tool by any path to it, with no word of shell control.
|
|
25
|
+
#: (String) -> ListMemberProblemsCheck?
|
|
26
|
+
def self.of(command)
|
|
27
|
+
ids = principle_ids(words_after_the_command(command))
|
|
28
|
+
new(ids.first) if ids
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The words after the command name, or nil unless command runs this tool alone.
|
|
32
|
+
#: (String) -> Array[String]?
|
|
33
|
+
def self.words_after_the_command(command)
|
|
34
|
+
words = Shellwords.split(command)
|
|
35
|
+
at = words.index(COMMAND)
|
|
36
|
+
words.drop(at + 1) if at && words.none? { SHELL_CONTROL.match?(it) } && this_tool?(words.take(at))
|
|
37
|
+
rescue ArgumentError
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# The principle ids the words after the command name give, at most one, or nil unless they are --short once and
|
|
42
|
+
# that id.
|
|
43
|
+
#: (Array[String]?) -> Array[String]?
|
|
44
|
+
def self.principle_ids(after)
|
|
45
|
+
return unless after
|
|
46
|
+
|
|
47
|
+
ids = after - [SHORT]
|
|
48
|
+
ids if after.count(SHORT) == 1 && ids.length <= 1 && ids.none? { it.start_with?("-") }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Whether words run this tool: its executable last, after nothing or a runner.
|
|
52
|
+
#: (Array[String]) -> bool
|
|
53
|
+
def self.this_tool?(words)
|
|
54
|
+
*runner, executable = words
|
|
55
|
+
executable&.split("/")&.last == "principles" && RUNNERS.include?(runner)
|
|
56
|
+
end
|
|
57
|
+
private_class_method :words_after_the_command, :principle_ids, :this_tool?
|
|
58
|
+
|
|
59
|
+
# The principle whose map the check reads, or nil for every map.
|
|
60
|
+
#: String?
|
|
61
|
+
attr_reader :principle_id
|
|
62
|
+
|
|
63
|
+
#: (String?) -> void
|
|
64
|
+
def initialize(principle_id)
|
|
65
|
+
@principle_id = principle_id
|
|
66
|
+
freeze
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# What the check lists in project now, read through the report the command prints from, over the same scope:
|
|
70
|
+
# each member, as its principle id and member id, and by principle the count of members no audit has assessed
|
|
71
|
+
# (#1254), beside the members acknowledging names of principle_id.
|
|
72
|
+
#: (Project, principle_id: String, acknowledging: Array[String]) -> ListedMembers
|
|
73
|
+
def listed(project, principle_id:, acknowledging:)
|
|
74
|
+
report = ProblemReport.for(project, @principle_id)
|
|
75
|
+
ListedMembers.new(listed: report.checked.fetch("members").map { it.values_at("principle", "id") },
|
|
76
|
+
principle_id:, acknowledging:, never_assessed: report.never_assessed)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
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 members a member's own list-member-problems check lists now, beside those one answer acknowledges: the check
|
|
8
|
+
# exits 3 until that answer's record is committed, and lists none then only if it acknowledges every one (#1276).
|
|
9
|
+
class ListedMembers
|
|
10
|
+
# listed is each member the check lists, as its principle id and member id; acknowledging is the ids of
|
|
11
|
+
# principle_id's members the answer acknowledges; never_assessed counts, by principle, the members no audit has
|
|
12
|
+
# assessed, which the check counts and no acknowledgement clears (#1254).
|
|
13
|
+
#: (listed: Array[[String, String]], principle_id: String, acknowledging: Array[String],
|
|
14
|
+
#| ?never_assessed: Hash[String, Integer]) -> void
|
|
15
|
+
def initialize(listed:, principle_id:, acknowledging:, never_assessed: {})
|
|
16
|
+
@listed = listed
|
|
17
|
+
@principle_id = principle_id
|
|
18
|
+
@acknowledging = acknowledging
|
|
19
|
+
@never_assessed = never_assessed
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Whether ids, as an answer reports them, are the ids of the members listed, each once, in any order.
|
|
24
|
+
#: (untyped) -> bool
|
|
25
|
+
def reported?(ids) = ids.is_a?(Array) ? ids.sort == @listed.map(&:last).sort : false
|
|
26
|
+
|
|
27
|
+
# The members listed that the answer does not acknowledge, which the check would still list: each by its id,
|
|
28
|
+
# with its principle when that is another, since an id is unique only within its map; then each principle's
|
|
29
|
+
# members no audit has assessed, by count.
|
|
30
|
+
#: () -> Array[String]
|
|
31
|
+
def unacknowledged
|
|
32
|
+
listed = @listed.filter_map do |principle, id|
|
|
33
|
+
next "#{id} of #{principle}" unless principle == @principle_id
|
|
34
|
+
|
|
35
|
+
id unless @acknowledging.include?(id)
|
|
36
|
+
end
|
|
37
|
+
listed + @never_assessed.map { |principle, count| never_assessed(principle, count) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# count members of principle no audit has assessed, as a refusal names them.
|
|
43
|
+
#: (String, Integer) -> String
|
|
44
|
+
def never_assessed(principle, count)
|
|
45
|
+
"#{count} member#{"s" unless count == 1} of #{principle} no audit has assessed"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -31,8 +31,7 @@ module Principles
|
|
|
31
31
|
return {} if @loads.empty?
|
|
32
32
|
|
|
33
33
|
total = session_start_total
|
|
34
|
-
{ "loading_basis" =>
|
|
35
|
-
"session_start_assumption" => "project_root" },
|
|
34
|
+
{ "loading_basis" => MemberLoads::BASIS.dup,
|
|
36
35
|
"files_loaded" => @loads.map { |path, file| { "path" => path }.merge(file.claude_code) },
|
|
37
36
|
**(total ? { "session_start_total" => total } : {}) }
|
|
38
37
|
end
|
|
@@ -30,20 +30,29 @@ module Principles
|
|
|
30
30
|
#: () -> String
|
|
31
31
|
def member_id = @decision["member_id"].to_s
|
|
32
32
|
|
|
33
|
-
# What the record keeps of this decision
|
|
34
|
-
# member's row in the listing.
|
|
33
|
+
# What the record keeps of this decision: its reason, or for kept the last accepted reason, and the loads it
|
|
34
|
+
# accepted, from its member's row in the listing; refused unless the decision is one the record can keep.
|
|
35
35
|
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
36
|
-
def kept(row)
|
|
36
|
+
def kept(row)
|
|
37
|
+
check(row)
|
|
38
|
+
reason = @decision["decision"] == "kept" ? row.dig("last_accepted", "reason") : @decision["reason"]
|
|
39
|
+
{ "reason" => reason, "loads" => row.fetch("loads") }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
37
43
|
|
|
38
|
-
# Refuses the decision unless it is accepted with a one-line reason
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
# Refuses the decision unless it is accepted with a one-line reason, or kept on a member row whose loading
|
|
45
|
+
# the last audit accepted and is unchanged since, so its reason still holds (#1186).
|
|
46
|
+
#: (Hash[String, untyped]) -> void
|
|
47
|
+
def check(row)
|
|
41
48
|
return if @decision["decision"] == "accepted" && AnswerText.new(@decision["reason"]).written?
|
|
49
|
+
return if @decision["decision"] == "kept" && row.dig("last_accepted", "since_accepted") == "unchanged"
|
|
42
50
|
|
|
43
51
|
raise Error.new("invalid_loading_decision",
|
|
44
52
|
"loading_decisions[#{@index}] for #{@decision["member_id"]} needs decision accepted with a " \
|
|
45
|
-
"reason",
|
|
46
|
-
"Give decision accepted with a one-line reason why the member loads as it does, or
|
|
53
|
+
"reason, or kept where its last_accepted.since_accepted is unchanged",
|
|
54
|
+
"Give decision accepted with a one-line reason why the member loads as it does, or kept to " \
|
|
55
|
+
"repeat the last accepted reason while since_accepted is unchanged, or, if the " \
|
|
47
56
|
"activation is what is wrong, change it with change-activation and run start-audit again, " \
|
|
48
57
|
"as the request's loads_to_check_instruction says; a finding decision is not built yet.")
|
|
49
58
|
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
module Models
|
|
6
|
+
# Literal loading-scope qualifiers for mapping feedback, distinct from persisted LoadingFacts.
|
|
7
|
+
class LoadingScope
|
|
8
|
+
QUALIFIERS = %w[
|
|
9
|
+
when context invoked_by skill_part description files paths_field
|
|
10
|
+
].freeze #: [String, String, String, String, String, String, String]
|
|
11
|
+
KNOWN_MOMENTS = %w[session_start on_files on_invocation on_delegation not_loaded].freeze #: Array[String]
|
|
12
|
+
|
|
13
|
+
# fields is MemberLoads#claude_code's derivation, not frontmatter or a second host classifier.
|
|
14
|
+
#: (Hash[String, untyped]) -> void
|
|
15
|
+
def initialize(fields)
|
|
16
|
+
@facts = projected(fields) #: Hash[String, untyped]
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#: () -> Hash[String, untyped]
|
|
21
|
+
def to_h = @facts
|
|
22
|
+
|
|
23
|
+
#: () -> bool
|
|
24
|
+
def known? = known_in?(@facts)
|
|
25
|
+
|
|
26
|
+
#: (untyped) -> bool
|
|
27
|
+
def ==(other) = other.is_a?(LoadingScope) && @facts.eql?(other.to_h)
|
|
28
|
+
|
|
29
|
+
alias eql? ==
|
|
30
|
+
|
|
31
|
+
#: () -> Integer
|
|
32
|
+
def hash = @facts.hash
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
# Unknown markers survive for limitations, but are never compared as known scopes.
|
|
37
|
+
#: (Hash[String, untyped]) -> bool
|
|
38
|
+
def known_in?(fields)
|
|
39
|
+
KNOWN_MOMENTS.include?(fields["when"]) && (!fields["description"] || known_in?(fields["description"]))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
43
|
+
def projected(fields)
|
|
44
|
+
facts = fields.slice(*QUALIFIERS).transform_values { |value| owned(value) }
|
|
45
|
+
facts["description"] = projected(fields.fetch("description")) if fields["description"]
|
|
46
|
+
facts.freeze
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Copy literal qualifiers without normalizing their strings or array order; hash keys must stay stable.
|
|
50
|
+
#: (untyped) -> untyped
|
|
51
|
+
def owned(value)
|
|
52
|
+
case value
|
|
53
|
+
when Hash then value.transform_values { |each| owned(each) }.freeze
|
|
54
|
+
when Array then value.map { |each| owned(each) }.freeze
|
|
55
|
+
when String then value.dup.freeze
|
|
56
|
+
else value
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -46,7 +46,6 @@ module Principles
|
|
|
46
46
|
expected = listed_by_id
|
|
47
47
|
raise incomplete(expected.keys) unless given.map(&:member_id).sort == expected.keys.sort
|
|
48
48
|
|
|
49
|
-
given.each(&:check)
|
|
50
49
|
given.to_h { |decision| [decision.member_id, decision.kept(expected.fetch(decision.member_id))] }
|
|
51
50
|
end
|
|
52
51
|
|
|
@@ -44,6 +44,12 @@ module Principles
|
|
|
44
44
|
#: () -> bool
|
|
45
45
|
def whole_file? = KEYS.none? { |key| @fields.key?(key) }
|
|
46
46
|
|
|
47
|
+
# A heading's full section, with no narrower passage or frontmatter query.
|
|
48
|
+
#: () -> bool
|
|
49
|
+
def complete_section?
|
|
50
|
+
!heading.nil? && starting_at.nil? && ending_at.nil? && query.nil?
|
|
51
|
+
end
|
|
52
|
+
|
|
47
53
|
# The locator as it was given.
|
|
48
54
|
#: () -> Hash[String, untyped]
|
|
49
55
|
def to_h = @fields
|