principles 0.0.11 → 0.1.1

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.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/lib/principles/controllers/answer.rb +2 -2
  4. data/lib/principles/controllers/assessment.rb +19 -3
  5. data/lib/principles/controllers/audit.rb +14 -4
  6. data/lib/principles/controllers/full_audit_request.rb +16 -10
  7. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  8. data/lib/principles/controllers/member_addition.rb +4 -1
  9. data/lib/principles/controllers/member_problems_report.rb +7 -6
  10. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  11. data/lib/principles/controllers/running_tool.rb +22 -5
  12. data/lib/principles/controllers/survey.rb +3 -2
  13. data/lib/principles/data/candidate_files_found.rb +6 -4
  14. data/lib/principles/data/command-steps.json +17 -17
  15. data/lib/principles/data/committed_texts.rb +58 -0
  16. data/lib/principles/data/first_parent_log.rb +50 -10
  17. data/lib/principles/data/json_text.rb +5 -1
  18. data/lib/principles/data/parser_message.rb +61 -0
  19. data/lib/principles/data/project_files.rb +4 -2
  20. data/lib/principles/data/repository.rb +29 -37
  21. data/lib/principles/data/running_version.rb +1 -1
  22. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  23. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  24. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  25. data/lib/principles/data/working_tree_changes.rb +62 -0
  26. data/lib/principles/invocation_options.rb +1 -1
  27. data/lib/principles/launch.rb +5 -3
  28. data/lib/principles/models/after_commit_input.rb +1 -0
  29. data/lib/principles/models/assessment_basis.rb +1 -1
  30. data/lib/principles/models/audit.rb +23 -3
  31. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  32. data/lib/principles/models/audit_record.rb +5 -14
  33. data/lib/principles/models/audit_records.rb +1 -1
  34. data/lib/principles/models/audited_member_lines.rb +1 -1
  35. data/lib/principles/models/candidate_files.rb +1 -1
  36. data/lib/principles/models/candidate_inventory.rb +19 -9
  37. data/lib/principles/models/candidate_outline.rb +1 -1
  38. data/lib/principles/models/changed_regions.rb +1 -1
  39. data/lib/principles/models/command_steps.rb +1 -2
  40. data/lib/principles/models/correction_basis.rb +1 -1
  41. data/lib/principles/models/declared_map_changes.rb +1 -2
  42. data/lib/principles/models/finding_decision.rb +84 -0
  43. data/lib/principles/models/finding_write_ups.rb +2 -1
  44. data/lib/principles/models/first_full_audit.rb +1 -0
  45. data/lib/principles/models/frontmatter_fields.rb +1 -1
  46. data/lib/principles/models/guidance_search_path.rb +1 -1
  47. data/lib/principles/models/guidance_search_paths.rb +5 -1
  48. data/lib/principles/models/head_moves.rb +1 -0
  49. data/lib/principles/models/ignored_candidates.rb +1 -1
  50. data/lib/principles/models/instruction_named.rb +1 -1
  51. data/lib/principles/models/json_path_query.rb +1 -1
  52. data/lib/principles/models/json_path_selectors.rb +1 -1
  53. data/lib/principles/models/json_path_string.rb +1 -1
  54. data/lib/principles/models/last_completed_revision.rb +1 -1
  55. data/lib/principles/models/line_diff.rb +1 -1
  56. data/lib/principles/models/line_span.rb +1 -1
  57. data/lib/principles/models/loading_scope.rb +1 -0
  58. data/lib/principles/models/located_text.rb +1 -1
  59. data/lib/principles/models/map_change.rb +66 -0
  60. data/lib/principles/models/mapped_principles.rb +4 -0
  61. data/lib/principles/models/markdown_file.rb +22 -1
  62. data/lib/principles/models/member.rb +1 -1
  63. data/lib/principles/models/member_elsewhere.rb +1 -1
  64. data/lib/principles/models/member_file.rb +6 -1
  65. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  66. data/lib/principles/models/member_history.rb +1 -1
  67. data/lib/principles/models/member_lines.rb +1 -1
  68. data/lib/principles/models/member_loading_scopes.rb +1 -0
  69. data/lib/principles/models/member_mapping_run.rb +4 -4
  70. data/lib/principles/models/member_moves.rb +1 -2
  71. data/lib/principles/models/member_problems.rb +5 -1
  72. data/lib/principles/models/member_region.rb +1 -1
  73. data/lib/principles/models/members_elsewhere.rb +1 -1
  74. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  75. data/lib/principles/models/members_sharing_lines.rb +1 -1
  76. data/lib/principles/models/misspelt_member_id.rb +1 -1
  77. data/lib/principles/models/open_finding.rb +4 -3
  78. data/lib/principles/models/open_findings_decision.rb +124 -0
  79. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  80. data/lib/principles/models/other_templates_placeholders.rb +1 -0
  81. data/lib/principles/models/outline_budget.rb +1 -1
  82. data/lib/principles/models/outline_group.rb +1 -1
  83. data/lib/principles/models/outline_section.rb +1 -1
  84. data/lib/principles/models/part_named.rb +1 -1
  85. data/lib/principles/models/plain_text_file.rb +1 -1
  86. data/lib/principles/models/principle_history.rb +3 -3
  87. data/lib/principles/models/principle_members.rb +1 -1
  88. data/lib/principles/models/problem_report.rb +26 -3
  89. data/lib/principles/models/project.rb +8 -3
  90. data/lib/principles/models/project_at_commit.rb +9 -19
  91. data/lib/principles/models/project_history.rb +8 -0
  92. data/lib/principles/models/prose_line.rb +36 -0
  93. data/lib/principles/models/record_format.rb +17 -4
  94. data/lib/principles/models/recorded_finding.rb +47 -7
  95. data/lib/principles/models/recorded_findings.rb +7 -7
  96. data/lib/principles/models/recorded_hashes.rb +1 -1
  97. data/lib/principles/models/recorded_members.rb +6 -8
  98. data/lib/principles/models/report_hooks.rb +1 -0
  99. data/lib/principles/models/request_id.rb +2 -2
  100. data/lib/principles/models/sent_answer.rb +1 -0
  101. data/lib/principles/models/session_start_input.rb +1 -0
  102. data/lib/principles/models/stale_request.rb +22 -8
  103. data/lib/principles/models/submitted_answer.rb +1 -1
  104. data/lib/principles/models/survey_search_paths.rb +13 -5
  105. data/lib/principles/models/text_within.rb +1 -1
  106. data/lib/principles/models/unchecked_members.rb +1 -0
  107. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  108. data/lib/principles/models/unknown_principle.rb +1 -0
  109. data/lib/principles/models/write_up_opening.rb +5 -31
  110. data/lib/principles/models/write_up_pointer.rb +2 -1
  111. data/lib/principles/start_audit_options.rb +25 -18
  112. data/lib/principles/version.rb +2 -2
  113. data/lib/principles/views/acknowledgement_result.rb +12 -9
  114. data/lib/principles/views/added_member.rb +10 -1
  115. data/lib/principles/views/answer_in_a_file.rb +16 -4
  116. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  117. data/lib/principles/views/assessment_request.rb +2 -26
  118. data/lib/principles/views/audit_result.rb +15 -6
  119. data/lib/principles/views/candidate_files_result.rb +24 -13
  120. data/lib/principles/views/context_parts.rb +40 -9
  121. data/lib/principles/views/correction_request.rb +8 -5
  122. data/lib/principles/views/first_audit_brief.rb +2 -1
  123. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  124. data/lib/principles/views/invocation.rb +14 -4
  125. data/lib/principles/views/json_on_one_line.rb +18 -0
  126. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  127. data/lib/principles/views/problem_facts.rb +46 -0
  128. data/lib/principles/views/problem_result.rb +42 -31
  129. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  130. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  131. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  132. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  133. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  134. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +1 -1
  135. data/lib/principles/views/prompts/find-a-principle-to-map/ask-in-this-order-after-the-table.md +1 -0
  136. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner.md +1 -0
  137. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -2
  138. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +3 -2
  139. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +2 -2
  140. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +2 -2
  141. data/lib/principles/views/prompts/find-a-principle-to-map/group-rules-into-principles.md +3 -0
  142. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  143. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  144. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  145. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  146. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  147. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  148. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  149. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  150. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  151. metadata +20 -9
  152. data/lib/principles/controllers/repoint.rb +0 -67
  153. data/lib/principles/models/repoint.rb +0 -125
  154. data/lib/principles/models/write_up_repoint.rb +0 -38
  155. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +0 -1
  156. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  157. data/lib/principles/views/repoint_result.rb +0 -80
@@ -9,7 +9,7 @@ require_relative "project_history"
9
9
  require_relative "survey_search_paths"
10
10
 
11
11
  module Principles
12
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
12
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
13
13
  module Models
14
14
  # What list-candidate-files found: the inventory of candidate files as it lists them, and in git
15
15
  # which of them, or of the files their links lead to, git does not track. Each list that names a file is
@@ -32,9 +32,10 @@ module Principles
32
32
  def self.read(files, history, search_paths:, after: nil, mapped: [])
33
33
  changed = after ? history.changed_after(after) : []
34
34
  inventory = files.inventory(also: changed.grep(CandidateFiles::MARKDOWN) | (changed & mapped),
35
- matching: search_paths.globs).merge(search_paths.recorded_listing)
35
+ matching: search_paths.globs, conventional: search_paths.conventional?)
36
+ inventory = inventory.merge(search_paths.recorded_listing)
36
37
  inventory = inventory.merge("uncommitted" => uncommitted_markdown(history)) if after
37
- found(inventory, history, changed:) { |path| files.read_text(path) }
38
+ found(inventory, history, changed:, conventional: search_paths.conventional?) { |path| files.read_text(path) }
38
39
  end
39
40
 
40
41
  # An explicit file request uses the survey's entries and budget without its broad search.
@@ -52,15 +53,16 @@ module Principles
52
53
  # git does not track.
53
54
  # Each listed file's text, which its outline is read from, is what the block gives for its path.
54
55
  # changed names the files a range of commits changed, which list first, marked.
55
- #: (Hash[String, untyped], ProjectHistory, ?changed: Array[String]) { (String) -> String } -> CandidateInventory
56
- def self.found(inventory, history, changed: [], &text_of)
56
+ #: (Hash[String, untyped], ProjectHistory, ?changed: Array[String], ?conventional: bool) { (String) -> String }
57
+ #| -> CandidateInventory
58
+ def self.found(inventory, history, changed: [], conventional: true, &text_of)
57
59
  texts = {} #: Hash[String, String]
58
60
  files = CandidateFiles.new(inventory.fetch("files"), selected: inventory.fetch("selected_files", []),
59
61
  text_of: ->(path) { texts[path] ||= text_of.call(path) })
60
62
  hints = inventory.fetch("possibly_test_data")
61
63
  listed = listed(inventory, files.listing(hints, changed:))
62
64
  new(listed, untracked: history.untracked_excluding_ignored(listed.fetch("files").map { it.fetch("path") }),
63
- outlines: files.outlines(hints))
65
+ outlines: files.outlines(hints), conventional:)
64
66
  end
65
67
 
66
68
  # The inventory as list-candidate-files lists it: the instruction files agent hosts load by convention, the other
@@ -86,11 +88,13 @@ module Principles
86
88
  attr_reader :untracked
87
89
 
88
90
  # outlines holds each outlined file's outline, by path, which within_budget cuts by.
89
- #: (Hash[String, untyped], untracked: Array[String]?, ?outlines: Hash[String, CandidateOutline]) -> void
90
- def initialize(listing, untracked:, outlines: {})
91
+ #: (Hash[String, untyped], untracked: Array[String]?, ?outlines: Hash[String, CandidateOutline],
92
+ #| ?conventional: bool) -> void
93
+ def initialize(listing, untracked:, outlines: {}, conventional: true)
91
94
  @listing = listing
92
95
  @untracked = untracked
93
96
  @outlines = outlines
97
+ @conventional = conventional
94
98
  @lists = listing.merge("untracked" => untracked) #: Hash[String, untyped]
95
99
  freeze
96
100
  end
@@ -98,6 +102,10 @@ module Principles
98
102
  #: () -> Hash[String, untyped]
99
103
  def to_h = @listing
100
104
 
105
+ # Whether the survey looked in the places hosts load by convention, as it does unless --only narrowed it.
106
+ #: () -> bool
107
+ def conventional? = @conventional
108
+
101
109
  # This inventory with its files' list items cut to OutlineBudget, the block giving the bytes each inventory tried
102
110
  # prints as.
103
111
  #: () { (CandidateInventory) -> Integer } -> CandidateInventory
@@ -118,7 +126,9 @@ module Principles
118
126
  private
119
127
 
120
128
  #: (Hash[String, untyped]) -> CandidateInventory
121
- def with(listing) = CandidateInventory.new(listing, untracked: @untracked, outlines: @outlines)
129
+ def with(listing)
130
+ CandidateInventory.new(listing, untracked: @untracked, outlines: @outlines, conventional: @conventional)
131
+ end
122
132
 
123
133
  # The path one list entry names: a file's path, a folder, or the path itself.
124
134
  #: (untyped) -> String
@@ -8,7 +8,7 @@ require_relative "outline_section"
8
8
  require_relative "text_within"
9
9
 
10
10
  module Principles
11
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
11
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
12
  module Models
13
13
  # One candidate file's outline, as the survey reads it in place of the file: its Markdown headings in order, and
14
14
  # under each its top-level list items. One user scripted a heading grep over 45 files to survey them,
@@ -4,7 +4,7 @@
4
4
  require_relative "line_diff"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # A long member's changed lines as a request shows them: each run of changed lines with up to context unchanged
10
10
  # lines around it, as git shows a hunk, runs whose context would meet joined into one region, and each later
@@ -5,8 +5,7 @@ require_relative "../error"
5
5
  require_relative "../data/command_steps_file"
6
6
 
7
7
  module Principles
8
- # Values built from validated data, and the rules a schema cannot express. models/CLAUDE.md owns the
9
- # boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
9
  module Models
11
10
  # The steps each command runs: which are this tool's and which are the agent's, the refusals each of
12
11
  # this tool's steps can raise, and where each step leads. Each command's --help and the workflow diagram
@@ -8,7 +8,7 @@ require_relative "last_completed_revision"
8
8
  require_relative "recorded_finding"
9
9
 
10
10
  module Principles
11
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
11
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
12
  module Models
13
13
  # What a correction request depends on, which it prints as its basis and the agent hands back with the answer:
14
14
  # the base commit, the map's version, each finding's members and problem, what the assessment reported beyond its
@@ -7,8 +7,7 @@ require_relative "member_moves"
7
7
  require_relative "declared_member_removals"
8
8
 
9
9
  module Principles
10
- # The domain: maps, audits and command steps, with every rule a schema cannot express.
11
- # models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
11
  module Models
13
12
  # The changes a correction declares it made to the map after the audit began: the members it moved,
14
13
  # and the members whose role or check a fix changed, which each fixed disposition lists in
@@ -0,0 +1,84 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "answer_place"
6
+ require_relative "answer_text"
7
+ require_relative "recorded_finding"
8
+ require_relative "waits_on"
9
+ require_relative "write_up_pointer"
10
+
11
+ module Principles
12
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
13
+ module Models
14
+ # One decision an answer to start-audit --open-findings gives on an open finding, between full audits: only the
15
+ # fields that change, each kept beside the finding with when and why. Whether the change is right is the agent's
16
+ # judgement; this tool checks its shape.
17
+ class FindingDecision
18
+ # The actions a decision may leave its finding at: those that keep it open. Closing it judges the problem
19
+ # against the text now, which is a full audit's work.
20
+ OPEN_ACTIONS = %w[deferred accepted].freeze #: Array[String]
21
+
22
+ # Each field a decision may give beside its finding_id, with its one-line meaning, which the template of
23
+ # start-audit --open-findings prints at its head in decision_fields, where an agent filling it reads.
24
+ FIELDS = {
25
+ "waits_on" => "One line, on a deferred finding only: whom it now waits on and to decide what. Or null, " \
26
+ "even on a deferred finding, to drop it.",
27
+ "action" => "deferred or accepted, as when the owner rules; its reason becomes the finding's own.",
28
+ "recorded_at" => "Where its write-up is now, in a committed file: {\"path\": ..., \"heading\": ...}, or null.",
29
+ "reason" => "One line saying why, required with any change. A field left out keeps its value; " \
30
+ "decision_fields may be kept or deleted."
31
+ }.freeze #: Hash[String, String]
32
+
33
+ # decision is one entry of the answer's decisions, at place in the answer, on a finding of principle_id's;
34
+ # recorded_at is its new pointer, already located, or nil when it gives none or null.
35
+ #: (Hash[String, untyped], AnswerPlace, principle_id: String, ?recorded_at: WriteUpPointer?) -> void
36
+ def initialize(decision, place, principle_id:, recorded_at: nil)
37
+ @decision = decision
38
+ @place = place
39
+ @principle_id = principle_id
40
+ @recorded_at = recorded_at
41
+ freeze
42
+ end
43
+
44
+ # The id of the finding it decides.
45
+ #: () -> String
46
+ def finding_id = @decision.fetch("finding_id")
47
+
48
+ # finding with this decision's changes made at at, its action before its wait, which is checked against the
49
+ # action it leaves; or finding itself when it changes nothing.
50
+ #: (RecordedFinding, at: String) -> RecordedFinding
51
+ def applied_to(finding, at:)
52
+ acted = @decision.key?("action") ? finding.acting(open_action, at:, reason:) : finding
53
+ acted = acted.pointed_at(@recorded_at, at:, reason:) if @decision.key?("recorded_at")
54
+ return acted unless @decision.key?("waits_on")
55
+
56
+ WaitsOn.new(@decision["waits_on"], action: acted.action).check(code: "invalid_answer",
57
+ subject: "Finding #{finding_id}")
58
+ acted.waiting_on(@decision["waits_on"], at:, reason:)
59
+ end
60
+
61
+ private
62
+
63
+ # The action it gives, refused unless it keeps the finding open.
64
+ #: () -> String
65
+ def open_action
66
+ action = @decision.fetch("action")
67
+ return action if OPEN_ACTIONS.include?(action)
68
+
69
+ raise @place.refusal(Error.new("invalid_answer",
70
+ "action #{action} closes the finding, which only a full audit judges",
71
+ "Give deferred or accepted, or run a full audit: " \
72
+ "#{Error::EXECUTABLE} start-audit #{@principle_id}"))
73
+ end
74
+
75
+ # Why it changes the finding, which the record keeps beside each change.
76
+ #: () -> String
77
+ def reason
78
+ AnswerText.new(@decision["reason"]).required("decision.reason")
79
+ rescue Error => e
80
+ raise @place.child("reason").refusal(e)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -12,7 +12,8 @@ module Principles
12
12
  # now.
13
13
  class FindingWriteUps
14
14
  # What to do about a recorded_at that no longer resolves, worded for a write-up rather than a member.
15
- REPAIR = "Fix the write-up, or point recorded_at at it again with start-audit --write-ups, without a full audit."
15
+ REPAIR = "Fix the write-up, or point recorded_at at it again with start-audit --open-findings, without a full " \
16
+ "audit."
16
17
  # What the repair adds when git detects a rename for the write-up's missing file.
17
18
  RENAMED = " git_detected_rename is git's match for its file, to #{MissingFiles::RENAME_MATCH}".freeze #: String
18
19
 
@@ -5,6 +5,7 @@ require_relative "../error"
5
5
  require_relative "audit_record"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # A principle's first full audit, which one background subagent runs from show-first-audit-brief so the session
10
11
  # that starts it spends little of its context on it: its id, and its record, or nil with none.
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "json_path_query"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The YAML frontmatter at the head of a Markdown file, read as lines and never parsed as YAML, since a
11
11
  # YAML parser over untrusted bytes is attack surface. A field is a top-level `key:` line and the indented,
@@ -4,7 +4,7 @@
4
4
  require_relative "../error"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # A glob the agent names for additional guidance inside this project, never a path outside it.
10
10
  class GuidanceSearchPath
@@ -5,7 +5,7 @@ require_relative "../data/guidance_search_paths_file"
5
5
  require_relative "guidance_search_path"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The additional guidance globs this project records, with one owner for normalized additions and removals.
11
11
  class GuidanceSearchPaths
@@ -42,6 +42,10 @@ module Principles
42
42
  #: (GuidanceSearchPaths) -> bool
43
43
  def same_as?(other) = @globs == other.globs
44
44
 
45
+ # The glob this list records that other did not, which a survey of just its matches reads; nil when none is.
46
+ #: (GuidanceSearchPaths) -> String?
47
+ def added_since(other) = (@globs - other.globs).first
48
+
45
49
  #: () -> String
46
50
  def save
47
51
  @file.write("format" => Data::GuidanceSearchPathsFile::FORMAT, "globs" => @globs)
@@ -5,6 +5,7 @@ require_relative "after_commit_input"
5
5
  require_relative "../data/head_reflog"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # Which repositories' HEAD a shell call moved by committing, each named once, in the order the call's
10
11
  # directories name them, with the commit HEAD named before the move: what report-after-commit reports on. A
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The candidate files git ignores, which this tool names but never reads. A folder git ignores can hold many
8
8
  # copies of instruction files written there by specs or builds, and listing each buries a file ignored on
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "../prose_list"
6
6
 
7
7
  module Principles
8
- # The domain of principles and their maps: each model owns its rules and loads and saves itself through data/.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The instruction field start-audit --instruction names, read whole from the request a full audit asks. Only a
11
11
  # field the request prints an instruction under can be read: the others explain fields it does not hold.
@@ -7,7 +7,7 @@ require_relative "json_path_string"
7
7
  require_relative "json_path_selectors"
8
8
 
9
9
  module Principles
10
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
12
  # A query in this tool's own profile of RFC 9535 JSONPath: from $, name selectors in dot or bracket
13
13
  # form, wildcards, and filters that keep the children whose relative paths equal strings, joined by &&.
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The selector * in a JSONPath query: every member value of an object, or every element of an array.
8
8
  class JsonPathWildcard
@@ -5,7 +5,7 @@ require "strscan"
5
5
  require_relative "../error"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # One quoted name or string in a JSONPath query, read as RFC 9535 writes it: single or double quotes, the
11
11
  # escapes it defines, and no raw control character. Anything else refuses the whole query.
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "audit_record"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The revision of a principle's last completed audit record when a request was printed, or nil when there was
11
11
  # none. An assessment's basis and a correction's carry it, so either answer is refused once that record changed,
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # Where two versions of a member's lines differ: each run of lines one side changed, in order, as a line diff finds
8
8
  # them by their longest common subsequence. The lines both sides share from the start and from the end are never
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The lines a member spans in its file, first to last, as a LocatedText gives them, and whether the member is
8
8
  # its whole file, so two members' spans are compared in one place.
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
5
6
  module Models
6
7
  # Literal loading-scope qualifiers for mapping feedback, distinct from persisted LoadingFacts.
7
8
  class LoadingScope
@@ -6,7 +6,7 @@ require_relative "line_span"
6
6
  require_relative "locator"
7
7
 
8
8
  module Principles
9
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
10
  module Models
11
11
  # The text a locator found now: its file, the lines it spans and the hash of what it says. A Locator says where
12
12
  # to look; this is what was found there, as MemberFile#locate finds it.
@@ -0,0 +1,66 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "../prose_list"
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
+ # How a principle's map differs from the one an audit's request was printed from: each field of the map, and of
12
+ # each member both maps hold, as it was and is now, which a stale request's refusal names.
13
+ class MapChange
14
+ #: (Principle, Principle) -> void
15
+ def initialize(base, current)
16
+ @base = base
17
+ @current = current
18
+ freeze
19
+ end
20
+
21
+ # Each change as a clause, such as: CLAUDE.md#Names's role was "a" and is now "b".
22
+ #: () -> String
23
+ def to_s = ProseList.new(clauses).to_s
24
+
25
+ # Whether it names no change, as when only the members' order, or which members the map holds, changed.
26
+ #: () -> bool
27
+ def empty? = clauses.empty?
28
+
29
+ # What an answer carried to a new request must judge again: each member whose entry changed, or, when a field of
30
+ # the map itself changed, every member.
31
+ #: () -> String
32
+ def to_judge_again
33
+ return "every member again against the map as it is now" unless map_fields.empty?
34
+
35
+ changed = @current.members.select { |member| member_fields_of(member).any? }.map(&:id)
36
+ entries = changed.one? ? "its map entry as it is" : "their map entries as they are"
37
+ "#{ProseList.new(changed)} again against #{entries} now"
38
+ end
39
+
40
+ private
41
+
42
+ #: () -> Array[String]
43
+ def clauses = map_fields + member_fields
44
+
45
+ #: () -> Array[String]
46
+ def map_fields = differing("its", @base.to_h.except("members"), @current.to_h.except("members"))
47
+
48
+ #: () -> Array[String]
49
+ def member_fields = @current.members.flat_map { |member| member_fields_of(member) }
50
+
51
+ # How member's entry differs from the one the base map holds under its key, none when it holds none.
52
+ #: (Member) -> Array[String]
53
+ def member_fields_of(member)
54
+ was = @base.members.with_key(member.key)
55
+ was ? differing("#{member.id}'s", was.to_h, member.to_h) : []
56
+ end
57
+
58
+ #: (String, Hash[String, untyped], Hash[String, untyped]) -> Array[String]
59
+ def differing(whose, was, now)
60
+ (was.keys | now.keys).reject { |field| was[field] == now[field] }.map do |field|
61
+ "#{whose} #{field} was #{JSON.generate(was[field])} and is now #{JSON.generate(now[field])}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -144,6 +144,10 @@ module Principles
144
144
  @files.relative(id)
145
145
  end
146
146
 
147
+ # Map id's file and each file holding one of its members, which a full audit judges as committed.
148
+ #: (String, PrincipleMembers) -> Array[String]
149
+ def audited_files(id, members) = [file(id), *members.paths]
150
+
147
151
  # The file map id was kept in under the folder's earlier name, relative to the project.
148
152
  #: (String) -> String
149
153
  def earlier_file(id)
@@ -3,15 +3,36 @@
3
3
 
4
4
  require_relative "member_file"
5
5
  require_relative "frontmatter_fields"
6
+ require_relative "prose_line"
6
7
 
7
8
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
10
  module Models
10
11
  # A Markdown file, where a member may be a section: a heading and what follows it, up to the next heading
11
12
  # at its level or above.
12
13
  class MarkdownFile < MemberFile
14
+ # The last line of the paragraph or list item that a passage named by its opening alone maps only the first
15
+ # line of, so the agent can judge whether it meant the whole; nil when no line continues it.
16
+ #: (Locator) -> Integer?
17
+ def continues_to(locator)
18
+ return unless locator.starting_at && !locator.ending_at
19
+
20
+ last = locate(locator).last_line
21
+ ending = block_end(last)
22
+ ending unless ending == last
23
+ end
24
+
13
25
  private
14
26
 
27
+ # The last line of the paragraph or list item that line, counted from 1, is in, read on from it; the line
28
+ # itself for a heading, a block of its own line.
29
+ #: (Integer) -> Integer
30
+ def block_end(line)
31
+ return line if ProseLine.new(@text.lines.fetch(line - 1)).heading?
32
+
33
+ line + @text.lines.drop(line).take_while { ProseLine.new(it).continues? }.length
34
+ end
35
+
15
36
  # The frontmatter field the reference's query names, or the section under its heading, or the whole text.
16
37
  #: (Array[String], Locator) -> [Integer, Integer]
17
38
  def region(lines, locator)
@@ -7,7 +7,7 @@ require_relative "meta_principle"
7
7
  require_relative "report_hooks"
8
8
 
9
9
  module Principles
10
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
12
  # One member of a principle as its map records it: a file, a Markdown section of it, or a passage
13
13
  # starting at a quoted first line. Its id names all three, so an agent can read where the member is
@@ -5,7 +5,7 @@ require_relative "line_span"
5
5
  require_relative "member"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # A member of another principle's map whose text shares a line with one located member: its principle, id,
11
11
  # role there and lines, and how its lines stand to the located member's: the same lines, all of them, within
@@ -9,7 +9,7 @@ require_relative "located_text"
9
9
  require_relative "write_up_opening"
10
10
 
11
11
  module Principles
12
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
12
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
13
13
  module Models
14
14
  # The text of one project file, as the type that knows how to find a member in it. It holds text, not a
15
15
  # file, so the same rules apply to a file on disk and to the file at a commit. Each type finds the region
@@ -78,6 +78,11 @@ module Principles
78
78
  found
79
79
  end
80
80
 
81
+ # The last line of the paragraph or list item that a passage named by its opening alone maps only the first
82
+ # line of; nil here, since only Markdown has such blocks, which MarkdownFile finds.
83
+ #: (Locator) -> Integer?
84
+ def continues_to(_locator) = nil
85
+
81
86
  # The lines of the region locator names, as the agent reads them.
82
87
  #: (Locator) -> Array[String]
83
88
  def lines_of(locator)
@@ -4,7 +4,7 @@
4
4
  require_relative "recorded_entry"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # The member hashes an audit record holds, read from a record a later copy wrote that this copy's schema refuses,
10
10
  # for list-member-problems to compare its members with, read-only. Only those fields are read, each entry
@@ -19,7 +19,7 @@ module Principles
19
19
  freeze
20
20
  end
21
21
 
22
- # Each member's hash by the key it was recorded under, as RecordedMembers#hashes_by_key gives a readable one.
22
+ # Each member's hash by the key it was recorded under, as RecordedMembers#hashes gives a readable one.
23
23
  #: Hash[String, String]
24
24
  attr_reader :by_key
25
25
 
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The commits that changed one member's own text since this tool last knew it, newest first. The walk goes
8
8
  # back from HEAD and stops at the first commit whose text for the member hashes to the baseline, so a fix
@@ -5,7 +5,7 @@ require_relative "changed_regions"
5
5
  require_relative "line_diff"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # A member's own lines at its baseline and now, as a one-member audit's request shows them, so the agent reads
11
11
  # the change its quotes are checked against and not the rest of an edit to the file. A long member, such
@@ -5,6 +5,7 @@ require_relative "member_loads"
5
5
  require_relative "loading_scope"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # One map's per-member loading scopes and the scope an added member newly represents.
10
11
  class MemberLoadingScopes
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "json"
5
+ require_relative "member"
5
6
  require_relative "project_history"
6
7
 
7
8
  module Principles
@@ -9,9 +10,8 @@ module Principles
9
10
  module Models
10
11
  # One member key's ordered historical placements and its oldest locatable mapping baseline.
11
12
  class MemberMappingRun
12
- #: (String, Array[[String, Hash[String, untyped]]]) -> void
13
- def initialize(key, entries)
14
- @key = key.dup.freeze #: String
13
+ #: (Array[[String, Hash[String, untyped]]]) -> void
14
+ def initialize(entries)
15
15
  @entries = JSON.parse(JSON.generate(entries), freeze: true) #: Array[[String, Hash[String, untyped]]]
16
16
  freeze
17
17
  end
@@ -19,7 +19,7 @@ module Principles
19
19
  #: (ProjectHistory) -> Hash[String, String]?
20
20
  def baseline(history)
21
21
  @entries.reverse_each do |sha, fields|
22
- hash = history.at(sha).hashes_by_key([fields])[@key] or next
22
+ hash = history.at(sha).hash_of(Member.new(fields)) or next
23
23
 
24
24
  return { "commit" => sha, "sha256" => hash }
25
25
  end