principles 0.0.1 → 0.0.4

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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +7 -1
  3. data/lib/principles/command_line.rb +12 -29
  4. data/lib/principles/controllers/acknowledgement.rb +4 -4
  5. data/lib/principles/controllers/answer.rb +64 -100
  6. data/lib/principles/controllers/assessment.rb +108 -0
  7. data/lib/principles/controllers/audit.rb +29 -135
  8. data/lib/principles/controllers/audit_completion.rb +2 -4
  9. data/lib/principles/controllers/command.rb +27 -13
  10. data/lib/principles/controllers/correction.rb +4 -4
  11. data/lib/principles/controllers/full_audit_request.rb +180 -0
  12. data/lib/principles/controllers/inventory.rb +32 -70
  13. data/lib/principles/controllers/mapping.rb +3 -3
  14. data/lib/principles/controllers/member_entries.rb +24 -12
  15. data/lib/principles/controllers/member_problems_report.rb +72 -0
  16. data/lib/principles/controllers/members_a_commit_changed.rb +10 -2
  17. data/lib/principles/controllers/members_to_assess.rb +16 -9
  18. data/lib/principles/controllers/meta_principle_setup.rb +5 -5
  19. data/lib/principles/controllers/repoint.rb +1 -1
  20. data/lib/principles/controllers/running_tool.rb +1 -1
  21. data/lib/principles/data/audit_files.rb +11 -7
  22. data/lib/principles/data/bounded_file.rb +11 -0
  23. data/lib/principles/data/command-steps.json +7 -6
  24. data/lib/principles/data/map_files.rb +2 -2
  25. data/lib/principles/data/principles_subfolder.rb +8 -1
  26. data/lib/principles/data/project_files.rb +1 -7
  27. data/lib/principles/data/project_root.rb +48 -0
  28. data/lib/principles/data/schema_check.rb +23 -5
  29. data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
  30. data/lib/principles/data/schemas/audit-record.schema.json +3 -0
  31. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  32. data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
  33. data/lib/principles/invocation_options.rb +1 -1
  34. data/lib/principles/models/assessment_answer.rb +64 -17
  35. data/lib/principles/models/audit.rb +24 -15
  36. data/lib/principles/models/audit_record.rb +10 -3
  37. data/lib/principles/models/audit_records.rb +74 -4
  38. data/lib/principles/models/audit_start.rb +3 -3
  39. data/lib/principles/models/carried_assessments.rb +1 -1
  40. data/lib/principles/models/check_since_last_audit.rb +6 -6
  41. data/lib/principles/models/correction_basis.rb +1 -1
  42. data/lib/principles/models/decided_prior_findings.rb +9 -19
  43. data/lib/principles/models/declared_map_changes.rb +8 -8
  44. data/lib/principles/models/disposition.rb +28 -24
  45. data/lib/principles/models/evidence_replacements.rb +8 -1
  46. data/lib/principles/models/fix_only_fields.rb +67 -0
  47. data/lib/principles/models/kept_prior_finding.rb +12 -7
  48. data/lib/principles/models/loaded_files.rb +5 -3
  49. data/lib/principles/models/loading_decision.rb +9 -2
  50. data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
  51. data/lib/principles/models/member.rb +1 -1
  52. data/lib/principles/models/member_assessments.rb +48 -3
  53. data/lib/principles/models/member_grounds.rb +2 -2
  54. data/lib/principles/models/member_hashes_as_written.rb +40 -0
  55. data/lib/principles/models/member_moves.rb +3 -3
  56. data/lib/principles/models/member_problems.rb +38 -18
  57. data/lib/principles/models/members_sharing_lines.rb +3 -3
  58. data/lib/principles/models/new_findings.rb +55 -0
  59. data/lib/principles/models/open_finding.rb +23 -13
  60. data/lib/principles/models/other_principles.rb +1 -1
  61. data/lib/principles/models/other_templates_placeholders.rb +74 -0
  62. data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
  63. data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
  64. data/lib/principles/models/{map_members.rb → principle_members.rb} +4 -4
  65. data/lib/principles/models/prior_decision_fields.rb +46 -0
  66. data/lib/principles/models/prior_finding_decision.rb +24 -3
  67. data/lib/principles/models/prior_finding_outcomes.rb +10 -3
  68. data/lib/principles/models/prior_findings.rb +1 -1
  69. data/lib/principles/models/problem_report.rb +7 -3
  70. data/lib/principles/models/project.rb +27 -13
  71. data/lib/principles/models/project_history.rb +2 -2
  72. data/lib/principles/models/recent_decision.rb +90 -0
  73. data/lib/principles/models/record_format.rb +105 -0
  74. data/lib/principles/models/recorded_finding.rb +4 -0
  75. data/lib/principles/models/recorded_hashes.rb +39 -0
  76. data/lib/principles/models/recorded_members.rb +17 -12
  77. data/lib/principles/models/reported_check.rb +63 -11
  78. data/lib/principles/models/request_id.rb +24 -4
  79. data/lib/principles/models/sent_prior_decisions.rb +31 -0
  80. data/lib/principles/models/still_holds_restatement.rb +7 -10
  81. data/lib/principles/models/template_placeholders.rb +41 -0
  82. data/lib/principles/session_start_options.rb +29 -0
  83. data/lib/principles/start_audit_options.rb +37 -0
  84. data/lib/principles/version.rb +2 -2
  85. data/lib/principles/views/answer_head.rb +29 -0
  86. data/lib/principles/views/assessed_members.rb +96 -0
  87. data/lib/principles/views/assessment_request.rb +51 -49
  88. data/lib/principles/views/audit_result.rb +38 -42
  89. data/lib/principles/views/check_result_template.rb +31 -10
  90. data/lib/principles/views/correction_request.rb +64 -0
  91. data/lib/principles/views/first_audit.rb +71 -0
  92. data/lib/principles/views/help.rb +3 -2
  93. data/lib/principles/views/loads_to_check_result.rb +11 -4
  94. data/lib/principles/views/map_added_to.rb +31 -0
  95. data/lib/principles/views/map_result.rb +37 -22
  96. data/lib/principles/views/members_a_commit_changed.rb +30 -10
  97. data/lib/principles/views/meta_principle_result.rb +3 -14
  98. data/lib/principles/views/principle_read_result.rb +27 -10
  99. data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
  100. data/lib/principles/views/prior_findings_result.rb +7 -3
  101. data/lib/principles/views/problem_lines.rb +14 -11
  102. data/lib/principles/views/problem_result.rb +30 -16
  103. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +3 -2
  104. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
  105. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  106. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  107. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
  108. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +1 -1
  109. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
  110. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
  111. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +22 -20
  112. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +8 -5
  113. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +3 -0
  114. data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
  115. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +6 -0
  116. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
  117. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +2 -1
  118. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
  119. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  120. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +37 -37
  121. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
  122. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +1 -0
  123. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
  124. data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
  125. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +2 -1
  126. data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
  127. data/lib/principles/views/request_part.rb +14 -2
  128. data/lib/principles/views/request_parts.rb +4 -0
  129. metadata +33 -7
@@ -3,14 +3,14 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "../data/map_files"
6
- require_relative "member_map"
6
+ require_relative "principle"
7
7
  require_relative "meta_principle"
8
8
 
9
9
  module Principles
10
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
- # Every member map in the project, loaded and saved through Data::MapFiles.
13
- class MemberMaps
12
+ # Every principle the project maps, each loaded and saved as its map through Data::MapFiles.
13
+ class MappedPrinciples
14
14
  # A principle id names its principle in lower-kebab-case.
15
15
  ID_FORMAT = Data::PrincipleId::FORMAT #: Regexp
16
16
 
@@ -63,39 +63,39 @@ module Principles
63
63
  end
64
64
 
65
65
  # The map named id, refused when there is none; Data::MapFiles refuses one that is unparseable.
66
- #: (String) -> MemberMap
66
+ #: (String) -> Principle
67
67
  def find(id)
68
68
  refuse_unknown(id)
69
- unique(MemberMap.new(id, @files.read(id)))
69
+ unique(Principle.new(id, @files.read(id)))
70
70
  end
71
71
 
72
72
  # The map id as text read elsewhere holds it, such as its file at commit, the one an audit began from.
73
- #: (String, String, ?commit: String?) -> MemberMap
73
+ #: (String, String, ?commit: String?) -> Principle
74
74
  def parsed(id, text, commit: nil)
75
- unique(MemberMap.new(id, @files.parse(id, text, commit: commit)), commit)
75
+ unique(Principle.new(id, @files.parse(id, text, commit: commit)), commit)
76
76
  end
77
77
 
78
78
  # A new map for id with no members, not yet saved. It is refused unless id is lower-kebab-case and not
79
79
  # yet mapped, and is not the meta-principle's, which setup starts; only then is the description asked for.
80
- #: (String) { () -> String } -> MemberMap
80
+ #: (String) { () -> String } -> Principle
81
81
  def create(id, &)
82
82
  refuse_unavailable(id)
83
83
  refuse_meta_principle_id(id)
84
- MemberMap.new(id, { "description" => yield, "members" => [] })
84
+ Principle.new(id, { "description" => yield, "members" => [] })
85
85
  end
86
86
 
87
87
  # The map a new member of principle id joins: the map named id, or, while the meta-principle has none, the map
88
88
  # it starts with, not yet saved, so that map is written only with its first member (T74). Any other id no map
89
89
  # has is refused, as find refuses it.
90
- #: (String) -> MemberMap
90
+ #: (String) -> Principle
91
91
  def addable(id)
92
92
  return find(id) if mapped?(id) || !started_by_setup?(id)
93
93
 
94
- MemberMap.new(id, MetaPrinciple.starting_fields)
94
+ Principle.new(id, MetaPrinciple.starting_fields)
95
95
  end
96
96
 
97
97
  # The map named id, refused when it has no members to audit.
98
- #: (String) -> MemberMap
98
+ #: (String) -> Principle
99
99
  def auditable(id)
100
100
  map = find(id)
101
101
  return map unless map.members.empty?
@@ -105,7 +105,7 @@ module Principles
105
105
  end
106
106
 
107
107
  # Writes map's file and names it, relative to the project.
108
- #: (MemberMap) -> String
108
+ #: (Principle) -> String
109
109
  def save(map)
110
110
  @files.write(map.id, map.to_h)
111
111
  file(map.id)
@@ -130,8 +130,8 @@ module Principles
130
130
  #: (String) -> bool
131
131
  def started_by_setup?(id) = id == MetaPrinciple::ID
132
132
 
133
- # map, refused when two of its members share an id or a key, as MapMembers#refuse_repeats says.
134
- #: (MemberMap, ?String?) -> MemberMap
133
+ # map, refused when two of its members share an id or a key, as PrincipleMembers#refuse_repeats says.
134
+ #: (Principle, ?String?) -> Principle
135
135
  def unique(map, commit = nil)
136
136
  where = commit ? "#{file(map.id)} at commit #{commit[0, 12]}" : file(map.id)
137
137
  map.members.refuse_repeats(where: where, file: file(map.id))
@@ -35,7 +35,7 @@ module Principles
35
35
  LOCATORS = %w[path section starting_at ending_at query].freeze #: [String, String, String, String, String]
36
36
 
37
37
  # fields is copied and frozen, so no caller changes a member through the hash it was built from or handed;
38
- # the copy is shallow, so its strings are the caller's. MemberMap builds its members from strings it has
38
+ # the copy is shallow, so its strings are the caller's. Principle builds its members from strings it has
39
39
  # copied and frozen, so a member in a map shares nothing (#654).
40
40
  #: (Hash[String, untyped]) -> void
41
41
  def initialize(fields)
@@ -6,11 +6,12 @@ require_relative "locator"
6
6
  require_relative "answer_fields"
7
7
  require_relative "answer_place"
8
8
  require_relative "carried_assessments"
9
- require_relative "map_members"
9
+ require_relative "principle_members"
10
10
  require_relative "member_sighting"
11
11
  require_relative "misspelt_member_id"
12
12
  require_relative "record_judged_against"
13
13
  require_relative "reported_check"
14
+ require_relative "template_placeholders"
14
15
 
15
16
  module Principles
16
17
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -22,15 +23,27 @@ module Principles
22
23
  # What a record entry keeps for a member carried forward, until completion puts back its last assessment.
23
24
  CARRIED = { "carried_forward" => true }.freeze #: Hash[String, untyped]
24
25
 
26
+ # The text a fresh member's template prints in its assessment, which an answer may not send back unchanged, as a
27
+ # correction may not send back its own (#991).
28
+ PLACEHOLDER = "Your assessment, including its context cost" #: String
29
+
30
+ # The text the template printed alone gives a sighting's fields beside delivery, each left as printed when the
31
+ # delivery gives none (#1010).
32
+ SIGHTING = TemplatePlaceholders.new(
33
+ { "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
+ ) #: TemplatePlaceholders
36
+
25
37
  # assessments is the answer's member_assessments; members are the mapped members, with each checked one's
26
38
  # check; fields checks each field and locates each piece of evidence; judged_against is the principle's record
27
39
  # as it stands, which says which members' last assessments may be carried forward, marked {"member_id",
28
40
  # "carried_forward": true} (D49), and which command it ran for each member's check (D63); answered_at is when
29
41
  # the answer came, which no sighting it reports is after (#699).
30
- #: (untyped, MapMembers, fields: AnswerFields, answered_at: String, ?judged_against: RecordJudgedAgainst?)
42
+ #: (untyped, PrincipleMembers, fields: AnswerFields, answered_at: String, ?judged_against: RecordJudgedAgainst?)
31
43
  #| -> void
32
44
  def initialize(assessments, members, fields:, answered_at:, judged_against: nil)
33
- @assessments = assessments
45
+ @sent = assessments #: untyped
46
+ @assessments = given(assessments) #: untyped
34
47
  @members = members
35
48
  @answered_at = answered_at
36
49
  @fields = fields
@@ -47,6 +60,21 @@ module Principles
47
60
  assessments.each_with_index { |assessment, index| member_assessment(assessment, place_of(assessment, index)) }
48
61
  end
49
62
 
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
+
50
78
  # The result reported for each checked member's check, by member id, once each has been checked. Call it after
51
79
  # check, which refuses an unmapped id first: finding the command the record ran needs each member's key.
52
80
  #: () -> Hash[String, Hash[String, untyped]]
@@ -73,6 +101,23 @@ module Principles
73
101
 
74
102
  private
75
103
 
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
+ # assessments without the sighting fields each leaves as printed, which it does not give (#1010).
114
+ #: (untyped) -> untyped
115
+ def given(assessments)
116
+ return assessments unless assessments.is_a?(Array)
117
+
118
+ assessments.map { |assessment| assessment.is_a?(Hash) ? SIGHTING.given(assessment) : assessment }
119
+ end
120
+
76
121
  # Refuses answered, the ids the assessments name, unless they are the mapped ids, each once, hinting at any
77
122
  # mapped id an unmapped one is spelled like.
78
123
  #: (Array[untyped]) -> void
@@ -3,7 +3,7 @@
3
3
 
4
4
  require_relative "json_digest"
5
5
  require_relative "loading_facts"
6
- require_relative "map_members"
6
+ require_relative "principle_members"
7
7
  require_relative "member_loads"
8
8
 
9
9
  module Principles
@@ -14,7 +14,7 @@ module Principles
14
14
  # keeps a digest of each with the assessment, and carries the assessment forward only while both match (D49).
15
15
  class MemberGrounds
16
16
  # members are the map's members; loads is each member's MemberLoads by id.
17
- #: (MapMembers, Hash[String, MemberLoads]) -> void
17
+ #: (PrincipleMembers, Hash[String, MemberLoads]) -> void
18
18
  def initialize(members, loads)
19
19
  @members = members.by_id #: Hash[String, Member]
20
20
  @loads = loads
@@ -0,0 +1,40 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "recorded_members"
5
+
6
+ module Principles
7
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The member hashes an audit record holds, read from a record a later copy wrote that this copy's schema refuses,
10
+ # for list-member-problems to compare its members with, read-only (#1066). Only those fields are read, each entry
11
+ # kept only when its hash is text, so nothing else of a shape this copy does not know travels; a member left out
12
+ # is compared with the commit that mapped it instead.
13
+ class MemberHashesAsWritten
14
+ # fields is the record as its file holds it, or anything else JSON may give.
15
+ #: (untyped) -> void
16
+ def initialize(fields)
17
+ members = fields["members"] if fields.is_a?(Hash)
18
+ @by_key = (members.is_a?(Hash) ? kept(members) : {}).freeze #: Hash[String, String]
19
+ freeze
20
+ end
21
+
22
+ # Each member's hash by the key it was recorded under, as RecordedMembers#hashes_by_key gives a readable one.
23
+ #: Hash[String, String]
24
+ attr_reader :by_key
25
+
26
+ private
27
+
28
+ # Each entry whose hash and key, as RecordedMembers.filed_key gives it, are text.
29
+ #: (Hash[untyped, untyped]) -> Hash[String, String]
30
+ def kept(members)
31
+ 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)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "member"
6
- require_relative "member_map"
6
+ require_relative "principle"
7
7
 
8
8
  module Principles
9
9
  # The domain: maps, audits and command steps, with every rule a schema cannot express.
@@ -34,7 +34,7 @@ module Principles
34
34
  end
35
35
 
36
36
  # The base map with each declared member moved to its place in current, each keeping its role.
37
- #: (MemberMap, MemberMap) -> MemberMap
37
+ #: (Principle, Principle) -> Principle
38
38
  def applied(base, current)
39
39
  @moves.reduce(base) { |map, (from, to)| map.moving(from, located(current, to)) }
40
40
  end
@@ -81,7 +81,7 @@ module Principles
81
81
  end
82
82
 
83
83
  # The current member to's place in its file, without its role.
84
- #: (MemberMap, String) -> Hash[String, untyped]
84
+ #: (Principle, String) -> Hash[String, untyped]
85
85
  def located(current, to)
86
86
  unless current.members.taken?(to)
87
87
  raise Error.new("unknown_member", "#{to} is not a member of #{current.id}",
@@ -3,8 +3,8 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "audit_record"
6
- require_relative "map_members"
7
- require_relative "member_map_history"
6
+ require_relative "principle_members"
7
+ require_relative "principle_history"
8
8
  require_relative "member_state"
9
9
  require_relative "locate_refusal"
10
10
 
@@ -21,31 +21,38 @@ module Principles
21
21
  class Baselines
22
22
  # The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
23
23
  # where it is, read with the map as that commit held it; none outside git.
24
- #: (Project, MapMembers) -> Baselines
24
+ #: (Project, PrincipleMembers) -> Baselines
25
25
  def self.of(project, members)
26
26
  id = members.principle_id
27
- audit = project.audit_records.find(id)
28
- mapped = MemberMapHistory.new(id: id, history: project.history, member_maps: project.member_maps)
27
+ audit, hashes = project.audit_records.for_comparison(id)
28
+ mapped = PrincipleHistory.new(id: id, history: project.history, principles: project.principles)
29
29
  .mapped_baselines(members.keys)
30
30
  new(audit: audit, mapped: mapped.transform_values { |each| each.fetch("sha256") },
31
- mapped_in: mapped.transform_values { |each| each.fetch("commit") }, in_git: project.history.inside_git?)
31
+ mapped_in: mapped.transform_values { |each| each.fetch("commit") }, in_git: project.history.inside_git?,
32
+ hashes: hashes)
32
33
  end
33
34
 
34
35
  # Whether the project is in git, so a member with no baseline is one no commit holds yet.
35
36
  #: bool
36
37
  attr_reader :in_git
37
38
 
39
+ # Whether a later copy wrote the principle's record, so its audits and acknowledgements wait on an upgrade.
40
+ #: bool
41
+ attr_reader :waiting
42
+
38
43
  # audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
39
- # completed, so a one-member audit is offered only where one would be accepted (#626).
40
- #: (audit: AuditRecord?, mapped: Hash[String, String], mapped_in: Hash[String, String], in_git: bool)
41
- #| -> void
42
- def initialize(audit:, mapped:, mapped_in:, in_git:)
43
- @audited = audit&.members&.hashes_by_key || {} #: Hash[String, String]
44
+ # completed, so a one-member audit is offered only where one would be accepted (#626). hashes is the member
45
+ # hashes the record holds, which a later copy may have written, so its members are compared read-only (#1066).
46
+ #: (audit: AuditRecord?, mapped: Hash[String, String], mapped_in: Hash[String, String], in_git: bool,
47
+ #| ?hashes: RecordedHashes) -> void
48
+ def initialize(audit:, mapped:, mapped_in:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE)
49
+ @audited = hashes.by_key #: Hash[String, String]
44
50
  @audit = audit #: AuditRecord?
45
51
  @audit_base = audit&.base_commit #: String?
46
52
  @mapped = mapped
47
53
  @mapped_in = mapped_in
48
54
  @in_git = in_git
55
+ @waiting = hashes.waiting? #: bool
49
56
  freeze
50
57
  end
51
58
 
@@ -82,7 +89,7 @@ module Principles
82
89
  #: (Member, String?) -> bool
83
90
  def acknowledgeable?(member, now_sha256)
84
91
  audit = @audit
85
- @in_git && !audit.nil? && audit.acknowledgement_refusal(member, now_sha256:).nil?
92
+ @in_git && !@waiting && !audit.nil? && audit.acknowledgement_refusal(member, now_sha256:).nil?
86
93
  end
87
94
  end
88
95
 
@@ -90,18 +97,18 @@ module Principles
90
97
  # refused when it was asked for, and listed as broken among every map.
91
98
  #: (Project, String, ?listing_all: bool) -> MemberProblems
92
99
  def self.for(project, id, listing_all: false)
93
- members = project.member_maps.find(id).members
100
+ members = project.principles.find(id).members
94
101
  new(members: members, now: project.current_by_key(members), baselines: Baselines.of(project, members))
95
102
  rescue Error => e
96
103
  raise unless listing_all
97
104
 
98
- none = MapMembers.new(id, [])
105
+ none = PrincipleMembers.new(id, [])
99
106
  new(members: none, now: {}, baselines: Baselines.of(project, none), unreadable: e.payload)
100
107
  end
101
108
 
102
109
  # now holds, for each member by key, its hash now or the refusal that says why it cannot be found.
103
110
  # unreadable is the refusal for a map this tool could not read, which is listed as one broken entry.
104
- #: (members: MapMembers, now: Hash[String, untyped],
111
+ #: (members: PrincipleMembers, now: Hash[String, untyped],
105
112
  #| baselines: Baselines, ?unreadable: Hash[String, untyped]?) -> void
106
113
  def initialize(members:, now:, baselines:, unreadable: nil)
107
114
  @members = members
@@ -130,7 +137,12 @@ module Principles
130
137
  # Whether a member an audit or acknowledgement assessed changed since, rather than only a member edited since
131
138
  # the commit that mapped it, which no audit assessed (D44).
132
139
  #: () -> bool
133
- def assessed_change? = changed_members.any? { |member| assessed?(member) }
140
+ def assessed_change? = changes_to_act_on.any? { |member| assessed?(member) }
141
+
142
+ # Whether a member no audit assessed was edited since the commit that mapped it, which --short exits 4 for
143
+ # when it is the only kind of change (D44).
144
+ #: () -> bool
145
+ def unassessed_change? = changes_to_act_on.any? { |member| !assessed?(member) }
134
146
 
135
147
  # The entries whose own text changed since this tool last knew it, those an audit assessed first. Given a
136
148
  # block, each gains "history", what the block makes of its member, the hash it was compared with, and its
@@ -188,7 +200,7 @@ module Principles
188
200
  # one (D58, #731 R7).
189
201
  #: () -> bool
190
202
  def awaits_first_audit?
191
- return false unless @baselines.no_completed_audit?
203
+ return false if @baselines.waiting || !@baselines.no_completed_audit?
192
204
 
193
205
  bases = compared_with.keys
194
206
  @baselines.in_git ? bases.any? { it != "no_baseline" } : !bases.empty?
@@ -222,6 +234,11 @@ module Principles
222
234
  @members.select { |member| entry(member).fetch("state") == "changed" }
223
235
  end
224
236
 
237
+ # The changed members this copy can act on: none while a later copy's record makes them wait on an upgrade,
238
+ # so they give --short neither exit 3 nor 4 (D85 V8, #1066).
239
+ #: () -> Array[Member]
240
+ def changes_to_act_on = @baselines.waiting ? [] : changed_members
241
+
225
242
  #: (Member) -> bool
226
243
  def assessed?(member) = baseline(member.key).last&.fetch("baseline") == "audit"
227
244
 
@@ -241,7 +258,10 @@ module Principles
241
258
  def compared(listed, key, sha)
242
259
  then_sha, since = baseline(key)
243
260
  return listed.merge("state" => "no_baseline") unless since
244
- return listed.merge("state" => "changed", "since" => since) unless then_sha == sha
261
+ unless then_sha == sha
262
+ return listed.merge("state" => "changed", "since" => since,
263
+ **(@baselines.waiting ? { "waiting_on_an_upgrade" => true } : {}))
264
+ end
245
265
 
246
266
  listed.merge("state" => since["baseline"] == "mapping_commit" ? "unchanged_since_mapping" : "unchanged")
247
267
  end
@@ -51,7 +51,7 @@ module Principles
51
51
  # The members sharing a line with the located one, beside map, its own: those in map, those of them on exactly
52
52
  # its lines, and those in the other maps, as plain values, with whether the agent should check the text where
53
53
  # one of those holds the other's lines without being a whole file (#756).
54
- #: (MemberMap)
54
+ #: (Principle)
55
55
  #| -> { overlaps: Array[String], same_lines_as: Array[String], mapped_elsewhere: Array[Hash[String, untyped]],
56
56
  #| text_check: bool }
57
57
  def facts_beside(map)
@@ -70,14 +70,14 @@ module Principles
70
70
  # reports it.
71
71
  #: (except: String) -> MembersElsewhere
72
72
  def elsewhere(except:)
73
- maps = @project.member_maps
73
+ maps = @project.principles
74
74
  MembersElsewhere.new((maps.ids - [except]).flat_map { |id| sharing_in(maps, id) })
75
75
  end
76
76
 
77
77
  private
78
78
 
79
79
  # The members of map id sharing a line with the located member, or none when that map cannot be read.
80
- #: (MemberMaps, String) -> Array[MemberElsewhere]
80
+ #: (MappedPrinciples, String) -> Array[MemberElsewhere]
81
81
  def sharing_in(maps, id)
82
82
  sharing(maps.find(id).members.to_a).map do |member, found|
83
83
  MemberElsewhere.new(principle_id: id, member:, span: found.span(whole_file: member.whole_file?),
@@ -0,0 +1,55 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "template_placeholders"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The findings an assessment answer raises, as start-audit --as template prints one to fill: a finding sent back
10
+ # exactly as printed raises none, and one otherwise filled may not keep a text field as printed (#1010).
11
+ class NewFindings
12
+ # The text fields of the printed finding, which their own check accepts as written text, so a field left as
13
+ # printed in a finding otherwise filled is refused here (#1010). A member id or evidence left as printed is
14
+ # refused by its own check.
15
+ TEXT = TemplatePlaceholders.new(
16
+ { "id" => "Only for a problem you found: an id such as F1. Leave this finding as printed to raise none",
17
+ "problem" => "What is wrong, in the members' own words",
18
+ "consequence" => "What it costs an agent that reads them",
19
+ "proposed_action" => "What would fix it. Fixing, deferring or accepting it is decided in the correction" }
20
+ ) #: TemplatePlaceholders
21
+
22
+ # The finding the template printed alone gives to fill, which an answer leaves as printed to raise none; whether
23
+ # to fix, defer or accept a finding is the correction's, so the finding itself carries none (#1010).
24
+ TEMPLATE = {
25
+ "id" => TEXT.fetch("id"), "member_ids" => ["The id of each member it concerns"],
26
+ "problem" => TEXT.fetch("problem"), "consequence" => TEXT.fetch("consequence"),
27
+ "proposed_action" => TEXT.fetch("proposed_action"),
28
+ "evidence" => [{ "path" => "Where it shows: a path, with heading, starting_at or query to narrow it" }]
29
+ }.freeze #: Hash[String, untyped]
30
+
31
+ # findings is the answer's findings as sent, a list once its shape is checked.
32
+ #: (Array[untyped]) -> void
33
+ def initialize(findings)
34
+ @findings = findings
35
+ freeze
36
+ end
37
+
38
+ # The findings the answer raises: each but one sent back as the template printed it.
39
+ #: () -> Array[untyped]
40
+ def raised = @findings.reject { it == TEMPLATE }
41
+
42
+ # Each text field a raised finding leaves as the template printed it, named by the finding's place and the
43
+ # field, with its pointer, which the answer refuses with every other judgement left so (#991, #1010).
44
+ #: () -> Hash[String, String]
45
+ def left_as_printed
46
+ @findings.each_with_index.flat_map do |finding, index|
47
+ next [] if !finding.is_a?(Hash) || finding == TEMPLATE
48
+
49
+ TEXT.to_h.keys.select { TEXT.left?(it, finding[it]) }
50
+ .map { ["Finding #{index + 1} #{it}", "/findings/#{index}/#{it}"] }
51
+ end.to_h
52
+ end
53
+ end
54
+ end
55
+ end
@@ -28,14 +28,14 @@ module Principles
28
28
  freeze
29
29
  end
30
30
 
31
- # The finding as list-open-findings prints it, with its principle, when its audit was made and when it was
32
- # first raised, so how long it has waited shows (#629), what it says it waits on, since when (D52), and the
33
- # evidence its record keeps, or that it keeps none (D64, #839).
31
+ # The finding as list-open-findings prints it, with its principle, why it was left open (#996), when its audit
32
+ # was made and when it was first raised, so how long it has waited shows (#629), what it says it waits on, since
33
+ # when (D52), and the evidence its record keeps, or that it keeps none (D64, #839).
34
34
  #: () -> Hash[String, untyped]
35
35
  def listed
36
36
  { "principle" => @principle_id, "finding_id" => id, "member_ids" => @finding.member_ids, **problem,
37
- "action" => @finding.action, "recorded_at" => recorded_at&.to_h, "audited_at" => @audited_at,
38
- "first_raised_at" => first_raised_at, **raised_in, **waiting, **kept_evidence }
37
+ "action" => @finding.action, **present("reason", @finding.reason), "recorded_at" => recorded_at&.to_h,
38
+ "audited_at" => @audited_at, "first_raised_at" => first_raised_at, **raised_in, **waiting, **kept_evidence }
39
39
  end
40
40
 
41
41
  # The finding as the next full audit's request lists it, with when it was first raised, and what it waits on,
@@ -52,7 +52,7 @@ module Principles
52
52
  # now, hashes_now: under its members' ids now, with whether each changed since the audit that left it open,
53
53
  # what its record did not keep of it, and the evidence it keeps, so the agent deciding it sees what it rests on
54
54
  # (#839). Given since, each evidence item also carries what since says of it now (#858, #877).
55
- #: (MapMembers, Hash[String, String]) ?{ (EvidenceItem) -> Hash[String, bool] }
55
+ #: (PrincipleMembers, Hash[String, String]) ?{ (EvidenceItem) -> Hash[String, bool] }
56
56
  #| -> Hash[String, untyped]
57
57
  def for_next_audit_against(members_now, hashes_now, &)
58
58
  finding = for_next_audit
@@ -63,11 +63,13 @@ module Principles
63
63
  end
64
64
 
65
65
  # The finding as the next full audit's record keeps it, before that audit's decision on it: under its members'
66
- # ids now, with its write-up, when it was first raised and the commit an earlier first_raised_at cited (D53).
67
- #: (MapMembers) -> Hash[String, untyped]
66
+ # ids now, with why it was left open (#996), its write-up, when it was first raised and the commit an earlier
67
+ # first_raised_at cited (D53).
68
+ #: (PrincipleMembers) -> Hash[String, untyped]
68
69
  def kept_against(members_now)
69
70
  { "id" => id, "member_ids" => ids_now(members_now), **problem, "action" => @finding.action,
70
- **present("recorded_at", recorded_at&.to_h), "first_raised_at" => first_raised_at, **raised_in }
71
+ **present("reason", @finding.reason), **present("recorded_at", recorded_at&.to_h),
72
+ "first_raised_at" => first_raised_at, **raised_in }
71
73
  end
72
74
 
73
75
  # The principle whose record left it open.
@@ -95,13 +97,21 @@ module Principles
95
97
  #: () -> Array[Hash[String, untyped]]?
96
98
  def evidence = @finding.evidence
97
99
 
100
+ # The problem it states, and the one a still_holds decision gives in its place, as the completed result names
101
+ # them, or nil when the decision gives none, its record states none or the two are the same (D82).
102
+ #: (String?) -> Hash[String, String]?
103
+ def restated(problem)
104
+ stated = @finding.problem
105
+ { "finding_id" => id, "replaced" => stated, "with" => problem } if stated && problem && problem != stated
106
+ end
107
+
98
108
  # Whether its record keeps the evidence it was raised with (D64).
99
109
  #: () -> bool
100
110
  def evidence_kept? = @finding.evidence_kept?
101
111
 
102
112
  # The ids now, as the next full audit's request lists them, of its members no longer in the map, which its
103
113
  # members_since calls removed.
104
- #: (MapMembers) -> Array[String]
114
+ #: (PrincipleMembers) -> Array[String]
105
115
  def removed_from(members_now) = ids_now(members_now).reject { |member_id| members_now.with_id(member_id) }
106
116
 
107
117
  # The new places a decision's problem_evidence gives the evidence its record keeps, so the check that an item is
@@ -170,13 +180,13 @@ module Principles
170
180
  private
171
181
 
172
182
  # Its members' ids now, each member found by key so a member renamed since keeps its new id (#772).
173
- #: (MapMembers) -> Array[String]
183
+ #: (PrincipleMembers) -> Array[String]
174
184
  def ids_now(members_now) = @finding.member_ids.map { |id| id_now(members_now, @members.key_of(id)) || id }
175
185
 
176
- #: (MapMembers, String) -> String?
186
+ #: (PrincipleMembers, String) -> String?
177
187
  def id_now(members_now, key) = members_now.with_key(key)&.id
178
188
 
179
- #: (MapMembers, Hash[String, String], String) -> String
189
+ #: (PrincipleMembers, Hash[String, String], String) -> String
180
190
  def since_this_audit(members_now, hashes_now, id)
181
191
  member = members_now.with_id(id) or return "removed"
182
192
  @members.freshness(member.key, hashes_now.fetch(id))
@@ -15,7 +15,7 @@ module Principles
15
15
  # cannot read is among them, as list-member-problems lists it.
16
16
  #: (Project, but: String) -> OtherPrinciples
17
17
  def self.of(project, but:)
18
- new((project.member_maps.ids - [but]).to_h { [it, MemberProblems.for(project, it, listing_all: true)] })
18
+ new((project.principles.ids - [but]).to_h { [it, MemberProblems.for(project, it, listing_all: true)] })
19
19
  end
20
20
 
21
21
  # problems maps each principle's id to its members' problems.