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,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
- unique(Principle.new(id, @files.read(id)))
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
- unique(Principle.new(id, @files.parse(id, text, commit: commit)), commit)
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
- refuse_meta_principle_id(id)
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) || !started_by_setup?(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
- # Whether principle id's map is started by setup and written by the add-member it prints, never by
129
- # create-principle: only the meta-principle's, whose description and activation ship with the tool (T74).
130
- #: (String) -> bool
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
- # map, refused when two of its members share an id or a key, as PrincipleMembers#refuse_repeats says.
134
- #: (Principle, ?String?) -> Principle
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 Error.new("unknown_principle", "No map named #{id}",
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
@@ -12,6 +12,7 @@ require_relative "misspelt_member_id"
12
12
  require_relative "record_judged_against"
13
13
  require_relative "reported_check"
14
14
  require_relative "template_placeholders"
15
+ require_relative "unchecked_members"
15
16
 
16
17
  module Principles
17
18
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -31,7 +32,8 @@ module Principles
31
32
  # delivery gives none (#1010).
32
33
  SIGHTING = TemplatePlaceholders.new(
33
34
  { "observation" => "Only with delivery observed: what you saw the member do, where, and what you did not see",
34
- "observed_at" => "Only for a sighting before this audit: when, in UTC, or a dated record's date" }
35
+ "observed_at" => "Only for a sighting before this audit: when, in UTC, or a dated record's date " \
36
+ "at 00:00:00Z" }
35
37
  ) #: TemplatePlaceholders
36
38
 
37
39
  # assessments is the answer's member_assessments; members are the mapped members, with each checked one's
@@ -60,21 +62,6 @@ module Principles
60
62
  assessments.each_with_index { |assessment, index| member_assessment(assessment, place_of(assessment, index)) }
61
63
  end
62
64
 
63
- # Each judgement an assessment leaves as its template printed it, named by whose it is and what, with its
64
- # pointer: its assessment, and an observed delivery's observation, which AssessmentAnswer refuses with any other
65
- # judgement left so, in one refusal (#991, #1010).
66
- #: () -> Hash[String, String]
67
- def left_as_printed
68
- return {} unless @sent.is_a?(Array)
69
-
70
- @sent.each_with_index.flat_map do |assessment, index|
71
- next [] unless assessment.is_a?(Hash)
72
-
73
- place = place_of(assessment, index)
74
- unwritten_fields(assessment).map { |field| ["#{place.subject} #{field}", place.child(field).pointer] }
75
- end.to_h
76
- end
77
-
78
65
  # The result reported for each checked member's check, by member id, once each has been checked. Call it after
79
66
  # check, which refuses an unmapped id first: finding the command the record ran needs each member's key.
80
67
  #: () -> Hash[String, Hash[String, untyped]]
@@ -101,15 +88,6 @@ module Principles
101
88
 
102
89
  private
103
90
 
104
- # The fields of assessment, as sent, that are still the text the template printed there and must be written:
105
- # its assessment, and an observed delivery's observation.
106
- #: (Hash[String, untyped]) -> Array[String]
107
- def unwritten_fields(assessment)
108
- [("assessment" if assessment["assessment"] == PLACEHOLDER),
109
- ("observation" if assessment["delivery"] == "observed" &&
110
- SIGHTING.left?("observation", assessment["observation"]))].compact
111
- end
112
-
113
91
  # assessments without the sighting fields each leaves as printed, which it does not give (#1010).
114
92
  #: (untyped) -> untyped
115
93
  def given(assessments)
@@ -132,9 +110,7 @@ module Principles
132
110
 
133
111
  # The place of the assessment at index in the answer, whose fields each refusal about it points into.
134
112
  #: (untyped, Integer) -> AnswerPlace
135
- def place_of(assessment, index)
136
- AnswerPlace.new("/member_assessments/#{index}", "Member #{assessment["member_id"]}")
137
- end
113
+ def place_of(assessment, index) = AnswerPlace.member_assessment(index, assessment["member_id"])
138
114
 
139
115
  #: (untyped, AnswerPlace) -> void
140
116
  def member_assessment(assessment, place)
@@ -175,13 +151,15 @@ module Principles
175
151
  "the request asks to judge it: judge_because #{reason}" if reason
176
152
  end
177
153
 
178
- # The result reported for the member assessed at place, checked against its check.
154
+ # The result reported for the member assessed at place, checked against its check; nil for a member with none,
155
+ # whose assessment UncheckedMembers refuses if it gives one.
179
156
  #: (untyped, AnswerPlace) -> Hash[String, untyped]?
180
157
  def reported(assessment, place)
181
158
  id = assessment["member_id"]
182
159
  key = @members.found(id).key
183
- ReportedCheck.new(place, @members.check(id), ran: @judged_against&.check_run_for(key),
184
- kept: @judged_against&.check_review_for(key) || {})
160
+ check = @members.check(id) or return UncheckedMembers.new(@members).refuse_at(place, assessment["check_result"])
161
+ ReportedCheck.new(place, check, ran: @judged_against&.check_run_for(key),
162
+ kept: @judged_against&.check_review_for(key) || {})
185
163
  .result(assessment["check_result"])
186
164
  end
187
165
  end
@@ -4,6 +4,8 @@
4
4
  require "digest"
5
5
  require_relative "../error"
6
6
  require_relative "locator"
7
+ require_relative "member_region"
8
+ require_relative "line_span"
7
9
  require_relative "write_up_opening"
8
10
 
9
11
  module Principles
@@ -55,10 +57,27 @@ module Principles
55
57
  first, last = region(lines, locator)
56
58
  selected = lines[first...last].to_a.join
57
59
  start_text = locator.starting_at
58
- first, last, selected = passage(lines, first, selected, start_text, locator.ending_at) if start_text
60
+ if start_text
61
+ selected_region = MemberRegion.new(self, span: LineSpan.new(first + 1, last))
62
+ first, last, selected = selected_region.passage(start_text, locator.ending_at)
63
+ end
59
64
  snapshot(locator, selected, first + 1, last)
60
65
  end
61
66
 
67
+ # Only a newly supplied add/move location needs an unambiguous ending; existing references keep lookup.
68
+ #: (Locator) -> Hash[String, untyped]
69
+ def locate_for_authoring(locator)
70
+ found = locate(locator)
71
+ opening = locator.starting_at
72
+ ending = locator.ending_at
73
+ if opening && ending
74
+ first, last = region(@text.lines, locator)
75
+ selected_region = MemberRegion.new(self, span: LineSpan.new(first + 1, last))
76
+ selected_region.check_authored_ending(opening, ending)
77
+ end
78
+ found
79
+ end
80
+
62
81
  # The lines of the region locator names, as the agent reads them (D33).
63
82
  #: (Locator) -> Array[String]
64
83
  def lines_of(locator)
@@ -102,52 +121,6 @@ module Principles
102
121
  def region(lines, locator)
103
122
  raise NotImplementedError, "#{self.class} names no region"
104
123
  end
105
-
106
- # Narrows a member to a passage of its section, or of the whole text. starting_at must occur exactly
107
- # once. With ending_at, the passage runs from the start of that match to the end of the first ending_at
108
- # after it; without, to the end of the line it starts on. Anchors, never line numbers, so the passage
109
- # stays found while text around and inside it changes. A lost anchor is refused, never widened to the
110
- # whole file. Returns the passage's first and last lines, counted from the start of the text, and the
111
- # passage.
112
- #: (Array[String], Integer, String, String, String?) -> [Integer, Integer, String]
113
- def passage(lines, first, selected, start_text, end_text)
114
- start = only_opening(selected, start_text)
115
- found = selected[start...passage_end(selected, start, start_text, end_text)].to_s
116
- line = @text[0, lines[0...first].to_a.join.length + start].to_s.count("\n")
117
- [line, line + line_count(found), found]
118
- end
119
-
120
- # How many lines a passage spans, counting a last line with no line break.
121
- #: (String) -> Integer
122
- def line_count(found)
123
- found.count("\n") + (found.end_with?("\n") ? 0 : 1)
124
- end
125
-
126
- #: (String, String) -> Integer
127
- def only_opening(text, start_text)
128
- matches = text.scan(start_text).length
129
- return text.index(start_text).to_i if matches == 1
130
- if matches.zero?
131
- raise Error.new("passage_not_found", "The passage starting #{start_text.inspect} is not in the file",
132
- "Quote the passage's opening text exactly.", @path)
133
- end
134
-
135
- raise Error.new("ambiguous_passage", "#{start_text.inspect} occurs #{matches} times",
136
- "Quote more of the passage's start so it occurs once.", @path)
137
- end
138
-
139
- #: (String, Integer, String, String?) -> Integer
140
- def passage_end(text, start, start_text, end_text)
141
- return (text.index("\n", start) || (text.length - 1)) + 1 unless end_text
142
-
143
- found = text.index(end_text, start + start_text.length)
144
- unless found
145
- raise Error.new("passage_end_not_found", "No #{end_text.inspect} after #{start_text.inspect}",
146
- "Quote the passage's closing text exactly.", @path)
147
- end
148
-
149
- found + end_text.length
150
- end
151
124
  end
152
125
  end
153
126
  end
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "recorded_members"
4
+ require_relative "recorded_entry"
5
5
 
6
6
  module Principles
7
7
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
@@ -25,16 +25,20 @@ module Principles
25
25
 
26
26
  private
27
27
 
28
- # Each entry whose hash and key, as RecordedMembers.filed_key gives it, are text.
28
+ # Each entry whose hash is text and whose key, if it keeps one, is text too, by its key as RecordedEntry#key
29
+ # gives it.
29
30
  #: (Hash[untyped, untyped]) -> Hash[String, String]
30
31
  def kept(members)
31
32
  members.each_with_object({}) do |(id, entry), kept|
32
- next unless entry.is_a?(Hash) && entry["sha256"].is_a?(String)
33
-
34
- key = RecordedMembers.filed_key(id, entry)
35
- kept[key] = entry["sha256"] if key.is_a?(String)
33
+ kept[RecordedEntry.new(id, entry).key] = entry["sha256"] if readable?(entry)
36
34
  end
37
35
  end
36
+
37
+ # Whether entry holds its hash, and any key it keeps, as text, the shape a readable record's schema requires.
38
+ #: (untyped) -> bool
39
+ def readable?(entry)
40
+ entry.is_a?(Hash) && [entry["sha256"], entry["key"]] in [String, String | nil]
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -12,13 +12,15 @@ module Principles
12
12
  # The most commits listed for one member; the walk says when it stopped here.
13
13
  LIMIT = 20
14
14
 
15
- # commits are the commits that touched the member's file or its map, newest first; hash_at gives the
16
- # member's hash at a revision, or nil where it cannot be found there.
17
- #: (baseline: String, now: String, commits: Array[Hash[String, String]], hash_at: ^(String) -> String?) -> void
18
- def initialize(baseline:, now:, commits:, hash_at:)
15
+ # commits are the commits that touched the member's file or its map, newest first, up to head, the commit the
16
+ # command reads as HEAD; hash_at gives the member's hash at a revision, or nil where it cannot be found there.
17
+ #: (baseline: String, now: String, commits: Array[Hash[String, String]], head: String,
18
+ #| hash_at: ^(String) -> String?) -> void
19
+ def initialize(baseline:, now:, commits:, head:, hash_at:)
19
20
  @baseline = baseline
20
21
  @now = now
21
22
  @commits = commits
23
+ @head = head
22
24
  @hash_at = hash_at
23
25
  freeze
24
26
  end
@@ -29,7 +31,7 @@ module Principles
29
31
  def to_h
30
32
  listed = [] #: Array[Hash[String, String]]
31
33
  stopped = walk(listed)
32
- { "commits" => listed, "stopped_at" => stopped, "uncommitted" => @hash_at.call("HEAD") != @now }
34
+ { "commits" => listed, "stopped_at" => stopped, "uncommitted" => @hash_at.call(@head) != @now }
33
35
  end
34
36
 
35
37
  private
@@ -13,9 +13,17 @@ module Principles
13
13
  # to a whole file. A first guess, for an alpha test to confirm (#379).
14
14
  SHOWN_AT_MOST = 80
15
15
 
16
- # The unchanged lines shown on each side of a changed region, as git shows by default (#449).
16
+ # The most bytes both sides together show whole: a 4 KB acknowledgement less its 2.7 KB of other fields,
17
+ # so a short file of long lines shows its changed region and not itself twice (D93's review F4, #1069).
18
+ SHOWN_BYTES_AT_MOST = 1300
19
+
20
+ # The most unchanged lines shown on each side of a changed region, as git shows by default (#449); fewer
21
+ # when these would pass SHOWN_BYTES_AT_MOST (#1069).
17
22
  CONTEXT_LINES = 3
18
23
 
24
+ # The most shown around a one-line change, whose edit first_changed_lines already gives (#1146).
25
+ ONE_LINE_CONTEXT_LINES = 1
26
+
19
27
  # Each line is kept without its line ending, so a line the agent copies from the request is a whole line it
20
28
  # can quote (#451).
21
29
  #: (at_baseline: Array[String], now: Array[String]) -> void
@@ -36,36 +44,76 @@ module Principles
36
44
  #: () -> bool
37
45
  def changed? = @at_baseline != @now
38
46
 
39
- # Both sides' lines while each fits; else their changed region, with where it starts within the member and
40
- # each side's length; else how many lines each side has.
41
- #: () -> Hash[String, untyped]
42
- def shown
47
+ # Both sides' lines while each is at most SHOWN_AT_MOST lines and together at most SHOWN_BYTES_AT_MOST less
48
+ # taken, the bytes a request's other parts take beyond its usual ones, as a checked member's check_result
49
+ # template does (#1119); else their changed region, with where it starts within the member and each side's
50
+ # length; else how many lines each side has.
51
+ #: (?taken: Integer) -> Hash[String, untyped]
52
+ def shown(taken: 0)
53
+ budget = SHOWN_BYTES_AT_MOST - taken
43
54
  sides = { "at_baseline" => @at_baseline, "now" => @now }
44
- return sides if fits?(sides.values)
55
+ return sides if within_line_limit?(sides.values) && bytes(sides.values) <= budget
45
56
 
46
57
  counts = sides.transform_values(&:length)
47
- region = changed_region
48
- return { "omitted" => "too_long", "lines" => counts } unless fits?(region.values.map { |each| each["lines"] })
58
+ context, region = region_within(budget)
59
+ return { "omitted" => "too_long", "lines" => counts } unless within_line_limit?(lines_of(region))
49
60
 
50
- { "changed_region" => { "context_lines" => CONTEXT_LINES, **region }, "lines" => counts }
61
+ { "changed_region" => { "context_lines" => context, **region }, "lines" => counts }
51
62
  end
52
63
 
53
64
  private
54
65
 
66
+ # How many bytes the sides' lines hold together.
67
+ #: (Array[Array[String]]) -> Integer
68
+ def bytes(sides) = sides.sum { |lines| lines.sum(&:bytesize) }
69
+
55
70
  #: (Array[Array[String]]) -> bool
56
- def fits?(sides)
71
+ def within_line_limit?(sides)
57
72
  sides.all? { |lines| lines.length <= SHOWN_AT_MOST }
58
73
  end
59
74
 
60
- # Each side's lines from CONTEXT_LINES before its first difference to CONTEXT_LINES after its last, with the
75
+ # The changed region with the most context, up to CONTEXT_LINES, whose lines fit budget, and how many lines of
76
+ # context it has; with none when no context fits, since the changed lines are what is judged, and then the sides
77
+ # first_changed_lines' span and read_the_change stand in for left out (#1103, #1144).
78
+ #: (Integer) -> [Integer, Hash[String, Hash[String, untyped]]]
79
+ def region_within(budget)
80
+ regions = most_context.downto(0).map { |context| [context, changed_region(context)] }
81
+ regions.find { |_, region| bytes(lines_of(region)) <= budget } ||
82
+ [0, with_sides_left_out(regions.fetch(-1).last)]
83
+ end
84
+
85
+ # ONE_LINE_CONTEXT_LINES when each side changed one line at most, else CONTEXT_LINES.
86
+ #: () -> Integer
87
+ def most_context
88
+ one_line = lines_of(changed_region(0)).all? { it.length <= 1 }
89
+ one_line ? ONE_LINE_CONTEXT_LINES : CONTEXT_LINES
90
+ end
91
+
92
+ # region with its baseline side's lines left out, saying so, and its side now too when each side holds one line
93
+ # at most, whose change first_changed_lines' span shows whole (#1144); a longer region's other changed lines no
94
+ # hint shows, so its side now stays (#1069).
95
+ #: (Hash[String, Hash[String, untyped]]) -> Hash[String, Hash[String, untyped]]
96
+ def with_sides_left_out(region)
97
+ one_line = lines_of(region).all? { it.length <= 1 }
98
+ left_out = one_line ? %w[at_baseline now] : %w[at_baseline]
99
+ region.to_h do |name, side|
100
+ [name, left_out.include?(name) ? { "from_line" => side.fetch("from_line"), "omitted" => "too_long" } : side]
101
+ end
102
+ end
103
+
104
+ # Each side's lines in a changed region, none for a side left out.
105
+ #: (Hash[String, Hash[String, untyped]]) -> Array[Array[String]]
106
+ def lines_of(region) = region.values.map { |side| side.fetch("lines", []) }
107
+
108
+ # Each side's lines from context lines before its first difference to context lines after its last, with the
61
109
  # 1-based line, within the member, the region starts at.
62
- #: () -> Hash[String, Hash[String, untyped]]
63
- def changed_region
110
+ #: (Integer) -> Hash[String, Hash[String, untyped]]
111
+ def changed_region(context)
64
112
  same_start = common_length(@at_baseline, @now)
65
113
  same_end = common_length(@at_baseline.drop(same_start).reverse, @now.drop(same_start).reverse)
66
- from = [same_start - CONTEXT_LINES, 0].max
114
+ from = [same_start - context, 0].max
67
115
  { "at_baseline" => @at_baseline, "now" => @now }.transform_values do |lines|
68
- to = [lines.length - same_end + CONTEXT_LINES, lines.length].min
116
+ to = [lines.length - same_end + context, lines.length].min
69
117
  { "from_line" => from + 1, "lines" => lines[from...to] || [] }
70
118
  end
71
119
  end
@@ -0,0 +1,49 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "member_loads"
5
+ require_relative "loading_scope"
6
+
7
+ module Principles
8
+ module Models
9
+ # One map's per-member loading scopes and the scope an added member newly represents.
10
+ class MemberLoadingScopes
11
+ #: (Hash[String, MemberLoads]) -> void
12
+ def initialize(loads)
13
+ @scopes = loads.transform_values { |member| LoadingScope.new(member.claude_code) }
14
+ .freeze #: Hash[String, LoadingScope]
15
+ freeze
16
+ end
17
+
18
+ # A new known scope absent from prior known ones, beside at least one differing known scope.
19
+ #: (String) -> Hash[String, untyped]
20
+ def introduced_by(id)
21
+ added = @scopes.fetch(id)
22
+ prior = @scopes.except(id)
23
+ known = prior.select { |_member_id, scope| scope.known? }
24
+ return {} unless added.known? && known.any? && known.values.none? { |scope| scope == added }
25
+
26
+ unknown = unclassified(prior)
27
+ { "loading_basis" => MemberLoads::BASIS.dup, "scope" => added.to_h, "already_mapped" => grouped(known),
28
+ **(unknown.empty? ? {} : { "not_compared" => unknown }) }
29
+ end
30
+
31
+ private
32
+
33
+ #: (Hash[String, LoadingScope]) -> Array[Hash[String, untyped]]
34
+ def grouped(known)
35
+ groups = known.group_by { |_id, scope| scope }.map do |scope, members|
36
+ { "member_ids" => members.map(&:first).sort, "scope" => scope.to_h }
37
+ end
38
+ groups.sort_by { |group| group.fetch("member_ids").first }
39
+ end
40
+
41
+ #: (Hash[String, LoadingScope]) -> Array[Hash[String, untyped]]
42
+ def unclassified(prior)
43
+ prior.reject { |_id, scope| scope.known? }.sort_by(&:first).map do |id, scope|
44
+ { "member_id" => id, "scope" => scope.to_h }
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -19,6 +19,10 @@ module Principles
19
19
  # audit-record.schema.json names each field so show-audit prints it; member_loads_spec holds a sample of each
20
20
  # branch to hold the two together, so add one there for a new branch.
21
21
  class MemberLoads
22
+ # The derivation shared by member and aggregate reports, never evidence of receipt in a session.
23
+ BASIS = { "host" => "claude_code", "kind" => "documented_prediction",
24
+ "session_start_assumption" => "project_root" }.freeze #: Hash[String, String]
25
+
22
26
  # The instruction files Claude Code loads at session start in the folder it starts in, and once a file is
23
27
  # read, written or edited in a folder below it, as its memory documentation says. This tool assumes a session
24
28
  # started at the project root.
@@ -0,0 +1,30 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "project_history"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # One member key's ordered historical placements and its oldest locatable mapping baseline.
11
+ class MemberMappingRun
12
+ #: (String, Array[[String, Hash[String, untyped]]]) -> void
13
+ def initialize(key, entries)
14
+ @key = key.dup.freeze #: String
15
+ @entries = JSON.parse(JSON.generate(entries), freeze: true) #: Array[[String, Hash[String, untyped]]]
16
+ freeze
17
+ end
18
+
19
+ #: (ProjectHistory) -> Hash[String, String]?
20
+ def baseline(history)
21
+ @entries.reverse_each do |sha, fields|
22
+ hash = history.hashes_by_key_at(sha, [fields])[@key] or next
23
+
24
+ return { "commit" => sha, "sha256" => hash }
25
+ end
26
+ nil
27
+ end
28
+ end
29
+ end
30
+ end
@@ -24,6 +24,10 @@ module Principles
24
24
  @moves.empty?
25
25
  end
26
26
 
27
+ # Whether any id participates in either end of a declared move, including a move keeping its id.
28
+ #: (Array[String]) -> bool
29
+ def involving_any?(ids) = @moves.keys.intersect?(ids) || @moves.values.intersect?(ids)
30
+
27
31
  # Refuses moves outside git, where there is no base map to check them against.
28
32
  #: (String?, principle_id: String) -> String
29
33
  def check_in_git(base, principle_id:)