principles 0.0.10 → 0.1.0

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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +0 -2
  4. data/lib/principles/controllers/acknowledgement.rb +11 -4
  5. data/lib/principles/controllers/acknowledgements.rb +4 -4
  6. data/lib/principles/controllers/answer.rb +2 -2
  7. data/lib/principles/controllers/assessment.rb +20 -4
  8. data/lib/principles/controllers/audit.rb +16 -5
  9. data/lib/principles/controllers/broken_member_repairs.rb +60 -0
  10. data/lib/principles/controllers/command.rb +8 -30
  11. data/lib/principles/controllers/correction.rb +7 -5
  12. data/lib/principles/controllers/full_audit_request.rb +44 -22
  13. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  14. data/lib/principles/controllers/inventory.rb +3 -3
  15. data/lib/principles/controllers/member_acknowledgement.rb +5 -5
  16. data/lib/principles/controllers/member_addition.rb +5 -2
  17. data/lib/principles/controllers/member_entries.rb +1 -1
  18. data/lib/principles/controllers/member_problems_report.rb +11 -7
  19. data/lib/principles/controllers/members_to_assess.rb +1 -1
  20. data/lib/principles/controllers/meta_principle_setup.rb +4 -3
  21. data/lib/principles/controllers/open_correction.rb +3 -3
  22. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  23. data/lib/principles/controllers/running_tool.rb +22 -5
  24. data/lib/principles/controllers/survey.rb +3 -2
  25. data/lib/principles/data/candidate_files_found.rb +6 -4
  26. data/lib/principles/data/command-steps.json +20 -20
  27. data/lib/principles/data/json_text.rb +5 -1
  28. data/lib/principles/data/parser_message.rb +61 -0
  29. data/lib/principles/data/project_files.rb +4 -2
  30. data/lib/principles/data/repository.rb +4 -4
  31. data/lib/principles/data/running_version.rb +1 -1
  32. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  33. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  34. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  35. data/lib/principles/invocation_options.rb +4 -4
  36. data/lib/principles/launch.rb +5 -3
  37. data/lib/principles/models/acknowledgement.rb +1 -27
  38. data/lib/principles/models/acknowledgement_left_as_printed.rb +2 -1
  39. data/lib/principles/models/acknowledgement_placeholders.rb +48 -0
  40. data/lib/principles/models/after_commit_input.rb +1 -0
  41. data/lib/principles/models/assessment_answer.rb +2 -2
  42. data/lib/principles/models/assessment_basis.rb +1 -1
  43. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  44. data/lib/principles/models/audit.rb +24 -4
  45. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  46. data/lib/principles/models/audit_record.rb +5 -14
  47. data/lib/principles/models/audit_records.rb +2 -2
  48. data/lib/principles/models/audited_member_lines.rb +1 -1
  49. data/lib/principles/models/candidate_files.rb +1 -1
  50. data/lib/principles/models/candidate_inventory.rb +20 -10
  51. data/lib/principles/models/candidate_outline.rb +1 -1
  52. data/lib/principles/models/changed_regions.rb +1 -1
  53. data/lib/principles/models/command_steps.rb +1 -2
  54. data/lib/principles/models/correction_basis.rb +1 -1
  55. data/lib/principles/models/declared_map_changes.rb +1 -2
  56. data/lib/principles/models/disposition.rb +12 -76
  57. data/lib/principles/models/disposition_placeholders.rb +48 -0
  58. data/lib/principles/models/disposition_text_field.rb +41 -0
  59. data/lib/principles/models/evidence_item.rb +1 -1
  60. data/lib/principles/models/finding_decision.rb +84 -0
  61. data/lib/principles/models/finding_write_ups.rb +2 -1
  62. data/lib/principles/models/first_full_audit.rb +1 -0
  63. data/lib/principles/models/fix_only_fields.rb +4 -3
  64. data/lib/principles/models/frontmatter_fields.rb +1 -1
  65. data/lib/principles/models/guidance_search_path.rb +1 -1
  66. data/lib/principles/models/guidance_search_paths.rb +5 -1
  67. data/lib/principles/models/head_moves.rb +1 -0
  68. data/lib/principles/models/ignored_candidates.rb +1 -1
  69. data/lib/principles/models/instruction_named.rb +1 -1
  70. data/lib/principles/models/json_path_query.rb +1 -1
  71. data/lib/principles/models/json_path_selectors.rb +1 -1
  72. data/lib/principles/models/json_path_string.rb +1 -1
  73. data/lib/principles/models/last_completed_revision.rb +1 -1
  74. data/lib/principles/models/line_diff.rb +1 -1
  75. data/lib/principles/models/line_span.rb +1 -1
  76. data/lib/principles/models/loading_scope.rb +1 -0
  77. data/lib/principles/models/located_text.rb +20 -12
  78. data/lib/principles/models/map_change.rb +66 -0
  79. data/lib/principles/models/mapped_principles.rb +4 -0
  80. data/lib/principles/models/markdown_file.rb +22 -1
  81. data/lib/principles/models/member.rb +1 -1
  82. data/lib/principles/models/member_assessments.rb +11 -4
  83. data/lib/principles/models/member_elsewhere.rb +1 -1
  84. data/lib/principles/models/member_file.rb +15 -13
  85. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  86. data/lib/principles/models/member_history.rb +1 -1
  87. data/lib/principles/models/member_lines.rb +1 -1
  88. data/lib/principles/models/member_loading_scopes.rb +1 -0
  89. data/lib/principles/models/member_mapping_run.rb +4 -4
  90. data/lib/principles/models/member_moves.rb +1 -2
  91. data/lib/principles/models/member_problems.rb +5 -1
  92. data/lib/principles/models/member_region.rb +1 -1
  93. data/lib/principles/models/member_repair_moves.rb +20 -4
  94. data/lib/principles/models/member_snapshots.rb +10 -10
  95. data/lib/principles/models/members_elsewhere.rb +1 -1
  96. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  97. data/lib/principles/models/members_sharing_lines.rb +2 -2
  98. data/lib/principles/models/misspelt_member_id.rb +10 -4
  99. data/lib/principles/models/named_placeholder.rb +32 -0
  100. data/lib/principles/models/open_finding.rb +4 -3
  101. data/lib/principles/models/open_findings_decision.rb +124 -0
  102. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  103. data/lib/principles/models/other_templates_placeholders.rb +26 -6
  104. data/lib/principles/models/outline_budget.rb +1 -1
  105. data/lib/principles/models/outline_group.rb +1 -1
  106. data/lib/principles/models/outline_section.rb +1 -1
  107. data/lib/principles/models/part_named.rb +1 -1
  108. data/lib/principles/models/plain_text_file.rb +1 -1
  109. data/lib/principles/models/principle_history.rb +5 -4
  110. data/lib/principles/models/principle_members.rb +1 -1
  111. data/lib/principles/models/problem_report.rb +13 -1
  112. data/lib/principles/models/project.rb +15 -16
  113. data/lib/principles/models/project_at_commit.rb +60 -0
  114. data/lib/principles/models/project_history.rb +10 -52
  115. data/lib/principles/models/prose_line.rb +36 -0
  116. data/lib/principles/models/record_format.rb +17 -4
  117. data/lib/principles/models/recorded_finding.rb +47 -7
  118. data/lib/principles/models/recorded_findings.rb +7 -7
  119. data/lib/principles/models/recorded_hashes.rb +1 -1
  120. data/lib/principles/models/recorded_members.rb +6 -8
  121. data/lib/principles/models/report_hooks.rb +1 -0
  122. data/lib/principles/models/request_id.rb +2 -2
  123. data/lib/principles/models/sent_answer.rb +5 -3
  124. data/lib/principles/models/session_start_input.rb +1 -0
  125. data/lib/principles/models/stale_request.rb +22 -8
  126. data/lib/principles/models/submitted_answer.rb +1 -1
  127. data/lib/principles/models/survey_search_paths.rb +13 -5
  128. data/lib/principles/models/template_placeholders.rb +22 -7
  129. data/lib/principles/models/text_size.rb +11 -3
  130. data/lib/principles/models/text_within.rb +1 -1
  131. data/lib/principles/models/unchecked_members.rb +1 -0
  132. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  133. data/lib/principles/models/unfinished_field.rb +34 -0
  134. data/lib/principles/models/unknown_principle.rb +1 -0
  135. data/lib/principles/models/write_up_opening.rb +5 -31
  136. data/lib/principles/models/write_up_pointer.rb +2 -1
  137. data/lib/principles/start_audit_options.rb +35 -20
  138. data/lib/principles/version.rb +2 -2
  139. data/lib/principles/views/acknowledged_result.rb +59 -0
  140. data/lib/principles/views/acknowledgement_result.rb +44 -51
  141. data/lib/principles/views/added_member.rb +10 -1
  142. data/lib/principles/views/answer_in_a_file.rb +65 -0
  143. data/lib/principles/views/assessed_members.rb +4 -2
  144. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  145. data/lib/principles/views/assessment_request.rb +2 -26
  146. data/lib/principles/views/audit_result.rb +18 -7
  147. data/lib/principles/views/candidate_files_result.rb +9 -4
  148. data/lib/principles/views/context_parts.rb +41 -10
  149. data/lib/principles/views/correction_request.rb +27 -18
  150. data/lib/principles/views/first_audit_brief.rb +2 -1
  151. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  152. data/lib/principles/views/invocation.rb +14 -4
  153. data/lib/principles/views/json_on_one_line.rb +18 -0
  154. data/lib/principles/views/member_repairs.rb +21 -5
  155. data/lib/principles/views/meta_principle_result.rb +26 -5
  156. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  157. data/lib/principles/views/parts_index_result.rb +8 -6
  158. data/lib/principles/views/principle_read_result.rb +2 -2
  159. data/lib/principles/views/problem_facts.rb +46 -0
  160. data/lib/principles/views/problem_lines.rb +8 -3
  161. data/lib/principles/views/problem_result.rb +53 -31
  162. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
  163. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  164. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  165. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  166. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  167. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  168. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  169. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  170. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  171. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-check.md +4 -3
  172. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +4 -3
  173. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  174. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +7 -8
  175. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  176. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +4 -3
  177. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member-check.md +4 -3
  178. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +4 -3
  179. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +13 -12
  180. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  181. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  182. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +12 -12
  183. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  184. data/lib/principles/views/prompts/start-a-session/act-on-the-changed-principles.md +2 -0
  185. data/lib/principles/views/prompts.rb +7 -4
  186. metadata +26 -8
  187. data/lib/principles/controllers/repoint.rb +0 -67
  188. data/lib/principles/models/repoint.rb +0 -125
  189. data/lib/principles/models/write_up_repoint.rb +0 -38
  190. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  191. data/lib/principles/views/repoint_result.rb +0 -80
@@ -1,15 +1,15 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "digest"
5
4
  require_relative "../error"
6
5
  require_relative "locator"
7
6
  require_relative "member_region"
8
7
  require_relative "line_span"
8
+ 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
@@ -50,7 +50,7 @@ module Principles
50
50
  end
51
51
 
52
52
  # Where the member locator names is in this text, and the hash of what it says there.
53
- #: (Locator) -> Hash[String, untyped]
53
+ #: (Locator) -> LocatedText
54
54
  def locate(locator)
55
55
  refuse_mixed_locators(locator)
56
56
  lines = @text.lines
@@ -65,7 +65,7 @@ module Principles
65
65
  end
66
66
 
67
67
  # Only a newly supplied add/move location needs an unambiguous ending; existing references keep lookup.
68
- #: (Locator) -> Hash[String, untyped]
68
+ #: (Locator) -> LocatedText
69
69
  def locate_for_authoring(locator)
70
70
  found = locate(locator)
71
71
  opening = locator.starting_at
@@ -78,11 +78,16 @@ 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)
84
89
  located = locate(locator)
85
- @text.lines[(located.fetch("first_line") - 1)...located.fetch("last_line")].to_a
90
+ @text.lines[(located.first_line - 1)...located.last_line].to_a
86
91
  end
87
92
 
88
93
  # The opening of the region locator names, after the heading line itself when it names a heading, as
@@ -91,19 +96,16 @@ module Principles
91
96
  def write_up_opening(locator)
92
97
  located = locate(locator)
93
98
  heading_line = locator.heading && !locator.starting_at ? 1 : 0
94
- WriteUpOpening.new(lines: @text.lines, first: located.fetch("first_line") - 1 + heading_line,
95
- last: located.fetch("last_line")).to_h
99
+ WriteUpOpening.new(lines: @text.lines, first: located.first_line - 1 + heading_line,
100
+ last: located.last_line).to_h
96
101
  end
97
102
 
98
103
  private
99
104
 
100
- # What locate found: the member's place, the hash of its text and its span. query appears only for a
101
- # member that has one, so every other member's snapshot, and each request id digesting it, is unchanged.
102
- #: (Locator, String, Integer, Integer) -> Hash[String, untyped]
105
+ # What locate found: the member's place, the hash of its text and its span.
106
+ #: (Locator, String, Integer, Integer) -> LocatedText
103
107
  def snapshot(locator, selected, first_line, last_line)
104
- { "path" => @path, "heading" => locator.heading, "starting_at" => locator.starting_at,
105
- "sha256" => Digest::SHA256.hexdigest(selected), "characters" => selected.length,
106
- "first_line" => first_line, "last_line" => last_line }.merge(locator.to_h.slice("query"))
108
+ LocatedText.new(locator:, path: @path, first_line:, last_line:, text: selected)
107
109
  end
108
110
 
109
111
  # A query names a field whole, so it takes no section or passage beside it.
@@ -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.hashes_by_key_at(sha, [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
@@ -6,8 +6,7 @@ require_relative "member"
6
6
  require_relative "principle"
7
7
 
8
8
  module Principles
9
- # The domain: maps, audits and command steps, with every rule a schema cannot express.
10
- # models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
10
  module Models
12
11
  # The members a correction says the agent moved after the audit began, from each old id to its new one. A
13
12
  # fix can rewrite the text a member's locator quotes; the agent then runs move-member and declares the
@@ -11,7 +11,7 @@ require_relative "member_state"
11
11
  require_relative "locate_refusal"
12
12
 
13
13
  module Principles
14
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
14
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
15
15
  module Models
16
16
  # One map's members, each as broken, changed, unchanged, unchanged since its mapping commit or with no
17
17
  # baseline, against what this tool last knew of its text: the last audit's hash for it, or else its text at
@@ -242,6 +242,10 @@ module Principles
242
242
  @baselines.none_because
243
243
  end
244
244
 
245
+ # The map's members, whose files an audit of it judges as committed.
246
+ #: PrincipleMembers
247
+ attr_reader :members
248
+
245
249
  # Each file holding a member found with no baseline, once.
246
250
  #: () -> Array[String]
247
251
  def no_baseline_paths
@@ -7,7 +7,7 @@ require_relative "member_file"
7
7
  require_relative "line_span"
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 file-selected region's text and full-file character origin, for literal passage matching.
13
13
  class MemberRegion
@@ -22,6 +22,22 @@ module Principles
22
22
  # tracked by git only under another spelling.
23
23
  FILE_NOT_AT_PATH = %w[unreadable_file renamed_in_case].freeze #: Array[String]
24
24
 
25
+ # One move: the locator fields it keeps, by name, and those the agent fills in.
26
+ class Move
27
+ #: Hash[String, untyped]
28
+ attr_reader :keep
29
+
30
+ #: Array[String]
31
+ attr_reader :fill
32
+
33
+ #: (Hash[String, untyped], Array[String]) -> void
34
+ def initialize(keep, fill)
35
+ @keep = keep
36
+ @fill = fill
37
+ freeze
38
+ end
39
+ end
40
+
25
41
  # member is the member's locator fields, as its map holds them; code is that of the refusal saying why it cannot
26
42
  # be found, and tracked_as the spelling git tracks its path under, which a renamed_in_case refusal gives.
27
43
  #: (Hash[String, untyped], code: String?, ?tracked_as: String?) -> void
@@ -32,8 +48,8 @@ module Principles
32
48
  freeze
33
49
  end
34
50
 
35
- # Each move, as { "keep" => the locator fields it keeps, by name, "fill" => the fields the agent fills in }.
36
- #: () -> Array[Hash[String, untyped]]
51
+ # Each move that may repair the member.
52
+ #: () -> Array[Move]
37
53
  def to_a
38
54
  return [move(@member.merge("path" => @tracked_as), [])] if @code == "renamed_in_case" && @tracked_as
39
55
  return [move(@member, %w[path])] if FILE_NOT_AT_PATH.include?(@code)
@@ -51,8 +67,8 @@ module Principles
51
67
  #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
52
68
  def given(member, fields) = fields.filter_map { [it, member[it]] unless member[it].nil? }.to_h.freeze
53
69
 
54
- #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
55
- def move(keep, fill) = { "keep" => keep, "fill" => fill }
70
+ #: (Hash[String, untyped], Array[String]) -> Move
71
+ def move(keep, fill) = Move.new(keep, fill)
56
72
  end
57
73
  end
58
74
  end
@@ -14,36 +14,36 @@ module Principles
14
14
  #: (Project, Principle) -> MemberSnapshots
15
15
  def self.read(project, map)
16
16
  broken = [] #: Array[Hash[String, untyped]]
17
- found = map.members.to_h do |member|
18
- [member.id, project.locate(member.locator)]
17
+ found = {} #: Hash[String, LocatedText]
18
+ map.members.each do |member|
19
+ found[member.id] = project.located_text(member.locator)
19
20
  rescue Error => e
20
21
  broken << { "id" => member.id }.merge(e.payload.except("status"))
21
- [member.id, {}]
22
22
  end
23
23
  broken.empty? ? new(found) : project.refuse_broken(map.id, broken)
24
24
  end
25
25
 
26
- #: (Hash[String, Hash[String, untyped]]) -> void
26
+ #: (Hash[String, LocatedText]) -> void
27
27
  def initialize(by_id)
28
- @by_id = by_id.freeze #: Hash[String, Hash[String, untyped]]
28
+ @by_id = by_id.freeze #: Hash[String, LocatedText]
29
29
  freeze
30
30
  end
31
31
 
32
- # Each member's snapshot by id.
33
- #: () -> Hash[String, Hash[String, untyped]]
32
+ # Each member's located text by id.
33
+ #: () -> Hash[String, LocatedText]
34
34
  def to_h = @by_id
35
35
 
36
36
  # Where the member id is in its file now, and the hash of what it says there.
37
37
  #: (String) -> LocatedText
38
- def of(id) = LocatedText.of(@by_id.fetch(id))
38
+ def of(id) = @by_id.fetch(id)
39
39
 
40
40
  # Each member's id and the hash of its text now.
41
41
  #: () -> Hash[String, String]
42
- def hashes = @by_id.transform_values { |snapshot| snapshot.fetch("sha256") }
42
+ def hashes = @by_id.transform_values(&:sha256)
43
43
 
44
44
  # The lines the members span now, against which another principle's evidence is said to share them.
45
45
  #: () -> AuditedMemberLines
46
- def audited_lines = AuditedMemberLines.new(@by_id.transform_values { LocatedText.of(it) })
46
+ def audited_lines = AuditedMemberLines.new(@by_id)
47
47
  end
48
48
  end
49
49
  end
@@ -5,7 +5,7 @@ require_relative "member_elsewhere"
5
5
  require_relative "open_finding"
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 members of other principles' maps sharing a line with one located member, as MembersSharingLines finds
11
11
  # them: what each result prints of them under mapped_elsewhere, and whether the agent should check the text
@@ -6,6 +6,7 @@ require_relative "member"
6
6
  require_relative "located_text"
7
7
 
8
8
  module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
10
  module Models
10
11
  # Members in complete sections meeting the new section at a literal line boundary, in other unaudited maps.
11
12
  class MembersInConsecutiveSections
@@ -9,13 +9,13 @@ require_relative "member_elsewhere"
9
9
  require_relative "members_elsewhere"
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 members whose text shares a line with one member located in its file, so one edit there shows on
15
15
  # each. The project locates the others; a member this tool cannot find now is left out, since show-principle
16
16
  # reports it.
17
17
  class MembersSharingLines
18
- # The members sharing a line with member, located where it is now; refuses as Project#locate does when it
18
+ # The members sharing a line with member, located where it is now; refuses as Project#located_text does when it
19
19
  # cannot be found.
20
20
  #: (Project, Member) -> MembersSharingLines
21
21
  def self.of(project, member)
@@ -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
  # A member id an answer named that the map does not hold. A member id copies its heading exactly, so
8
8
  # an agent typing it may use a straight apostrophe for a curly one, a hyphen for a dash, or other
@@ -19,11 +19,13 @@ module Principles
19
19
  freeze
20
20
  end
21
21
 
22
- # The one mapped id spelled like this one apart from punctuation, case and spacing, or nil.
22
+ # The one mapped id spelled like this one apart from punctuation, case and spacing, or else the one whose
23
+ # heading or passage this is, as an agent gives a passage's start text without its path@ prefix; nil when
24
+ # none or several are. It is only named, for the agent to judge.
23
25
  #: (Array[String]) -> String?
24
26
  def closest(mapped)
25
- matches = mapped.select { |each| loose(each) == loose(@id) }
26
- matches.first if matches.one?
27
+ only(mapped.select { |each| loose(each) == loose(@id) }) ||
28
+ only(mapped.select { |each| each.end_with?("##{@id}", "@#{@id}") })
27
29
  end
28
30
 
29
31
  # What a refusal says of this id: that it is not mapped, and the mapped id it is spelled like; nil when none.
@@ -35,6 +37,10 @@ module Principles
35
37
 
36
38
  private
37
39
 
40
+ # The one id among matches, or nil.
41
+ #: (Array[String]) -> String?
42
+ def only(matches) = (matches.first if matches.one?)
43
+
38
44
  #: (String) -> String
39
45
  def loose(text)
40
46
  text.unicode_normalize(:nfkc).gsub(APOSTROPHES, "'").gsub(QUOTES, '"').gsub(DASHES, "-")
@@ -0,0 +1,32 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # A placeholder a template prints naming the id of the slot it fills, a member's or a finding's, so no two slots
8
+ # are alike and a file-edit tool's one-match replace fills one. Its text for any id, or the text it printed
9
+ # before it named one, sent in any slot, is left as printed.
10
+ class NamedPlaceholder
11
+ # The slot in slotted that each slot's id fills.
12
+ SLOT = "%<id>s" #: String
13
+
14
+ # slotted is the text with SLOT where the id goes; before is the text it printed before it named one.
15
+ #: (String, before: String) -> void
16
+ def initialize(slotted, before:)
17
+ @slotted = slotted
18
+ @before = before
19
+ @pattern = /\A#{Regexp.escape(slotted).sub(Regexp.escape(SLOT), ".+")}\z/m #: Regexp
20
+ freeze
21
+ end
22
+
23
+ # The text with SLOT, which a controller hands the view that fills each slot's id.
24
+ #: String
25
+ attr_reader :slotted
26
+
27
+ # Whether text is this placeholder, for any id or as it was printed before it named one.
28
+ #: (untyped) -> bool
29
+ def left?(text) = text == @before || (text.is_a?(String) && @pattern.match?(text))
30
+ end
31
+ end
32
+ end
@@ -38,14 +38,15 @@ module Principles
38
38
  "audited_at" => @audited_at, "first_raised_at" => first_raised_at, **raised_in, **waiting, **kept_evidence }
39
39
  end
40
40
 
41
- # The finding as the next full audit's request lists it, with when it was first raised, and what it waits on,
42
- # since when, for the agent to confirm.
41
+ # The finding as the next full audit's request lists it, with when it was first raised, what it waits on,
42
+ # since when, for the agent to confirm, and each change made to it since its record.
43
43
  #: () -> Hash[String, untyped]
44
44
  def for_next_audit
45
45
  { "finding_id" => id, "member_ids" => @finding.member_ids, **problem,
46
46
  **present("recorded_at", recorded_at&.to_h),
47
47
  "action" => @finding.action,
48
- "first_raised_at" => first_raised_at, **raised_in, **waiting }
48
+ "first_raised_at" => first_raised_at, **raised_in, **waiting,
49
+ **present("changed_since_audit", @finding.changes_since_audit) }
49
50
  end
50
51
 
51
52
  # The finding as the next full audit's request lists it, against the map's members now and each one's hash
@@ -0,0 +1,124 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "answer_fields"
6
+ require_relative "answer_place"
7
+ require_relative "audit_record"
8
+ require_relative "audit_records"
9
+ require_relative "finding_decision"
10
+ require_relative "last_completed_revision"
11
+ require_relative "project_history"
12
+ require_relative "request_id"
13
+
14
+ module Principles
15
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
16
+ module Models
17
+ # A decision on a principle's open findings between full audits: the agent gives, for each finding it names,
18
+ # only what changes of its wait, action or write-up, and the last completed record keeps each change beside it,
19
+ # with the old value, when and why. Whether the change is right is the agent's judgement.
20
+ class OpenFindingsDecision
21
+ # The phase of start-audit --open-findings, which decides a finding's wait, action or write-up.
22
+ DECIDING = "deciding"
23
+
24
+ # record is the principle's audit record now; history says whether a new pointer's file is committed.
25
+ #: (principle_id: String, record: AuditRecord?, history: ProjectHistory) -> void
26
+ def initialize(principle_id:, record:, history:)
27
+ @principle_id = principle_id
28
+ @record = record
29
+ @history = history
30
+ freeze
31
+ end
32
+
33
+ # The request's id, digesting the last completed record's revision it was printed after, so an answer is
34
+ # matched to the record it read.
35
+ #: () -> RequestId
36
+ def request_id = RequestId.for(principle_id: @principle_id, phase: DECIDING, parts: [revision])
37
+
38
+ # The completed record's revision, which the request prints and the answer hands back.
39
+ #: () -> String
40
+ def revision = completed.revision
41
+
42
+ # The record with each decision an answer to start-audit --open-findings gives applied at at, once each names a
43
+ # different open finding and each new recorded_at is located by the block, in a committed file; a decision that
44
+ # changes no field leaves its finding as it is.
45
+ #: (untyped, at: String) { (Locator) -> void } -> AuditRecord
46
+ def decided(response, at:, &locate)
47
+ fields = AnswerFields.new(locate)
48
+ decisions = response.fetch("decisions")
49
+ each_open_once(decisions.map { |decision| decision.fetch("finding_id") })
50
+ completed.decided(decisions.each_with_index.map { |decision, index| decision_at(decision, index, fields) },
51
+ at:)
52
+ end
53
+
54
+ # The records decided changes among records, not yet written: refused once the record changed after the
55
+ # request, whose revision response quotes back in its basis, was printed, unless it changes none.
56
+ #: (AuditRecord, untyped, records: AuditRecords) -> Array[AuditRecord]
57
+ def confirmed_writable(decided, response, records:)
58
+ changes = records.changes(decided)
59
+ LastCompletedRevision.new(response.dig("basis", "revision")).confirm_writable(@principle_id, @record, changes)
60
+ changes
61
+ end
62
+
63
+ # The ids of the completed record's open findings that decided, the record accepted, changes.
64
+ #: (AuditRecord) -> Array[String]
65
+ def changed_ids(decided)
66
+ before = completed.left_open.to_h { |finding| [finding.id, finding.listed] }
67
+ decided.left_open.reject { |finding| before[finding.id] == finding.listed }.map(&:id)
68
+ end
69
+
70
+ # Refuses unless the principle's record is a completed audit's: an open record outside git keeps the completed
71
+ # one, whose findings its correction will decide, and with none there is nothing to decide.
72
+ #: () -> AuditRecord
73
+ def completed
74
+ record = @record
75
+ return record if record&.completed?
76
+
77
+ start = "#{Error::EXECUTABLE} start-audit #{@principle_id}"
78
+ if record
79
+ raise Error.new("cannot_decide_open_findings",
80
+ "#{@principle_id} has an audit left open, whose correction decides its findings",
81
+ "Answer that correction, or start the audit again: #{start}")
82
+ end
83
+
84
+ raise Error.new("cannot_decide_open_findings", "#{@principle_id} has no completed audit, so no finding is open",
85
+ "Run a full audit first: #{start}")
86
+ end
87
+
88
+ private
89
+
90
+ # Refuses ids, the findings an answer's decisions name, when one is not open in the completed record or two
91
+ # name one finding, since either would otherwise read as a success.
92
+ #: (Array[String]) -> void
93
+ def each_open_once(ids)
94
+ open = completed.open_ids
95
+ unknown = ids - open
96
+ unless unknown.empty?
97
+ raise Error.new("unknown_finding", "#{@principle_id}'s last completed audit leaves no finding " \
98
+ "#{unknown.join(", ")} open",
99
+ "Decide only its open findings: #{open.join(", ")}")
100
+ end
101
+ each_once(ids)
102
+ end
103
+
104
+ #: (Array[String]) -> void
105
+ def each_once(ids)
106
+ repeated = ids.tally.select { |_, count| count > 1 }.keys
107
+ return if repeated.empty?
108
+
109
+ raise Error.new("duplicate_finding", "Decisions name #{repeated.join(", ")} more than once",
110
+ "Give each finding one decision.")
111
+ end
112
+
113
+ # The decision at index, its new recorded_at, when it gives one, located and committed.
114
+ #: (Hash[String, untyped], Integer, AnswerFields) -> FindingDecision
115
+ def decision_at(decision, index, fields)
116
+ place = AnswerPlace.new("/decisions/#{index}", "Finding #{decision["finding_id"]}")
117
+ reference = decision["recorded_at"]
118
+ pointer = fields.write_up_pointer(reference, place.child("recorded_at")) if reference
119
+ @history.refuse_uncommitted_write_up(pointer.path) if pointer
120
+ FindingDecision.new(decision, place, principle_id: @principle_id, recorded_at: pointer)
121
+ end
122
+ end
123
+ end
124
+ end
@@ -6,7 +6,7 @@ require_relative "members_elsewhere"
6
6
  require_relative "open_finding"
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 findings other principles' records leave open on members sharing lines with a full audit's members, read
12
12
  # once per principle: each member's mapped_elsewhere names them by id, and the request lists each once, since a
@@ -4,9 +4,10 @@
4
4
  require_relative "../error"
5
5
  require_relative "acknowledgement"
6
6
  require_relative "assessment_answer"
7
- require_relative "disposition"
7
+ require_relative "disposition_placeholders"
8
8
  require_relative "loading_decision"
9
9
  require_relative "member_assessments"
10
+ require_relative "named_placeholder"
10
11
  require_relative "prior_decision_fields"
11
12
  require_relative "recent_decision"
12
13
  require_relative "refusal_before_shape"
@@ -14,6 +15,7 @@ require_relative "reported_check"
14
15
  require_relative "shape_problems_beside"
15
16
 
16
17
  module Principles
18
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
17
19
  module Models
18
20
  # The text in an answer that ends as this tool's placeholders end, "Leave as printed ...", "else leave" or "else
19
21
  # kept", or is a placeholder some template of this release prints, but is none the request's own template
@@ -63,12 +65,19 @@ module Principles
63
65
  # decision, the correction's disposition, and the one-member audit's acknowledgement. Its spec fails on a
64
66
  # placeholder constant in models/ missing here.
65
67
  KNOWN = [
66
- MemberAssessments::PLACEHOLDER, AssessmentAnswer::COLLECTIVE_PLACEHOLDER, RecentDecision::PLACEHOLDERS.to_h,
68
+ MemberAssessments::PLACEHOLDER, MemberAssessments::NAMED_PLACEHOLDER, AssessmentAnswer::COLLECTIVE_PLACEHOLDER,
69
+ RecentDecision::PLACEHOLDERS.to_h,
67
70
  ReportedCheck::PLACEHOLDERS.to_h, ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h,
68
71
  LoadingDecision::PLACEHOLDERS.to_h, PriorDecisionFields::TEMPLATE_PLACEHOLDERS,
69
- Disposition::TEMPLATE_PLACEHOLDERS, Acknowledgement::PLACEHOLDERS.to_h, Acknowledgement::EXIT_STATUS_PLACEHOLDER
72
+ DispositionPlaceholders::TEMPLATE_PLACEHOLDERS, DispositionPlaceholders::ACTION_PLACEHOLDER,
73
+ AcknowledgementPlaceholders::PLACEHOLDERS.to_h, AcknowledgementPlaceholders::EXIT_STATUS_PLACEHOLDER
70
74
  ].then { Strings.new(it).by_pointer.values.to_set }.freeze #: Set[String]
71
75
 
76
+ # Every placeholder a template of this release prints naming its slot's id, for any id or as printed before
77
+ # it named one.
78
+ NAMED = [MemberAssessments::ASSESSMENT, *DispositionPlaceholders::NAMED,
79
+ *AcknowledgementPlaceholders::PLACEHOLDERS.named].freeze #: Array[NamedPlaceholder]
80
+
72
81
  # Each string in template, a request's template as printed, which its answer may send back; start_from says
73
82
  # where that template is printed, as RequestId#answer_to_fill gives it.
74
83
  #: (untyped, start_from: String) -> OtherTemplatesPlaceholders
@@ -76,11 +85,14 @@ module Principles
76
85
  new(Strings.new(template).by_pointer.values, start_from:)
77
86
  end
78
87
 
79
- # printed is the placeholders the request's own template printed, which an answer may leave as printed, and
80
- # start_from where that template is printed.
88
+ # printed is the placeholders the request's own template printed, which an answer may leave as printed, each
89
+ # with NamedPlaceholder::SLOT where it names its slot's id, for any id, and start_from where that template is
90
+ # printed.
81
91
  #: (Array[String], start_from: String) -> void
82
92
  def initialize(printed, start_from:)
83
93
  @printed = printed
94
+ @printed_named = printed.select { it.include?(NamedPlaceholder::SLOT) }
95
+ .map { NamedPlaceholder.new(it, before: it) } #: Array[NamedPlaceholder]
84
96
  @repair = "Start from #{start_from}, or replace each field named with your own text; if one is your own " \
85
97
  "text, reword its ending" #: String
86
98
  end
@@ -108,7 +120,15 @@ module Principles
108
120
 
109
121
  # Whether text ends as a placeholder does, or is one another template prints, but is none printed.
110
122
  #: (String) -> bool
111
- def other?(text) = (text.match?(ENDING) || KNOWN.include?(text)) && !@printed.include?(text)
123
+ def other?(text) = (known?(text) || NAMED.any? { it.left?(text) }) && !printed?(text)
124
+
125
+ # Whether the request's own template printed text, a slot's id in any named placeholder.
126
+ #: (String) -> bool
127
+ def printed?(text) = @printed.include?(text) || @printed_named.any? { it.left?(text) }
128
+
129
+ # Whether text ends as a placeholder does, or is one a model's constant holds.
130
+ #: (String) -> bool
131
+ def known?(text) = text.match?(ENDING) || KNOWN.include?(text)
112
132
  end
113
133
  end
114
134
  end
@@ -6,7 +6,7 @@ require_relative "candidate_outline"
6
6
  require_relative "entry_files"
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
  # How much list-candidate-files may print: its listed files' outlines, cut a whole file's list items at a time
12
12
  # until the result fits. One user's run printed 66,145 B for 45 files, against a ceiling of about
@@ -4,7 +4,7 @@
4
4
  require_relative "outline_section"
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
  # One section of a candidate file's outline and the deeper sections under it, which a cut outline folds into it
10
10
  # once its headings are cut too.