principles 0.0.5 → 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/command_line.rb +12 -28
- data/lib/principles/command_routes.rb +7 -1
- data/lib/principles/controllers/acknowledgement.rb +36 -26
- data/lib/principles/controllers/answer.rb +7 -5
- data/lib/principles/controllers/assessment.rb +14 -3
- data/lib/principles/controllers/audit_completion.rb +3 -1
- data/lib/principles/controllers/command.rb +2 -2
- data/lib/principles/controllers/correction.rb +3 -1
- data/lib/principles/controllers/full_audit_request.rb +1 -1
- 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_addition.rb +65 -0
- data/lib/principles/controllers/member_entries.rb +6 -24
- data/lib/principles/controllers/member_problems_report.rb +2 -2
- 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 +77 -16
- 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 +4 -5
- data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
- 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 +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 +2 -2
- data/lib/principles/models/acknowledgement.rb +28 -6
- data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
- data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
- data/lib/principles/models/audit_record.rb +4 -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/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/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_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 +48 -24
- data/lib/principles/models/member_region.rb +129 -0
- data/lib/principles/models/member_repair_moves.rb +9 -11
- 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 +17 -5
- data/lib/principles/models/project.rb +43 -27
- 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 +2 -1
- data/lib/principles/models/sent_answer.rb +10 -0
- 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 +37 -0
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +16 -12
- data/lib/principles/views/added_member.rb +41 -0
- data/lib/principles/views/answered_request.rb +21 -0
- data/lib/principles/views/assessment_request.rb +2 -1
- data/lib/principles/views/audit_result.rb +21 -26
- data/lib/principles/views/candidate_files_result.rb +56 -12
- data/lib/principles/views/candidate_outlines_result.rb +25 -0
- 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/json_with_entries_on_lines.rb +12 -4
- 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/new_loading_scope.rb +31 -0
- data/lib/principles/views/one_member_check_result_template.rb +25 -21
- 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 +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 -3
- 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/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/list-candidate-files.md +37 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +5 -4
- 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 +26 -0
- 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 +2 -2
- 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
- metadata +55 -4
- data/lib/principles/models/candidate_listing.rb +0 -41
|
@@ -5,8 +5,6 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "audit_record"
|
|
6
6
|
require_relative "member"
|
|
7
7
|
require_relative "principle_history"
|
|
8
|
-
require_relative "mapped_principles"
|
|
9
|
-
require_relative "project_history"
|
|
10
8
|
|
|
11
9
|
module Principles
|
|
12
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -16,11 +14,9 @@ module Principles
|
|
|
16
14
|
# committed map, and the audit asks the agent to run it, so a check no audit has seen needs a review
|
|
17
15
|
# first (#227). This tool states the fact; the review is the agent's step.
|
|
18
16
|
class CheckSinceLastAudit
|
|
19
|
-
#: (
|
|
20
|
-
def initialize(
|
|
21
|
-
@
|
|
22
|
-
@history = history
|
|
23
|
-
@principles = principles
|
|
17
|
+
#: (principle_history: PrincipleHistory, record: AuditRecord?) -> void
|
|
18
|
+
def initialize(principle_history:, record:)
|
|
19
|
+
@principle_history = principle_history
|
|
24
20
|
@record = record
|
|
25
21
|
freeze
|
|
26
22
|
end
|
|
@@ -66,7 +62,7 @@ module Principles
|
|
|
66
62
|
|
|
67
63
|
#: (String, String) -> String?
|
|
68
64
|
def commit_that_set(key, check)
|
|
69
|
-
run =
|
|
65
|
+
run = @principle_history.runs([key]).fetch(key)
|
|
70
66
|
run.take_while { |_sha, fields| Member.new(fields).check == check }.last&.first
|
|
71
67
|
end
|
|
72
68
|
end
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -5,6 +5,8 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "../data/map_files"
|
|
6
6
|
require_relative "principle"
|
|
7
7
|
require_relative "meta_principle"
|
|
8
|
+
require_relative "unknown_principle"
|
|
9
|
+
require_relative "project_history"
|
|
8
10
|
|
|
9
11
|
module Principles
|
|
10
12
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -14,9 +16,10 @@ module Principles
|
|
|
14
16
|
# A principle id names its principle in lower-kebab-case.
|
|
15
17
|
ID_FORMAT = Data::PrincipleId::FORMAT #: Regexp
|
|
16
18
|
|
|
17
|
-
#: (Data::MapFiles) -> void
|
|
18
|
-
def initialize(files)
|
|
19
|
+
#: (Data::MapFiles, ProjectHistory) -> void
|
|
20
|
+
def initialize(files, history)
|
|
19
21
|
@files = files
|
|
22
|
+
@history = history
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
#: () -> Array[String]
|
|
@@ -24,6 +27,16 @@ module Principles
|
|
|
24
27
|
@files.ids
|
|
25
28
|
end
|
|
26
29
|
|
|
30
|
+
# The mapped rules a survey compares with its candidate principles, without audit or freshness reads.
|
|
31
|
+
#: () -> Array[Hash[String, untyped]]
|
|
32
|
+
def descriptions
|
|
33
|
+
ids.map do |id|
|
|
34
|
+
find(id).description_with_id
|
|
35
|
+
rescue Error => e
|
|
36
|
+
{ "id" => id, "refusal" => e.payload }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
27
40
|
# The id of map id, or of every map when id is nil; an id no map has is refused, as find refuses it.
|
|
28
41
|
#: (String?) -> Array[String]
|
|
29
42
|
def ids_of(id)
|
|
@@ -66,13 +79,18 @@ module Principles
|
|
|
66
79
|
#: (String) -> Principle
|
|
67
80
|
def find(id)
|
|
68
81
|
refuse_unknown(id)
|
|
69
|
-
|
|
82
|
+
Principle.from_map(id, @files.read(id), files: @files)
|
|
70
83
|
end
|
|
71
84
|
|
|
72
85
|
# The map id as text read elsewhere holds it, such as its file at commit, the one an audit began from.
|
|
73
86
|
#: (String, String, ?commit: String?) -> Principle
|
|
74
87
|
def parsed(id, text, commit: nil)
|
|
75
|
-
|
|
88
|
+
Principle.from_map(id, @files.parse(id, text, commit: commit), files: @files, commit: commit)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
#: (String, String, commit: String?) -> Principle
|
|
92
|
+
def parsed_history(id, text, commit:)
|
|
93
|
+
Principle.from_map(id, @files.parse_history(id, text, commit: commit), files: @files, commit: commit)
|
|
76
94
|
end
|
|
77
95
|
|
|
78
96
|
# A new map for id with no members, not yet saved. It is refused unless id is lower-kebab-case and not
|
|
@@ -80,7 +98,8 @@ module Principles
|
|
|
80
98
|
#: (String) { () -> String } -> Principle
|
|
81
99
|
def create(id, &)
|
|
82
100
|
refuse_unavailable(id)
|
|
83
|
-
|
|
101
|
+
MetaPrinciple.refuse_explicit_creation(id)
|
|
102
|
+
refuse_uncommitted_removal(id)
|
|
84
103
|
Principle.new(id, { "description" => yield, "members" => [] })
|
|
85
104
|
end
|
|
86
105
|
|
|
@@ -89,8 +108,9 @@ module Principles
|
|
|
89
108
|
# has is refused, as find refuses it.
|
|
90
109
|
#: (String) -> Principle
|
|
91
110
|
def addable(id)
|
|
92
|
-
return find(id) if mapped?(id) || !
|
|
111
|
+
return find(id) if mapped?(id) || !MetaPrinciple.id?(id)
|
|
93
112
|
|
|
113
|
+
refuse_uncommitted_removal(id)
|
|
94
114
|
Principle.new(id, MetaPrinciple.starting_fields)
|
|
95
115
|
end
|
|
96
116
|
|
|
@@ -111,6 +131,13 @@ module Principles
|
|
|
111
131
|
file(map.id)
|
|
112
132
|
end
|
|
113
133
|
|
|
134
|
+
# Removes only the map, after the command's audit-entry guard; no member or audit file is changed.
|
|
135
|
+
#: (Principle) -> String
|
|
136
|
+
def remove(map)
|
|
137
|
+
@files.remove(map.id)
|
|
138
|
+
file(map.id)
|
|
139
|
+
end
|
|
140
|
+
|
|
114
141
|
# The file map id is kept in, relative to the project.
|
|
115
142
|
#: (String) -> String
|
|
116
143
|
def file(id)
|
|
@@ -125,17 +152,12 @@ module Principles
|
|
|
125
152
|
|
|
126
153
|
private
|
|
127
154
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def started_by_setup?(id) = id == MetaPrinciple::ID
|
|
155
|
+
#: (String) -> void
|
|
156
|
+
def refuse_uncommitted_removal(id)
|
|
157
|
+
return unless [file(id), earlier_file(id)].any? { |path| @history.entry_at_head?(path) }
|
|
132
158
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def unique(map, commit = nil)
|
|
136
|
-
where = commit ? "#{file(map.id)} at commit #{commit[0, 12]}" : file(map.id)
|
|
137
|
-
map.members.refuse_repeats(where: where, file: file(map.id))
|
|
138
|
-
map
|
|
159
|
+
raise Error.new("map_removal_not_committed", "#{id}'s map is still present at committed HEAD",
|
|
160
|
+
"Commit its removal or ID change before recreating #{id}, then retry this command.", file(id))
|
|
139
161
|
end
|
|
140
162
|
|
|
141
163
|
# A principle no map names, with the commands that create one and list the rest. For the meta-principle's id the
|
|
@@ -145,27 +167,7 @@ module Principles
|
|
|
145
167
|
def refuse_unknown(id)
|
|
146
168
|
return if mapped?(id)
|
|
147
169
|
|
|
148
|
-
raise
|
|
149
|
-
"#{creating(id)}\nTo see the mapped ids: #{Error::EXECUTABLE} list-principles")
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# The repair line that creates principle id's map.
|
|
153
|
-
#: (String) -> String
|
|
154
|
-
def creating(id)
|
|
155
|
-
return MetaPrinciple::SET_UP if started_by_setup?(id)
|
|
156
|
-
|
|
157
|
-
"To create it: #{Error::EXECUTABLE} create-principle #{id} --description TEXT"
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# The meta-principle's map is written by the add-member setup prints, with its first member; create-principle
|
|
161
|
-
# would write it with no members, another description and no activation (T74).
|
|
162
|
-
#: (String) -> void
|
|
163
|
-
def refuse_meta_principle_id(id)
|
|
164
|
-
return unless started_by_setup?(id)
|
|
165
|
-
|
|
166
|
-
raise Error.new("meta_principle_id",
|
|
167
|
-
"#{id} is set up by show-meta-principle-passage, whose printed add-member creates its map " \
|
|
168
|
-
"with its first member", MetaPrinciple::SET_UP)
|
|
170
|
+
raise UnknownPrinciple.new(id).refusal
|
|
169
171
|
end
|
|
170
172
|
|
|
171
173
|
#: (String) -> void
|