principles 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/cli.rb +3 -1
  4. data/lib/principles/command_line.rb +38 -26
  5. data/lib/principles/command_routes.rb +11 -4
  6. data/lib/principles/controllers/acknowledgement.rb +93 -17
  7. data/lib/principles/controllers/answer.rb +45 -76
  8. data/lib/principles/controllers/answer_phase.rb +54 -0
  9. data/lib/principles/controllers/assessment.rb +46 -11
  10. data/lib/principles/controllers/audit.rb +17 -6
  11. data/lib/principles/controllers/audit_completion.rb +9 -5
  12. data/lib/principles/controllers/command.rb +5 -4
  13. data/lib/principles/controllers/correction.rb +22 -10
  14. data/lib/principles/controllers/full_audit_request.rb +11 -1
  15. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  16. data/lib/principles/controllers/inventory.rb +15 -29
  17. data/lib/principles/controllers/mapping.rb +9 -1
  18. data/lib/principles/controllers/member_addition.rb +65 -0
  19. data/lib/principles/controllers/member_entries.rb +6 -24
  20. data/lib/principles/controllers/member_problems_report.rb +13 -6
  21. data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
  22. data/lib/principles/controllers/members_to_assess.rb +21 -13
  23. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  24. data/lib/principles/controllers/repoint.rb +22 -23
  25. data/lib/principles/controllers/survey.rb +60 -0
  26. data/lib/principles/data/audit_files.rb +4 -0
  27. data/lib/principles/data/bounded_file.rb +9 -4
  28. data/lib/principles/data/candidate_files_found.rb +48 -13
  29. data/lib/principles/data/command-steps.json +85 -24
  30. data/lib/principles/data/committed_tree.rb +84 -0
  31. data/lib/principles/data/first_parent_log.rb +48 -0
  32. data/lib/principles/data/first_parent_range.rb +122 -0
  33. data/lib/principles/data/git_command.rb +37 -0
  34. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  35. data/lib/principles/data/map_files.rb +35 -10
  36. data/lib/principles/data/principles_directory.rb +40 -0
  37. data/lib/principles/data/principles_subfolder.rb +39 -16
  38. data/lib/principles/data/project_files.rb +22 -11
  39. data/lib/principles/data/repository.rb +55 -29
  40. data/lib/principles/data/requested_candidate_files.rb +43 -0
  41. data/lib/principles/data/running_version.rb +3 -5
  42. data/lib/principles/data/schema_check.rb +16 -6
  43. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +18 -5
  44. data/lib/principles/data/schemas/answer-guide.schema.json +255 -68
  45. data/lib/principles/data/schemas/audit-record.schema.json +10 -1
  46. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  47. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  48. data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
  49. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  50. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  51. data/lib/principles/data/verified_head.rb +162 -0
  52. data/lib/principles/invocation_options.rb +3 -3
  53. data/lib/principles/models/acknowledgement.rb +95 -84
  54. data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
  55. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  56. data/lib/principles/models/answer_place.rb +4 -0
  57. data/lib/principles/models/assessment_answer.rb +0 -45
  58. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  59. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  60. data/lib/principles/models/audit_record.rb +12 -16
  61. data/lib/principles/models/audit_records.rb +52 -23
  62. data/lib/principles/models/candidate_files.rb +44 -10
  63. data/lib/principles/models/candidate_inventory.rb +69 -8
  64. data/lib/principles/models/candidate_outline.rb +195 -0
  65. data/lib/principles/models/captured_head.rb +72 -0
  66. data/lib/principles/models/carried_member.rb +42 -0
  67. data/lib/principles/models/check_since_last_audit.rb +20 -11
  68. data/lib/principles/models/command_steps.rb +17 -1
  69. data/lib/principles/models/declared_map_changes.rb +29 -12
  70. data/lib/principles/models/declared_member_removals.rb +75 -0
  71. data/lib/principles/models/disposition.rb +4 -2
  72. data/lib/principles/models/fix_only_fields.rb +12 -0
  73. data/lib/principles/models/frontmatter_fields.rb +9 -8
  74. data/lib/principles/models/guidance_search_path.rb +26 -0
  75. data/lib/principles/models/guidance_search_paths.rb +57 -0
  76. data/lib/principles/models/instruction_named.rb +35 -0
  77. data/lib/principles/models/left_as_printed.rb +39 -0
  78. data/lib/principles/models/line_span.rb +6 -0
  79. data/lib/principles/models/loaded_files.rb +1 -2
  80. data/lib/principles/models/loading_scope.rb +61 -0
  81. data/lib/principles/models/locator.rb +6 -0
  82. data/lib/principles/models/mapped_principles.rb +39 -37
  83. data/lib/principles/models/member_assessments.rb +9 -31
  84. data/lib/principles/models/member_file.rb +20 -47
  85. data/lib/principles/models/member_hashes_as_written.rb +10 -6
  86. data/lib/principles/models/member_history.rb +7 -5
  87. data/lib/principles/models/member_lines.rb +63 -15
  88. data/lib/principles/models/member_loading_scopes.rb +49 -0
  89. data/lib/principles/models/member_loads.rb +4 -0
  90. data/lib/principles/models/member_mapping_run.rb +30 -0
  91. data/lib/principles/models/member_moves.rb +4 -0
  92. data/lib/principles/models/member_problems.rb +63 -33
  93. data/lib/principles/models/member_region.rb +129 -0
  94. data/lib/principles/models/member_repair_moves.rb +52 -0
  95. data/lib/principles/models/member_snapshots.rb +14 -1
  96. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  97. data/lib/principles/models/meta_principle.rb +14 -0
  98. data/lib/principles/models/missing_files.rb +2 -2
  99. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  100. data/lib/principles/models/other_templates_placeholders.rb +81 -42
  101. data/lib/principles/models/outline_budget.rb +142 -0
  102. data/lib/principles/models/outline_group.rb +31 -0
  103. data/lib/principles/models/outline_section.rb +56 -0
  104. data/lib/principles/models/principle.rb +14 -7
  105. data/lib/principles/models/principle_file_revision.rb +48 -0
  106. data/lib/principles/models/principle_history.rb +46 -19
  107. data/lib/principles/models/principle_lineage.rb +118 -0
  108. data/lib/principles/models/principle_map_revision.rb +39 -0
  109. data/lib/principles/models/principle_mapping_history.rb +132 -0
  110. data/lib/principles/models/principle_members.rb +25 -0
  111. data/lib/principles/models/principle_predecessor.rb +45 -0
  112. data/lib/principles/models/principle_publication.rb +177 -0
  113. data/lib/principles/models/principle_revision.rb +104 -0
  114. data/lib/principles/models/prior_decision_fields.rb +3 -2
  115. data/lib/principles/models/prior_finding_decision.rb +14 -4
  116. data/lib/principles/models/problem_report.rb +17 -5
  117. data/lib/principles/models/project.rb +46 -39
  118. data/lib/principles/models/project_history.rb +45 -25
  119. data/lib/principles/models/quoted_change.rb +137 -0
  120. data/lib/principles/models/record_format.rb +12 -2
  121. data/lib/principles/models/recorded_entry.rb +6 -0
  122. data/lib/principles/models/recorded_hashes.rb +7 -3
  123. data/lib/principles/models/recorded_members.rb +27 -15
  124. data/lib/principles/models/refusal_before_shape.rb +21 -0
  125. data/lib/principles/models/repoint.rb +13 -0
  126. data/lib/principles/models/reported_check.rb +5 -14
  127. data/lib/principles/models/sent_answer.rb +61 -0
  128. data/lib/principles/models/shape_problems_beside.rb +40 -0
  129. data/lib/principles/models/submitted_answer.rb +34 -0
  130. data/lib/principles/models/survey_search_paths.rb +26 -0
  131. data/lib/principles/models/template_placeholders.rb +34 -4
  132. data/lib/principles/models/text_within.rb +55 -0
  133. data/lib/principles/models/unchecked_members.rb +76 -0
  134. data/lib/principles/models/uncommitted_files.rb +50 -0
  135. data/lib/principles/models/unknown_principle.rb +29 -0
  136. data/lib/principles/models/write_up_opening.rb +21 -4
  137. data/lib/principles/positional_arguments.rb +37 -0
  138. data/lib/principles/session_start_options.rb +2 -2
  139. data/lib/principles/start_audit_options.rb +19 -4
  140. data/lib/principles/version.rb +2 -2
  141. data/lib/principles/views/acknowledgement_result.rb +23 -11
  142. data/lib/principles/views/added_member.rb +41 -0
  143. data/lib/principles/views/answered_request.rb +21 -0
  144. data/lib/principles/views/assessed_members.rb +43 -10
  145. data/lib/principles/views/assessment_request.rb +91 -31
  146. data/lib/principles/views/audit_result.rb +40 -28
  147. data/lib/principles/views/candidate_files_result.rb +85 -19
  148. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  149. data/lib/principles/views/check_notes.rb +44 -0
  150. data/lib/principles/views/check_result_template.rb +14 -23
  151. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  152. data/lib/principles/views/correction_request.rb +32 -1
  153. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  154. data/lib/principles/views/instruction.rb +74 -0
  155. data/lib/principles/views/json_with_entries_on_lines.rb +59 -0
  156. data/lib/principles/views/loads_to_check_result.rb +2 -2
  157. data/lib/principles/views/map_added_to.rb +56 -2
  158. data/lib/principles/views/map_result.rb +23 -43
  159. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  160. data/lib/principles/views/member_change_since_baseline.rb +23 -5
  161. data/lib/principles/views/member_repairs.rb +22 -52
  162. data/lib/principles/views/members_a_commit_changed.rb +16 -6
  163. data/lib/principles/views/new_loading_scope.rb +31 -0
  164. data/lib/principles/views/one_member_check_result_template.rb +47 -0
  165. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  166. data/lib/principles/views/open_findings_line.rb +77 -23
  167. data/lib/principles/views/principle_read_result.rb +24 -29
  168. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  169. data/lib/principles/views/prior_findings_result.rb +23 -15
  170. data/lib/principles/views/problem_lines.rb +3 -1
  171. data/lib/principles/views/problem_result.rb +8 -3
  172. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  173. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  174. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -48
  175. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  176. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  177. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
  178. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  179. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  180. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  181. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  182. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  183. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  184. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  185. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +16 -3
  186. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  187. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  188. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  189. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  190. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  191. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +11 -5
  192. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  193. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  194. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  195. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  196. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  197. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  198. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  199. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  200. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  201. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  202. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +55 -7
  203. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +9 -8
  204. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  205. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
  206. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  207. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  208. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  209. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +27 -1
  210. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  211. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
  212. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
  213. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  214. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  215. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  216. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  217. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  218. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
  219. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  220. data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
  221. data/lib/principles/views/request_part.rb +16 -8
  222. data/lib/principles/views/request_parts.rb +4 -0
  223. metadata +92 -7
  224. data/lib/principles/models/candidate_listing.rb +0 -32
  225. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  226. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
  227. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -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
- #: (id: String, history: ProjectHistory, principles: MappedPrinciples, record: AuditRecord?) -> void
20
- def initialize(id:, history:, principles:, record:)
21
- @id = id
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
@@ -34,26 +30,39 @@ module Principles
34
30
  # changed_in may then name a later commit than the one that set the check: the review is still asked for.
35
31
  #: (Member, String) -> Hash[String, untyped]
36
32
  def of(member, check)
37
- ran = @record&.check_run_for(member.key)
33
+ status = status_of(member.key, check)
38
34
  review = review_of(member.key)
39
- return { "status" => "unchanged", **review } if ran == check
35
+ return { "status" => "unchanged", **review } if status == :unchanged
40
36
 
41
37
  changed_in = commit_that_set(member.key, check)
42
- return { "status" => "new", "changed_in" => changed_in } unless ran
38
+ return { "status" => "new", "changed_in" => changed_in } if %i[new not_run].include?(status)
43
39
 
40
+ ran = @record&.check_run_for(member.key)
44
41
  last_run_review = review.slice("review_basis").transform_keys { "last_run_review_basis" }
45
42
  { "status" => "changed", "last_run" => ran, **last_run_review, "changed_in" => changed_in }
46
43
  end
47
44
 
45
+ # The member's check and how it stands to the last audit's, as a request lists them beside the member; nothing
46
+ # for a member without a check.
47
+ #: (Member) -> Hash[String, untyped]
48
+ def entry(member)
49
+ check = member.check or return {}
50
+ { "check" => check, "check_since_last_audit" => of(member, check) }
51
+ end
52
+
48
53
  private
49
54
 
55
+ # How check stands to the one the last audit ran, as its record says; new when there is no record.
56
+ #: (String, String) -> Symbol
57
+ def status_of(key, check) = @record ? @record.members.check_since(key, check) : :new
58
+
50
59
  # The line the last audit's record keeps for what the review of its run rested on, and since when (D63).
51
60
  #: (String) -> Hash[String, untyped]
52
61
  def review_of(key) = @record&.check_review_for(key) || {}
53
62
 
54
63
  #: (String, String) -> String?
55
64
  def commit_that_set(key, check)
56
- run = PrincipleHistory.new(id: @id, history: @history, principles: @principles).runs([key]).fetch(key)
65
+ run = @principle_history.runs([key]).fetch(key)
57
66
  run.take_while { |_sha, fields| Member.new(fields).check == check }.last&.first
58
67
  end
59
68
  end
@@ -133,6 +133,9 @@ module Principles
133
133
  # The named options it takes, without their dashes, besides --project and --help.
134
134
  #: Array[String]
135
135
  attr_reader :options
136
+ # The named options it cannot run without, which the command line refuses together with any missing argument.
137
+ #: Array[String]
138
+ attr_reader :requires
136
139
  #: String
137
140
  attr_reader :summary
138
141
  #: String
@@ -146,6 +149,7 @@ module Principles
146
149
  @usage = data.fetch("usage") #: String
147
150
  @group = data.fetch("group") #: String
148
151
  @options = data.fetch("options").freeze #: Array[String]
152
+ @requires = data.fetch("requires", []).freeze #: Array[String]
149
153
  @summary = data.fetch("summary") #: String
150
154
  @help = data.fetch("help") #: String
151
155
  @steps = steps.freeze #: Array[Step]
@@ -162,6 +166,17 @@ module Principles
162
166
  following ? [following] : []
163
167
  end
164
168
 
169
+ # The first rule of its own entry the command breaks, or nil when it keeps them all.
170
+ #: () -> String?
171
+ def fault
172
+ ids = @steps.map(&:id)
173
+ return "#{@name} repeats a step id" unless ids.uniq == ids
174
+
175
+ # The command line refuses an option a command does not take, so it could never be given.
176
+ untaken = @requires - @options
177
+ "#{@name} requires #{untaken.join(", ")}, which it does not take" if untaken.any?
178
+ end
179
+
165
180
  #: (String) -> Step
166
181
  def find(id)
167
182
  @steps.find { |step| step.id == id } || raise(KeyError, "#{@name} has no step #{id}")
@@ -244,8 +259,9 @@ module Principles
244
259
  #: (Command, Array[String]) -> void
245
260
  def check_command(command, names)
246
261
  writes(command)
262
+ fault = command.fault
263
+ refuse(fault) if fault
247
264
  ids = command.steps.map(&:id)
248
- refuse("#{command.name} repeats a step id") unless ids.uniq == ids
249
265
  command.steps.each { |step| check_step("#{command.name}/#{step.id}", step, names, ids) }
250
266
  end
251
267
 
@@ -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 map at the base commit, which may also hold
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 changes an answer declares: its moved_members and each disposition's changed_map_entries.
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
- "changed_map_entries needs git, to read the map #{principle_id} began from",
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
- expected = @entries.reduce(@moves.applied(base, current)) { |map, id| claimed_entry(map, current, id) }
67
- raise unexplained(current.id, map_file) unless with_added(expected, current).version == current.version
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
@@ -79,15 +85,23 @@ module Principles
79
85
  @entries.map { |id| changed_fields(id, moved.member(id), current.member(id)) }
80
86
  end
81
87
 
82
- # The map file, when a fix changed a member's role or check in it or the correction added members to it, so the
83
- # agent commits it too (T69).
88
+ # The map file, when the correction moved a member in it, even under its own id (#1100), a fix changed a
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
- @entries.empty? && added.empty? ? [] : [map_file]
92
+ empty? && added.empty? ? [] : [map_file]
87
93
  end
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)
@@ -146,8 +160,11 @@ module Principles
146
160
  def stale_map(principle_id, map_file)
147
161
  Error.new("stale_map", "The map of #{principle_id} changed during this audit",
148
162
  "If you moved a member to fix a finding, declare it in the answer's moved_members as " \
149
- "{\"from\": OLD_ID, \"to\": NEW_ID}; if a fix changed a member's role or check, list the " \
150
- "member's id in that fixed disposition's changed_map_entries. In git, a member you added with " \
163
+ "{\"from\": OLD_ID, \"to\": NEW_ID}, and a move that kept its id, as narrowing or widening a " \
164
+ "passage, as {\"from\": ID, \"to\": ID}; if a fix changed a member's role or check, list the " \
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 " \
151
168
  "add-member needs no declaration, as long as nothing else changed.\n" \
152
169
  "Otherwise, start a fresh audit: #{Error::EXECUTABLE} start-audit #{principle_id}", map_file)
153
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 and evidence and gives a reassessment; deferred gives recorded_at, " \
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.
@@ -59,6 +59,15 @@ module Principles
59
59
  raise unless e.payload.fetch("code") == "field_not_found"
60
60
  end
61
61
 
62
+ # The index of the --- that closes the frontmatter, or nil when the text opens with none; the
63
+ # file's body starts after it.
64
+ #: () -> Integer?
65
+ def closing_line
66
+ return nil unless @lines.first&.chomp == "---"
67
+
68
+ (1...@lines.length).find { |i| @lines.fetch(i).chomp == "---" }
69
+ end
70
+
62
71
  private
63
72
 
64
73
  # Each top-level field's name and line range, in order; refused on a line this tool would misread.
@@ -71,14 +80,6 @@ module Principles
71
80
  end
72
81
  end
73
82
 
74
- # The index of the --- that closes the frontmatter, or nil when the text opens with none.
75
- #: () -> Integer?
76
- def closing_line
77
- return nil unless @lines.first&.chomp == "---"
78
-
79
- (1...@lines.length).find { |i| @lines.fetch(i).chomp == "---" }
80
- end
81
-
82
83
  # The last line from start to last that is not blank, so trailing blank lines stay out of a field.
83
84
  #: (Integer, Integer) -> Integer
84
85
  def last_filled(start, last)
@@ -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
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+
7
+ module Principles
8
+ # The domain of principles and their maps: each model owns its rules and loads and saves itself through data/.
9
+ module Models
10
+ # The instruction field start-audit --instruction names, read whole from the request a full audit asks (D81 step
11
+ # 2, #983). Only a field the request prints an instruction under can be read: the others explain fields it does
12
+ # not hold.
13
+ class InstructionNamed
14
+ #: (String, principle_id: String, printed: Array[String]) -> void
15
+ def initialize(field, principle_id:, printed:)
16
+ @field = field
17
+ @id = principle_id
18
+ @printed = printed
19
+ freeze
20
+ end
21
+
22
+ # The field, refused unless the request prints an instruction under it.
23
+ #: () -> String
24
+ def field
25
+ return @field if @printed.include?(@field)
26
+
27
+ refusal = Error.new("unknown_instruction",
28
+ "This request prints no instruction named #{@field}. It prints #{ProseList.new(@printed)}.",
29
+ "")
30
+ raise refusal.ending_with([Error::RepairCommand.new(purpose: "To print one whole", command: "start-audit",
31
+ values: [@id], usage: "--instruction FIELD")])
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "shape_problems_beside"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # The judgements an answer leaves as its template printed them, each named with its pointer, which the answer
12
+ # refuses in one refusal, so a copied template takes one repair (#991, #1010, #1040).
13
+ class LeftAsPrinted
14
+ # The problem with a judgement sent back as its placeholder.
15
+ UNCHANGED = "is the template's placeholder, unchanged" #: String
16
+
17
+ # pointers holds each judgement left as printed, by its name, with its JSON pointer.
18
+ #: (Hash[String, String]) -> void
19
+ def initialize(pointers)
20
+ @pointers = pointers.freeze #: Hash[String, String]
21
+ freeze
22
+ end
23
+
24
+ # Refuses the answer naming each judgement left as printed, then each of besides, problems its shape has
25
+ # elsewhere, so one refusal names every repair (#1106); one at or under a pointer named is left out, since
26
+ # writing the judgement repairs it. Nothing when none is left as printed, so the shape's own refusal names them.
27
+ #: (?besides: Array[Hash[String, String]]) -> void
28
+ def refuse(besides: [])
29
+ return if @pointers.empty?
30
+
31
+ elsewhere = ShapeProblemsBeside.new(besides, named: @pointers.values)
32
+ raise Error.new("invalid_answer", elsewhere.message("Still to write: #{ProseList.new(@pointers.keys)}"),
33
+ "#{elsewhere.repair("Replace each placeholder named in fields with your own judgement",
34
+ ", and repair each other field listed there")}.",
35
+ fields: @pointers.values.map { { "pointer" => it, "problem" => UNCHANGED } } + elsewhere.fields)
36
+ end
37
+ end
38
+ end
39
+ 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" => { "host" => "claude_code", "kind" => "documented_prediction",
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