principles 0.0.11 → 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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/lib/principles/controllers/answer.rb +2 -2
  4. data/lib/principles/controllers/assessment.rb +19 -3
  5. data/lib/principles/controllers/audit.rb +14 -4
  6. data/lib/principles/controllers/full_audit_request.rb +16 -10
  7. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  8. data/lib/principles/controllers/member_addition.rb +4 -1
  9. data/lib/principles/controllers/member_problems_report.rb +7 -6
  10. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  11. data/lib/principles/controllers/running_tool.rb +22 -5
  12. data/lib/principles/controllers/survey.rb +3 -2
  13. data/lib/principles/data/candidate_files_found.rb +6 -4
  14. data/lib/principles/data/command-steps.json +17 -17
  15. data/lib/principles/data/json_text.rb +5 -1
  16. data/lib/principles/data/parser_message.rb +61 -0
  17. data/lib/principles/data/project_files.rb +4 -2
  18. data/lib/principles/data/running_version.rb +1 -1
  19. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  20. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  21. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  22. data/lib/principles/invocation_options.rb +1 -1
  23. data/lib/principles/launch.rb +5 -3
  24. data/lib/principles/models/after_commit_input.rb +1 -0
  25. data/lib/principles/models/assessment_basis.rb +1 -1
  26. data/lib/principles/models/audit.rb +23 -3
  27. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  28. data/lib/principles/models/audit_record.rb +5 -14
  29. data/lib/principles/models/audit_records.rb +1 -1
  30. data/lib/principles/models/audited_member_lines.rb +1 -1
  31. data/lib/principles/models/candidate_files.rb +1 -1
  32. data/lib/principles/models/candidate_inventory.rb +19 -9
  33. data/lib/principles/models/candidate_outline.rb +1 -1
  34. data/lib/principles/models/changed_regions.rb +1 -1
  35. data/lib/principles/models/command_steps.rb +1 -2
  36. data/lib/principles/models/correction_basis.rb +1 -1
  37. data/lib/principles/models/declared_map_changes.rb +1 -2
  38. data/lib/principles/models/finding_decision.rb +84 -0
  39. data/lib/principles/models/finding_write_ups.rb +2 -1
  40. data/lib/principles/models/first_full_audit.rb +1 -0
  41. data/lib/principles/models/frontmatter_fields.rb +1 -1
  42. data/lib/principles/models/guidance_search_path.rb +1 -1
  43. data/lib/principles/models/guidance_search_paths.rb +5 -1
  44. data/lib/principles/models/head_moves.rb +1 -0
  45. data/lib/principles/models/ignored_candidates.rb +1 -1
  46. data/lib/principles/models/instruction_named.rb +1 -1
  47. data/lib/principles/models/json_path_query.rb +1 -1
  48. data/lib/principles/models/json_path_selectors.rb +1 -1
  49. data/lib/principles/models/json_path_string.rb +1 -1
  50. data/lib/principles/models/last_completed_revision.rb +1 -1
  51. data/lib/principles/models/line_diff.rb +1 -1
  52. data/lib/principles/models/line_span.rb +1 -1
  53. data/lib/principles/models/loading_scope.rb +1 -0
  54. data/lib/principles/models/located_text.rb +1 -1
  55. data/lib/principles/models/map_change.rb +66 -0
  56. data/lib/principles/models/mapped_principles.rb +4 -0
  57. data/lib/principles/models/markdown_file.rb +22 -1
  58. data/lib/principles/models/member.rb +1 -1
  59. data/lib/principles/models/member_elsewhere.rb +1 -1
  60. data/lib/principles/models/member_file.rb +6 -1
  61. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  62. data/lib/principles/models/member_history.rb +1 -1
  63. data/lib/principles/models/member_lines.rb +1 -1
  64. data/lib/principles/models/member_loading_scopes.rb +1 -0
  65. data/lib/principles/models/member_mapping_run.rb +4 -4
  66. data/lib/principles/models/member_moves.rb +1 -2
  67. data/lib/principles/models/member_problems.rb +5 -1
  68. data/lib/principles/models/member_region.rb +1 -1
  69. data/lib/principles/models/members_elsewhere.rb +1 -1
  70. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  71. data/lib/principles/models/members_sharing_lines.rb +1 -1
  72. data/lib/principles/models/misspelt_member_id.rb +1 -1
  73. data/lib/principles/models/open_finding.rb +4 -3
  74. data/lib/principles/models/open_findings_decision.rb +124 -0
  75. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  76. data/lib/principles/models/other_templates_placeholders.rb +1 -0
  77. data/lib/principles/models/outline_budget.rb +1 -1
  78. data/lib/principles/models/outline_group.rb +1 -1
  79. data/lib/principles/models/outline_section.rb +1 -1
  80. data/lib/principles/models/part_named.rb +1 -1
  81. data/lib/principles/models/plain_text_file.rb +1 -1
  82. data/lib/principles/models/principle_history.rb +3 -3
  83. data/lib/principles/models/principle_members.rb +1 -1
  84. data/lib/principles/models/problem_report.rb +13 -1
  85. data/lib/principles/models/project.rb +8 -3
  86. data/lib/principles/models/project_at_commit.rb +9 -19
  87. data/lib/principles/models/prose_line.rb +36 -0
  88. data/lib/principles/models/record_format.rb +17 -4
  89. data/lib/principles/models/recorded_finding.rb +47 -7
  90. data/lib/principles/models/recorded_findings.rb +7 -7
  91. data/lib/principles/models/recorded_hashes.rb +1 -1
  92. data/lib/principles/models/recorded_members.rb +6 -8
  93. data/lib/principles/models/report_hooks.rb +1 -0
  94. data/lib/principles/models/request_id.rb +2 -2
  95. data/lib/principles/models/sent_answer.rb +1 -0
  96. data/lib/principles/models/session_start_input.rb +1 -0
  97. data/lib/principles/models/stale_request.rb +22 -8
  98. data/lib/principles/models/submitted_answer.rb +1 -1
  99. data/lib/principles/models/survey_search_paths.rb +13 -5
  100. data/lib/principles/models/text_within.rb +1 -1
  101. data/lib/principles/models/unchecked_members.rb +1 -0
  102. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  103. data/lib/principles/models/unknown_principle.rb +1 -0
  104. data/lib/principles/models/write_up_opening.rb +5 -31
  105. data/lib/principles/models/write_up_pointer.rb +2 -1
  106. data/lib/principles/start_audit_options.rb +25 -18
  107. data/lib/principles/version.rb +2 -2
  108. data/lib/principles/views/acknowledgement_result.rb +12 -9
  109. data/lib/principles/views/added_member.rb +10 -1
  110. data/lib/principles/views/answer_in_a_file.rb +16 -4
  111. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  112. data/lib/principles/views/assessment_request.rb +2 -26
  113. data/lib/principles/views/audit_result.rb +15 -6
  114. data/lib/principles/views/candidate_files_result.rb +9 -4
  115. data/lib/principles/views/context_parts.rb +40 -9
  116. data/lib/principles/views/correction_request.rb +8 -5
  117. data/lib/principles/views/first_audit_brief.rb +2 -1
  118. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  119. data/lib/principles/views/invocation.rb +14 -4
  120. data/lib/principles/views/json_on_one_line.rb +18 -0
  121. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  122. data/lib/principles/views/problem_facts.rb +46 -0
  123. data/lib/principles/views/problem_result.rb +42 -31
  124. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  125. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  126. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  127. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  128. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  129. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  130. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  131. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  132. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  133. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  134. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  135. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  136. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  137. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  138. metadata +14 -7
  139. data/lib/principles/controllers/repoint.rb +0 -67
  140. data/lib/principles/models/repoint.rb +0 -125
  141. data/lib/principles/models/write_up_repoint.rb +0 -38
  142. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  143. data/lib/principles/views/repoint_result.rb +0 -80
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # Where two versions of a member's lines differ: each run of lines one side changed, in order, as a line diff finds
8
8
  # them by their longest common subsequence. The lines both sides share from the start and from the end are never
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The lines a member spans in its file, first to last, as a LocatedText gives them, and whether the member is
8
8
  # its whole file, so two members' spans are compared in one place.
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
5
6
  module Models
6
7
  # Literal loading-scope qualifiers for mapping feedback, distinct from persisted LoadingFacts.
7
8
  class LoadingScope
@@ -6,7 +6,7 @@ require_relative "line_span"
6
6
  require_relative "locator"
7
7
 
8
8
  module Principles
9
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
10
  module Models
11
11
  # The text a locator found now: its file, the lines it spans and the hash of what it says. A Locator says where
12
12
  # to look; this is what was found there, as MemberFile#locate finds it.
@@ -0,0 +1,66 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "../prose_list"
6
+ require_relative "principle"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # How a principle's map differs from the one an audit's request was printed from: each field of the map, and of
12
+ # each member both maps hold, as it was and is now, which a stale request's refusal names.
13
+ class MapChange
14
+ #: (Principle, Principle) -> void
15
+ def initialize(base, current)
16
+ @base = base
17
+ @current = current
18
+ freeze
19
+ end
20
+
21
+ # Each change as a clause, such as: CLAUDE.md#Names's role was "a" and is now "b".
22
+ #: () -> String
23
+ def to_s = ProseList.new(clauses).to_s
24
+
25
+ # Whether it names no change, as when only the members' order, or which members the map holds, changed.
26
+ #: () -> bool
27
+ def empty? = clauses.empty?
28
+
29
+ # What an answer carried to a new request must judge again: each member whose entry changed, or, when a field of
30
+ # the map itself changed, every member.
31
+ #: () -> String
32
+ def to_judge_again
33
+ return "every member again against the map as it is now" unless map_fields.empty?
34
+
35
+ changed = @current.members.select { |member| member_fields_of(member).any? }.map(&:id)
36
+ entries = changed.one? ? "its map entry as it is" : "their map entries as they are"
37
+ "#{ProseList.new(changed)} again against #{entries} now"
38
+ end
39
+
40
+ private
41
+
42
+ #: () -> Array[String]
43
+ def clauses = map_fields + member_fields
44
+
45
+ #: () -> Array[String]
46
+ def map_fields = differing("its", @base.to_h.except("members"), @current.to_h.except("members"))
47
+
48
+ #: () -> Array[String]
49
+ def member_fields = @current.members.flat_map { |member| member_fields_of(member) }
50
+
51
+ # How member's entry differs from the one the base map holds under its key, none when it holds none.
52
+ #: (Member) -> Array[String]
53
+ def member_fields_of(member)
54
+ was = @base.members.with_key(member.key)
55
+ was ? differing("#{member.id}'s", was.to_h, member.to_h) : []
56
+ end
57
+
58
+ #: (String, Hash[String, untyped], Hash[String, untyped]) -> Array[String]
59
+ def differing(whose, was, now)
60
+ (was.keys | now.keys).reject { |field| was[field] == now[field] }.map do |field|
61
+ "#{whose} #{field} was #{JSON.generate(was[field])} and is now #{JSON.generate(now[field])}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -144,6 +144,10 @@ module Principles
144
144
  @files.relative(id)
145
145
  end
146
146
 
147
+ # Map id's file and each file holding one of its members, which a full audit judges as committed.
148
+ #: (String, PrincipleMembers) -> Array[String]
149
+ def audited_files(id, members) = [file(id), *members.paths]
150
+
147
151
  # The file map id was kept in under the folder's earlier name, relative to the project.
148
152
  #: (String) -> String
149
153
  def earlier_file(id)
@@ -3,15 +3,36 @@
3
3
 
4
4
  require_relative "member_file"
5
5
  require_relative "frontmatter_fields"
6
+ require_relative "prose_line"
6
7
 
7
8
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
10
  module Models
10
11
  # A Markdown file, where a member may be a section: a heading and what follows it, up to the next heading
11
12
  # at its level or above.
12
13
  class MarkdownFile < MemberFile
14
+ # The last line of the paragraph or list item that a passage named by its opening alone maps only the first
15
+ # line of, so the agent can judge whether it meant the whole; nil when no line continues it.
16
+ #: (Locator) -> Integer?
17
+ def continues_to(locator)
18
+ return unless locator.starting_at && !locator.ending_at
19
+
20
+ last = locate(locator).last_line
21
+ ending = block_end(last)
22
+ ending unless ending == last
23
+ end
24
+
13
25
  private
14
26
 
27
+ # The last line of the paragraph or list item that line, counted from 1, is in, read on from it; the line
28
+ # itself for a heading, a block of its own line.
29
+ #: (Integer) -> Integer
30
+ def block_end(line)
31
+ return line if ProseLine.new(@text.lines.fetch(line - 1)).heading?
32
+
33
+ line + @text.lines.drop(line).take_while { ProseLine.new(it).continues? }.length
34
+ end
35
+
15
36
  # The frontmatter field the reference's query names, or the section under its heading, or the whole text.
16
37
  #: (Array[String], Locator) -> [Integer, Integer]
17
38
  def region(lines, locator)
@@ -7,7 +7,7 @@ require_relative "meta_principle"
7
7
  require_relative "report_hooks"
8
8
 
9
9
  module Principles
10
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
12
  # One member of a principle as its map records it: a file, a Markdown section of it, or a passage
13
13
  # starting at a quoted first line. Its id names all three, so an agent can read where the member is
@@ -5,7 +5,7 @@ require_relative "line_span"
5
5
  require_relative "member"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # A member of another principle's map whose text shares a line with one located member: its principle, id,
11
11
  # role there and lines, and how its lines stand to the located member's: the same lines, all of them, within
@@ -9,7 +9,7 @@ require_relative "located_text"
9
9
  require_relative "write_up_opening"
10
10
 
11
11
  module Principles
12
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
12
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
13
13
  module Models
14
14
  # The text of one project file, as the type that knows how to find a member in it. It holds text, not a
15
15
  # file, so the same rules apply to a file on disk and to the file at a commit. Each type finds the region
@@ -78,6 +78,11 @@ module Principles
78
78
  found
79
79
  end
80
80
 
81
+ # The last line of the paragraph or list item that a passage named by its opening alone maps only the first
82
+ # line of; nil here, since only Markdown has such blocks, which MarkdownFile finds.
83
+ #: (Locator) -> Integer?
84
+ def continues_to(_locator) = nil
85
+
81
86
  # The lines of the region locator names, as the agent reads them.
82
87
  #: (Locator) -> Array[String]
83
88
  def lines_of(locator)
@@ -4,7 +4,7 @@
4
4
  require_relative "recorded_entry"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # The member hashes an audit record holds, read from a record a later copy wrote that this copy's schema refuses,
10
10
  # for list-member-problems to compare its members with, read-only. Only those fields are read, each entry
@@ -19,7 +19,7 @@ module Principles
19
19
  freeze
20
20
  end
21
21
 
22
- # Each member's hash by the key it was recorded under, as RecordedMembers#hashes_by_key gives a readable one.
22
+ # Each member's hash by the key it was recorded under, as RecordedMembers#hashes gives a readable one.
23
23
  #: Hash[String, String]
24
24
  attr_reader :by_key
25
25
 
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The commits that changed one member's own text since this tool last knew it, newest first. The walk goes
8
8
  # back from HEAD and stops at the first commit whose text for the member hashes to the baseline, so a fix
@@ -5,7 +5,7 @@ require_relative "changed_regions"
5
5
  require_relative "line_diff"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # A member's own lines at its baseline and now, as a one-member audit's request shows them, so the agent reads
11
11
  # the change its quotes are checked against and not the rest of an edit to the file. A long member, such
@@ -5,6 +5,7 @@ require_relative "member_loads"
5
5
  require_relative "loading_scope"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # One map's per-member loading scopes and the scope an added member newly represents.
10
11
  class MemberLoadingScopes
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "json"
5
+ require_relative "member"
5
6
  require_relative "project_history"
6
7
 
7
8
  module Principles
@@ -9,9 +10,8 @@ module Principles
9
10
  module Models
10
11
  # One member key's ordered historical placements and its oldest locatable mapping baseline.
11
12
  class MemberMappingRun
12
- #: (String, Array[[String, Hash[String, untyped]]]) -> void
13
- def initialize(key, entries)
14
- @key = key.dup.freeze #: String
13
+ #: (Array[[String, Hash[String, untyped]]]) -> void
14
+ def initialize(entries)
15
15
  @entries = JSON.parse(JSON.generate(entries), freeze: true) #: Array[[String, Hash[String, untyped]]]
16
16
  freeze
17
17
  end
@@ -19,7 +19,7 @@ module Principles
19
19
  #: (ProjectHistory) -> Hash[String, String]?
20
20
  def baseline(history)
21
21
  @entries.reverse_each do |sha, fields|
22
- hash = history.at(sha).hashes_by_key([fields])[@key] or next
22
+ hash = history.at(sha).hash_of(Member.new(fields)) or next
23
23
 
24
24
  return { "commit" => sha, "sha256" => hash }
25
25
  end
@@ -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
@@ -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,7 +9,7 @@ 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
@@ -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
@@ -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
@@ -15,6 +15,7 @@ require_relative "reported_check"
15
15
  require_relative "shape_problems_beside"
16
16
 
17
17
  module Principles
18
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
18
19
  module Models
19
20
  # The text in an answer that ends as this tool's placeholders end, "Leave as printed ...", "else leave" or "else
20
21
  # kept", or is a placeholder some template of this release prints, but is none the request's own template
@@ -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.
@@ -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
  # One heading of a candidate file's outline and the top-level list items under it, with the lines of the file it
8
8
  # spans, so an outline whose items are cut can say where to read them back.
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "../prose_list"
6
6
 
7
7
  module Principles
8
- # The domain of principles and their maps: each model owns its rules and loads and saves itself through data/.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The part start-audit --part names, printed alone from the request a full audit asks, so an agent that needs one
11
11
  # part of it need not read the whole request or script it. Only a part the request has, or leaves
@@ -4,7 +4,7 @@
4
4
  require_relative "member_file"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # A file that is not Markdown, such as a script or a config file. It has no sections, so a member is the
10
10
  # whole file or a passage of it, and a # line is never read as a heading.
@@ -61,7 +61,7 @@ module Principles
61
61
  #: (Array[String]) -> Hash[String, Hash[String, String]]
62
62
  def mapped_baselines(keys)
63
63
  runs(keys).each_with_object({}) do |(key, run), found|
64
- baseline = MemberMappingRun.new(key, run).baseline(@history)
64
+ baseline = MemberMappingRun.new(run).baseline(@history)
65
65
  found[key] = baseline if baseline
66
66
  end
67
67
  end
@@ -157,7 +157,7 @@ module Principles
157
157
  fields_at = [members_at(commit)&.fetch(key, nil), now_at].compact
158
158
  fields_at.uniq { |fields| Member.new(fields).reference }.map do |fields|
159
159
  Placement.new(commit: commit, reference: Member.new(fields).reference,
160
- sha256: @history.at(commit).hashes_by_key([fields]).values.first)
160
+ sha256: @history.at(commit).hash_of(Member.new(fields)))
161
161
  end
162
162
  end
163
163
 
@@ -176,7 +176,7 @@ module Principles
176
176
  def hash_at(key, now_at, revision)
177
177
  fields = members_at(revision)&.fetch(key, nil) or return nil
178
178
  then_project = @history.at(revision)
179
- then_project.hashes_by_key([fields])[key] || then_project.hashes_by_key([now_at])[key]
179
+ then_project.hash_of(Member.new(fields)) || then_project.hash_of(Member.new(now_at))
180
180
  end
181
181
 
182
182
  # Each member the map at commit holds, by key. Legacy unreadable maps give nil; certified proof failures
@@ -6,7 +6,7 @@ require_relative "member"
6
6
  require_relative "misspelt_member_id"
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
  # One principle's members, as Members: finding one by its id, and the rules on ids and keys among them,
12
12
  # which Principle asks as it changes the map. It is Enumerable over its members, in the map's order.