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
@@ -2,13 +2,9 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
- require_relative "members_a_commit_changed"
6
- require_relative "../models/member_problems"
5
+ require_relative "member_problems_report"
7
6
  require_relative "../models/member_state"
8
7
  require_relative "../models/meta_principle"
9
- require_relative "../models/problem_report"
10
- require_relative "../views/problem_result"
11
- require_relative "../views/problem_lines"
12
8
  require_relative "../views/candidate_files_result"
13
9
  require_relative "../views/principle_read_result"
14
10
 
@@ -17,7 +13,8 @@ module Principles
17
13
  # controllers/CLAUDE.md owns the boundary.
18
14
  module Controllers
19
15
  # The reads that show what a project holds: its candidate instruction files, its principles, and each
20
- # member and how fresh it is against the last audit. None changes anything on disk.
16
+ # member and how fresh it is against the last audit, handing list-member-problems to MemberProblemsReport. None
17
+ # changes anything on disk.
21
18
  class Inventory < Command
22
19
  #: (String, String?, Hash[String, untyped]) -> untyped
23
20
  def call(command, id, options)
@@ -25,7 +22,7 @@ module Principles
25
22
  case command
26
23
  when "list-candidate-files" then list_candidate_files.merge("wrote" => [])
27
24
  when "list-principles" then listing.merge("wrote" => [])
28
- when "list-member-problems" then problems_printed(id, options)
25
+ when "list-member-problems" then handed(MemberProblemsReport).printed(id, options)
29
26
  when "show-principle" then members(required_id(id)).merge("wrote" => [])
30
27
  else unknown(command)
31
28
  end
@@ -44,13 +41,13 @@ module Principles
44
41
  found = @project.candidate_files
45
42
  listed = Views::CandidateFilesResult::Found.new(inventory: found.to_h, untracked: found.untracked,
46
43
  owner_asks: found.owner_asks)
47
- Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @member_maps.ids,
48
- map_file: @member_maps.file("ID"), set_up: set_up?)
44
+ Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
45
+ map_file: @principles.file("ID"), set_up: set_up?)
49
46
  end
50
47
 
51
48
  #: (String) -> untyped
52
49
  def members(id)
53
- principle = @member_maps.find(id)
50
+ principle = @principles.find(id)
54
51
  audit = @audit_records.find(id)
55
52
  hooks = @project.hook_commands
56
53
  members = shown_members(principle, audit, hooks)
@@ -63,7 +60,7 @@ module Principles
63
60
  end
64
61
 
65
62
  # Each member as show-principle prints it, with its loads read once for the whole map, from hooks.
66
- #: (Models::MemberMap, Models::AuditRecord?, Models::HookCommands) -> Array[Hash[String, untyped]]
63
+ #: (Models::Principle, Models::AuditRecord?, Models::HookCommands) -> Array[Hash[String, untyped]]
67
64
  def shown_members(principle, audit, hooks)
68
65
  loads = member_loads(principle, hooks)
69
66
  principle.members_shown.map do |member|
@@ -75,7 +72,7 @@ module Principles
75
72
  # The span sits beside the id too, as in add-member's and move-member's results (alpha friction).
76
73
  #: (Hash[String, untyped], Models::AuditRecord?, Models::MemberLoads) -> Hash[String, untyped]
77
74
  def shown_member(member, audit, loads)
78
- now = fresh(member, audit)
75
+ now = fresh(member, audit&.members&.hashes || Models::RecordedHashes::NONE)
79
76
  member.merge(now.fetch("snapshot", {}).slice("first_line", "last_line"), now,
80
77
  "loads" => loads.to_h)
81
78
  end
@@ -90,19 +87,18 @@ module Principles
90
87
  # The members sharing a line with this one, in its map and in others, as add-member names them, so a member
91
88
  # whose lines others hold too does not look as if its member_bytes were its alone (#541). A member this tool
92
89
  # cannot find now shares nothing it can name.
93
- #: (Hash[String, untyped], map: Models::MemberMap) -> Hash[String, untyped]
90
+ #: (Hash[String, untyped], map: Models::Principle) -> Hash[String, untyped]
94
91
  def shared(member, map:)
95
92
  lines_shared(Models::Member.new(member), map).to_h
96
93
  rescue Error
97
94
  {}
98
95
  end
99
96
 
100
- # Where the member is now and whether it changed since the last audit assessed it.
101
- #: (Hash[String, untyped], Models::AuditRecord?) -> Hash[String, untyped]
102
- def fresh(member, audit)
103
- @project.freshness(Models::Member.new(member).locator) do |sha|
104
- audit ? audit.members.freshness(Models::Member.new(member).key, sha) : "unassessed"
105
- end
97
+ # Where the member is now and whether it changed since the record holding hashes assessed it.
98
+ #: (Hash[String, untyped], Models::RecordedHashes) -> Hash[String, untyped]
99
+ def fresh(member, hashes)
100
+ found = Models::Member.new(member)
101
+ @project.freshness(found.locator) { |sha| hashes.freshness(found.key, sha) }
106
102
  end
107
103
 
108
104
  #: () -> Views::PrincipleReadResult
@@ -110,71 +106,37 @@ module Principles
110
106
  Views::PrincipleReadResult.new(invocation)
111
107
  end
112
108
 
109
+ # Its next_action offers an audit while one principle's audits do not wait on an upgrade; a map listed with its
110
+ # refusal counts, since repairing it leaves it to audit (#1067).
113
111
  #: () -> untyped
114
112
  def listing
115
- read_result.listing(rows(@member_maps.ids), set_up: set_up?)
113
+ ids = @principles.ids
114
+ waiting = ids.filter_map { waiting_on_an_upgrade(it) }
115
+ read_result.listing(rows(ids), set_up: set_up?, waiting: waiting, one_to_audit: waiting.size < ids.size)
116
116
  end
117
117
 
118
- # Whether principles is set up, as MemberMaps decides it (D68, D75).
118
+ # Whether principles is set up, as MappedPrinciples decides it (D68, D75).
119
119
  #: () -> bool
120
- def set_up? = @member_maps.set_up?
121
-
122
- # list-member-problems' JSON result, or with --short its lines for a trigger (#291), or with --hook-event the
123
- # after-commit hook's JSON, which MembersACommitChanged prints (D73).
124
- #: (String?, Hash[String, untyped]) -> untyped
125
- def problems_printed(id, options)
126
- if (event = options["hook_event"])
127
- return handed(MembersACommitChanged, report: -> { checked_report(id) })
128
- .printed(after: options.fetch("commits_after"), event: event)
129
- end
130
-
131
- problems = Models::ProblemReport.new(problems_of(id), history: @history)
132
- report = member_problems(problems)
133
- return report.merge("wrote" => []) unless options["short"]
134
-
135
- Views::ProblemLines.new(invocation).short(report, nothing_changed: Views::ProblemResult::NOTHING_CHANGED,
136
- assessed_change: problems.assessed_change?)
137
- end
138
-
139
- # list-member-problems' JSON result for map id, or every map, without the files it wrote.
140
- #: (String?) -> Hash[String, untyped]
141
- def checked_report(id) = member_problems(Models::ProblemReport.new(problems_of(id), history: @history))
142
-
143
- # The result for problems, every member of map id or of every map that is broken or whose own text changed
144
- # (#187).
145
- #: (Models::ProblemReport) -> untyped
146
- def member_problems(problems)
147
- report = problems.checked do |map_id, member, baseline, now|
148
- map_history(map_id).member_history(member, baseline: baseline, now: now)
149
- end
150
- Views::ProblemResult.new(invocation).checked(report, not_read: @project.unread_older_files,
151
- no_baseline_files: problems.files_to_commit(@member_maps),
152
- acknowledgeable: problems.acknowledgeable)
153
- end
154
-
155
- # Map id's members against their baselines, or every map's, listing a map it cannot read among them.
156
- #: (String?) -> Array[Models::MemberProblems]
157
- def problems_of(id)
158
- return [Models::MemberProblems.for(@project, id)] if id
159
-
160
- @member_maps.ids.map { Models::MemberProblems.for(@project, it, listing_all: true) }
161
- end
120
+ def set_up? = @principles.set_up?
162
121
 
163
- # One map's row; a map this tool cannot read is listed with its refusal, so the others still show (D29).
122
+ # One map's row; a map this tool cannot read is listed with its refusal, so the others still show (D29), and one
123
+ # whose record a later copy wrote says its audits wait on an upgrade, as show-audit does (#1067).
164
124
  #: (String) -> Hash[String, untyped]
165
125
  def entry(id)
166
- map = @member_maps.find(id)
126
+ map = @principles.find(id)
167
127
  row = { "id" => id, "description" => map.description, "members_by_freshness" => members_by_freshness(map) }
168
- map.unstarted? ? row.merge(read_result.no_members(@member_maps.file(id))) : row
128
+ row = row.merge(read_result.no_members(@principles.file(id))) if map.unstarted?
129
+ row.merge(waiting_on_an_upgrade(id)&.marker || {})
169
130
  rescue Error => e
170
131
  { "id" => id, "refusal" => e.payload }
171
132
  end
172
133
 
173
- # How many of map's members are in each freshness state, against its principle's last audit.
174
- #: (Models::MemberMap) -> Hash[String, Integer]
134
+ # How many of map's members are in each freshness state, against its principle's last audit, or the hashes a
135
+ # record a later copy wrote holds, read-only, when this copy cannot read the rest of it (#1067).
136
+ #: (Models::Principle) -> Hash[String, Integer]
175
137
  def members_by_freshness(map)
176
- audit = @audit_records.find(map.id)
177
- map.members_shown.map { |member| fresh(member, audit).fetch("freshness") }.tally.sort.to_h
138
+ _, hashes = @audit_records.for_comparison(map.id)
139
+ map.members_shown.map { |member| fresh(member, hashes).fetch("freshness") }.tally.sort.to_h
178
140
  end
179
141
  end
180
142
  end
@@ -30,13 +30,13 @@ module Principles
30
30
 
31
31
  #: (String, Hash[String, untyped]) -> untyped
32
32
  def create_principle(id, options)
33
- map = @member_maps.create(id) { text(options["description"], "--description") }
33
+ map = @principles.create(id) { text(options["description"], "--description") }
34
34
  write_map(map) { |printed| map_result.created(printed) }
35
35
  end
36
36
 
37
37
  #: (String, Hash[String, untyped]) -> untyped
38
38
  def change_description(id, options)
39
- map = @member_maps.find(id).describing(text(options["description"], "--description"))
39
+ map = @principles.find(id).describing(text(options["description"], "--description"))
40
40
  write_map(map) { |printed| map_result.description_changed(printed) }
41
41
  end
42
42
 
@@ -45,7 +45,7 @@ module Principles
45
45
  def change_activation(id, options)
46
46
  activation = Models::Activation.declared(when_files: options["when_files"],
47
47
  when_invoked: options["when_invoked"], always: options["always"])
48
- map = @member_maps.find(id)
48
+ map = @principles.find(id)
49
49
  activated = map.activating(activation)
50
50
  return map_result.activation_unchanged(printed_principle(map)).merge("wrote" => []) if activated.same_as?(map)
51
51
 
@@ -45,22 +45,34 @@ module Principles
45
45
 
46
46
  #: (String, Hash[String, untyped]) -> untyped
47
47
  def add_member(id, options)
48
- started = !@member_maps.mapped?(id)
49
- map = @member_maps.addable(id)
48
+ started = !@principles.mapped?(id)
49
+ map = @principles.addable(id)
50
50
  member = located(options, { "path" => text(options["path"], "PATH") }).merge(played(options))
51
+ facts = joined(map)
51
52
  write_map(map.adding(member)) do |printed|
52
- added = member_added(printed, map, member)
53
+ added = member_added(printed, map, member, facts)
53
54
  started ? added.merge(map_result.map_created(printed)) : added
54
55
  end
55
56
  end
56
57
 
57
58
  # What add-member reports of the member it added to map: its id, lines and check, and the members, in
58
- # this map or another, that share a line with it, so the agent sees an edit there shows on each (#383).
59
- #: (Views::PrintedPrinciple, Models::MemberMap, Hash[String, untyped]) -> Hash[String, untyped]
60
- def member_added(printed, map, member)
59
+ # this map or another, that share a line with it, so the agent sees an edit there shows on each (#383), and,
60
+ # when a correction may be open on map, how a fix claims the member (D72, #1023).
61
+ #: (Views::PrintedPrinciple, Models::Principle, Hash[String, untyped], Views::MapAddedTo) -> Hash[String, untyped]
62
+ def member_added(printed, map, member, joined)
61
63
  added = Models::Member.new(member)
62
64
  map_result.member_added(printed, added: span(member).merge(member.slice("check")),
63
- shared: lines_shared(added, map))
65
+ shared: lines_shared(added, map), joined: joined)
66
+ end
67
+
68
+ # What add-member says of map, read before the member joins it and the map is saved, so the history can say
69
+ # whether this is the first add-member since the map was last committed (#1025).
70
+ #: (Models::Principle) -> Views::MapAddedTo
71
+ def joined(map)
72
+ history = principle_history(map.id)
73
+ Views::MapAddedTo.new(keeps_others_held: map.keeps_others_held?,
74
+ correction_may_be_open: history.startable_at_head?,
75
+ reminded: history.first_add_since_commit?(map))
64
76
  end
65
77
 
66
78
  # The part a new member plays, and the check that enforces it when one is named (D30).
@@ -82,7 +94,7 @@ module Principles
82
94
  # its audit (#268).
83
95
  #: (String, Hash[String, untyped]) -> untyped
84
96
  def move_member(id, options)
85
- map = @member_maps.find(id)
97
+ map = @principles.find(id)
86
98
  old = map.member(text(options["member"], "MEMBER"))
87
99
  member = located(options, { "path" => new_path(options, old) })
88
100
  moved = span(member)
@@ -99,7 +111,7 @@ module Principles
99
111
 
100
112
  #: (String, Hash[String, untyped]) -> untyped
101
113
  def change_member_role(id, options)
102
- map = @member_maps.find(id)
114
+ map = @principles.find(id)
103
115
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
104
116
  write_map(map.changing_role(target, text(options["role"], "--role"))) do |printed|
105
117
  map_result.member_replaced(printed, member: target, done: "Changed the role of #{target}.")
@@ -109,7 +121,7 @@ module Principles
109
121
  # Names the command that enforces a member, which the audit asks the agent to run (D30).
110
122
  #: (String, Hash[String, untyped]) -> untyped
111
123
  def change_member_check(id, options)
112
- map = @member_maps.find(id)
124
+ map = @principles.find(id)
113
125
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
114
126
  check = text(options["check"], "--check")
115
127
  changed = map.changing_check(target, check)
@@ -119,7 +131,7 @@ module Principles
119
131
 
120
132
  #: (String, Hash[String, untyped]) -> untyped
121
133
  def remove_member_check(id, options)
122
- map = @member_maps.find(id)
134
+ map = @principles.find(id)
123
135
  target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
124
136
  write_map(map.removing_check(target)) do |printed|
125
137
  map_result.member_replaced(printed, member: target,
@@ -130,7 +142,7 @@ module Principles
130
142
 
131
143
  #: (String, Hash[String, untyped]) -> untyped
132
144
  def remove_member(id, options)
133
- map = @member_maps.find(id)
145
+ map = @principles.find(id)
134
146
  target = text(options["member"], "MEMBER")
135
147
  write_map(map.removing(target)) { |printed| map_result.member_removed(printed, removed: target) }
136
148
  end
@@ -0,0 +1,72 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "members_a_commit_changed"
6
+ require_relative "../models/member_problems"
7
+ require_relative "../models/problem_report"
8
+ require_relative "../views/record_waiting_on_an_upgrade"
9
+ require_relative "../views/problem_result"
10
+ require_relative "../views/problem_lines"
11
+
12
+ module Principles
13
+ # Each runs one command: reads models, applies their rules and prints through a view.
14
+ # controllers/CLAUDE.md owns the boundary.
15
+ module Controllers
16
+ # list-member-problems, which Inventory hands over: each member of one map or every map checked against its
17
+ # baseline, printed as JSON, as --short's lines, or for the after-commit hook through MembersACommitChanged.
18
+ class MemberProblemsReport < Command
19
+ # list-member-problems' JSON result, or with --short its lines for a trigger (#291), or with --hook-event the
20
+ # after-commit hook's JSON, which MembersACommitChanged prints (D73).
21
+ #: (String?, Hash[String, untyped]) -> untyped
22
+ def printed(id, options)
23
+ if (event = options["hook_event"])
24
+ return handed(MembersACommitChanged, report: -> { checked_report(id) })
25
+ .printed(after: options.fetch("commits_after"), event: event)
26
+ end
27
+
28
+ problems, report = checked(id)
29
+ return report.merge("wrote" => []) unless options["short"]
30
+
31
+ Views::ProblemLines.new(invocation).short(report, nothing_changed: Views::ProblemResult::NOTHING_CHANGED,
32
+ assessed_change: problems.assessed_change?,
33
+ unassessed_change: problems.unassessed_change?)
34
+ end
35
+
36
+ private
37
+
38
+ # list-member-problems' JSON result for map id, or every map, without the files it wrote.
39
+ #: (String?) -> Hash[String, untyped]
40
+ def checked_report(id) = checked(id).last
41
+
42
+ # The problems of map id, or every map, and list-member-problems' JSON result for them, naming each principle
43
+ # whose record a later copy wrote as waiting on an upgrade, its members compared read-only (D85 V8, #1066).
44
+ #: (String?) -> [Models::ProblemReport, Hash[String, untyped]]
45
+ def checked(id)
46
+ waiting = (id ? [id] : @principles.ids).filter_map { waiting_on_an_upgrade(it) }
47
+ problems = Models::ProblemReport.new(problems_of(id), history: @history)
48
+ [problems, member_problems(problems, waiting)]
49
+ end
50
+
51
+ # The result for problems, every member of map id or of every map that is broken or whose own text changed
52
+ # (#187), and each principle waiting on an upgrade.
53
+ #: (Models::ProblemReport, Array[Views::RecordWaitingOnAnUpgrade]) -> untyped
54
+ def member_problems(problems, waiting)
55
+ report = problems.checked do |map_id, member, baseline, now|
56
+ principle_history(map_id).member_history(member, baseline: baseline, now: now)
57
+ end
58
+ Views::ProblemResult.new(invocation).checked(report, not_read: @project.unread_older_files,
59
+ no_baseline_files: problems.files_to_commit(@principles),
60
+ acknowledgeable: problems.acknowledgeable, waiting:)
61
+ end
62
+
63
+ # Map id's members against their baselines, or every map's, listing a map it cannot read among them.
64
+ #: (String?) -> Array[Models::MemberProblems]
65
+ def problems_of(id)
66
+ return [Models::MemberProblems.for(@project, id)] if id
67
+
68
+ @principles.ids.map { Models::MemberProblems.for(@project, it, listing_all: true) }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -27,15 +27,23 @@ module Principles
27
27
  changed = @history.commits_brought_in(after).changed_by(members)
28
28
  return Views::MembersACommitChanged::NOTHING if changed.empty?
29
29
 
30
- view.changed(event, changed, others: members.size - changed.size)
30
+ changed_lines(event, changed, others: members.size - changed.size)
31
31
  rescue Error => e
32
- return Views::MembersACommitChanged::NOTHING unless @history.touched_since?(after, @member_maps.readable_paths)
32
+ return Views::MembersACommitChanged::NOTHING unless @history.touched_since?(after, @principles.readable_paths)
33
33
 
34
34
  view.refused(event, e.payload.fetch("code"))
35
35
  end
36
36
 
37
37
  private
38
38
 
39
+ # The hook's output naming changed, the members the commits changed, beside others still listed, with the wait
40
+ # of each of their principles whose record a later copy wrote, which says why their audits wait (D85 V8, #1066).
41
+ #: (String, Array[Hash[String, untyped]], others: Integer) -> Views::Lines
42
+ def changed_lines(event, changed, others:)
43
+ waits = changed.map { it.fetch("principle") }.uniq.filter_map { waiting_on_an_upgrade(it) }
44
+ view.changed(event, changed, others:, waits:)
45
+ end
46
+
39
47
  #: () -> Views::MembersACommitChanged
40
48
  def view = Views::MembersACommitChanged.new(invocation)
41
49
  end
@@ -38,7 +38,7 @@ module Principles
38
38
  @principle_id = principle_id
39
39
  @record = @audit_records.find(principle_id) #: Models::AuditRecord?
40
40
  @completed = @record&.last_completed #: Models::AuditRecord?
41
- @checks = Models::CheckSinceLastAudit.new(id: principle_id, history: @history, member_maps: @member_maps,
41
+ @checks = Models::CheckSinceLastAudit.new(id: principle_id, history: @history, principles: @principles,
42
42
  record: @record) #: Models::CheckSinceLastAudit
43
43
  end
44
44
 
@@ -52,17 +52,24 @@ module Principles
52
52
  map = audit.map
53
53
  carried = carried_assessments(audit)
54
54
  elsewhere = elsewhere(map, current)
55
- members = map.members_shown.map do |fields|
56
- member = Models::Member.new(fields)
57
- judged = carried(member, carried)
58
- located(member, current).merge(checked(member), acknowledged(fields), judged,
59
- changed_since(fields, judged), shared_lines(member, elsewhere))
60
- end
55
+ members = map.members_shown.map { |fields| member_listed(fields, carried, elsewhere, current) }
61
56
  Listing.new(members: members, open_findings_elsewhere: elsewhere_listed(elsewhere, current))
62
57
  end
63
58
 
64
59
  private
65
60
 
61
+ # One member of the map, from its fields there, as the request lists it: located as current has it, with its
62
+ # check, the edits acknowledged since the last full audit, its carried assessment or why it is judged again,
63
+ # and the other principles' members sharing its lines.
64
+ #: (Hash[String, untyped], Models::CarriedAssessments, Models::OpenFindingsElsewhere, Models::MemberSnapshots)
65
+ #| -> Hash[String, untyped]
66
+ def member_listed(fields, carried, elsewhere, current)
67
+ member = Models::Member.new(fields)
68
+ judged = carried(member, carried)
69
+ located(member, current).merge(checked(member), acknowledged(fields), judged,
70
+ changed_since(fields, judged), shared_lines(member, elsewhere))
71
+ end
72
+
66
73
  # Each finding elsewhere names, once, with each evidence item's lines beside this audit's members, where current
67
74
  # locates them; the project locates each item now (D64).
68
75
  #: (Models::OpenFindingsElsewhere, Models::MemberSnapshots) -> Array[Hash[String, untyped]]
@@ -74,7 +81,7 @@ module Principles
74
81
  # findings their records leave open on them, each record read once (#772, D62). The request id hashes this
75
82
  # principle's members, not other maps or their records: another principle changing after the request is its
76
83
  # own audit to judge, and does not make this one stale.
77
- #: (Models::MemberMap, Models::MemberSnapshots) -> Models::OpenFindingsElsewhere
84
+ #: (Models::Principle, Models::MemberSnapshots) -> Models::OpenFindingsElsewhere
78
85
  def elsewhere(map, current)
79
86
  sharing = map.members.ids.to_h do |id|
80
87
  [id, Models::MembersSharingLines.new(@project, current.of(id), id: id).elsewhere(except: @principle_id)]
@@ -127,7 +134,7 @@ module Principles
127
134
  base = @completed&.base_commit
128
135
  return {} unless judged["judge_because"] && base
129
136
 
130
- paths = map_history(@principle_id).paths_from(base, Models::Member.new(fields).key, fields)
137
+ paths = principle_history(@principle_id).paths_from(base, Models::Member.new(fields).key, fields)
131
138
  { "read_the_change" => Views::DiffSinceLastAudit.new(last_audited_commit: base, paths: paths).to_s }
132
139
  end
133
140
 
@@ -32,7 +32,7 @@ module Principles
32
32
  # to judge whether one is the passage.
33
33
  #: () -> untyped
34
34
  def show_meta_principle_passage
35
- map = @member_maps.addable(Models::MetaPrinciple::ID)
35
+ map = @principles.addable(Models::MetaPrinciple::ID)
36
36
  view = meta_principle_result
37
37
  view.proposal(printed_principle(map), placement(view), map_in_project(map),
38
38
  existing_principles: existing_principles).merge("wrote" => [])
@@ -40,17 +40,17 @@ module Principles
40
40
 
41
41
  # map as the project holds it: whether it was there before this run, its members already in an entry file, and
42
42
  # whether principles is set up, its map having a member (D75).
43
- #: (Models::MemberMap) -> Views::MetaPrincipleResult::MapInProject
43
+ #: (Models::Principle) -> Views::MetaPrincipleResult::MapInProject
44
44
  def map_in_project(map)
45
45
  Views::MetaPrincipleResult::MapInProject.new(
46
- already_mapped: @member_maps.mapped?(map.id), members_in_entry_files: map.members_in(Models::EntryFiles::PATHS),
47
- set_up: @member_maps.set_up?
46
+ already_mapped: @principles.mapped?(map.id), members_in_entry_files: map.members_in(Models::EntryFiles::PATHS),
47
+ set_up: @principles.set_up?
48
48
  )
49
49
  end
50
50
 
51
51
  # The project's other principles, as list-principles lists them, which this principle's first audit keeps held.
52
52
  #: () -> Array[Hash[String, untyped]]
53
- def existing_principles = handed(Inventory).rows(@member_maps.ids - [Models::MetaPrinciple::ID])
53
+ def existing_principles = handed(Inventory).rows(@principles.ids - [Models::MetaPrinciple::ID])
54
54
 
55
55
  # Where the passage can go: how this run was started and whether the hook runs in this session, the project's
56
56
  # entry files, and the passage.
@@ -44,7 +44,7 @@ module Principles
44
44
  # What the repoint did, and each other principle's open finding whose write-up cannot be found (T16).
45
45
  #: (Models::Repoint, Models::AuditRecord) -> Views::RepointResult::Outcome
46
46
  def outcome(repoint, repointed)
47
- others = @audit_records.of(@member_maps.ids - [repointed.principle_id])
47
+ others = @audit_records.of(@principles.ids - [repointed.principle_id])
48
48
  Views::RepointResult::Outcome.new(repointed: repoint.moved_ids(repointed),
49
49
  unchanged: repoint.unchanged_ids(repointed),
50
50
  not_found_elsewhere: Models::FindingWriteUps.of(@project, others).not_found)
@@ -29,7 +29,7 @@ module Principles
29
29
 
30
30
  # The release of principles this run comes from, as the audit of map's principle keeps it: the version running
31
31
  # and the passage as setup prints it, which only a view holds; nil for a principle whose audit keeps none (D68).
32
- #: (Models::MemberMap) -> Models::PrinciplesPackage?
32
+ #: (Models::Principle) -> Models::PrinciplesPackage?
33
33
  def release_kept_by(map)
34
34
  return unless map.keeps_package?
35
35
 
@@ -33,21 +33,25 @@ module Principles
33
33
  @directory.exist?(id)
34
34
  end
35
35
 
36
- # The record of id's last audit, or nil when it has none, checked against its schema (D29).
37
- #: (String) -> Hash[String, untyped]?
38
- def read(id)
36
+ # The record of id's last audit, or nil when it has none, checked against its schema (D29), handing the block
37
+ # a record the schema refuses, as parse does.
38
+ #: (String) ?{ (untyped) -> void } -> Hash[String, untyped]?
39
+ def read(id, &)
39
40
  return unless exist?(id)
40
41
 
41
- parse(id, @directory.read(id, shown_as: relative(id)))
42
+ parse(id, @directory.read(id, shown_as: relative(id)), &)
42
43
  end
43
44
 
44
- # The record of id from its text, with an older version's key upgraded, checked against its schema (D29).
45
- #: (String, String) -> Hash[String, untyped]
46
- def parse(id, text)
45
+ # The record of id from its text, with an older version's key upgraded, checked against its schema (D29). A
46
+ # record the schema refuses is handed to the block first, which may refuse it otherwise, as a model does one a
47
+ # later copy wrote (D85).
48
+ #: (String, String) ?{ (untyped) -> void } -> Hash[String, untyped]
49
+ def parse(id, text, &)
47
50
  record = upgraded(JsonText.new(text).parsed)
48
51
  problems = SchemaCheck.new("audit-record").problems(record)
49
52
  return record if problems.empty?
50
53
 
54
+ yield record if block_given?
51
55
  raise Error.new("invalid_audit_record", "#{relative(id)} is not in the shape this tool writes",
52
56
  "Repair each field listed, or restore the record from version control.", relative(id),
53
57
  fields: problems)
@@ -31,6 +31,17 @@ module Principles
31
31
  File.read(@path, encoding: encoding)
32
32
  end
33
33
 
34
+ # A bounded regular file whose text must also be valid UTF-8, as project members require.
35
+ #: () -> String
36
+ def read_text
37
+ text = read
38
+ unless text.valid_encoding?
39
+ raise Error.new("invalid_encoding", "Cannot read UTF-8 text", "Choose a text member.", @shown_as)
40
+ end
41
+
42
+ text
43
+ end
44
+
34
45
  # Refuses bytes of text, such as stdin's, that are more than this tool reads from one file.
35
46
  #: (Integer) -> void
36
47
  def refuse_larger(bytes)
@@ -11,6 +11,7 @@
11
11
  "any-command": ["file_too_large", "invalid_invocation", "invalid_shape", "filesystem_error", "unknown_command", "missing_id", "invalid_command_steps"],
12
12
  "read-map": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unknown_principle", "unparseable_map", "invalid_map", "newer_format", "duplicate_member"],
13
13
  "read-audit": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unparseable_audit", "invalid_audit_record"],
14
+ "rewrite-audit": ["newer_audit_record"],
14
15
  "locate-text": ["outside_project", "not_a_file", "unreadable_file", "invalid_encoding", "section_needs_markdown", "query_needs_frontmatter", "query_with_other_locators", "unsupported_query", "unsupported_frontmatter", "duplicate_frontmatter_key", "field_not_found", "section_not_found",
15
16
  "ambiguous_heading", "passage_not_found", "ambiguous_passage", "passage_end_not_found",
16
17
  "broken_members"]
@@ -46,7 +47,7 @@
46
47
  "help": "learn-what-a-command-does/list-member-problems",
47
48
  "steps": [
48
49
  { "id": "compare-members-with-their-baselines", "actor": "cli",
49
- "does": "Finds each member of map ID, or of every map, and compares its own text with the last audit's hash for it, or else with its text at the commit that mapped it where it is. Refuses while any member cannot be found or read, or a map cannot be read, so a gate can stop on the exit status; otherwise lists each changed member with what it was compared with, and counts every state. With --short, prints one tab-separated line per changed member and exits 3 when any changed.",
50
+ "does": "Finds each member of map ID, or of every map, and compares its own text with the last audit's hash for it, or else with its text at the commit that mapped it where it is. Refuses while any member cannot be found or read, or a map cannot be read, so a gate can stop on the exit status; otherwise lists each changed member with what it was compared with, and counts every state. With --short, prints one tab-separated line per changed member and exits 3 when a member an audit assessed changed, and 4 when the only changes are edits to members no audit has assessed.",
50
51
  "refuses": ["broken_members"], "refuses_like": ["read-map", "read-audit"] },
51
52
  { "id": "repair-or-audit", "actor": "agent",
52
53
  "does": "For a refusal, say whether each listed member moved or is gone, and repair it. For a changed member, audit its principle when the change was meant to alter the principle.",
@@ -98,7 +99,7 @@
98
99
  "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request", "stale_request", "stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git",
99
100
  "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding",
100
101
  "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes"],
101
- "refuses_like": ["read-map", "read-audit", "locate-text"] },
102
+ "refuses_like": ["read-map", "read-audit", "locate-text", "rewrite-audit"] },
102
103
  { "id": "submit-the-checked-answer", "actor": "agent",
103
104
  "does": "Fix what a refusal names and check again, or submit the answer unchanged.",
104
105
  "answer_with": "submit-answer" }
@@ -217,13 +218,13 @@
217
218
  ]
218
219
  },
219
220
  {
220
- "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups]", "group": "write-audit-record", "options": ["member", "write-ups"],
221
+ "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups | --as template]", "group": "write-audit-record", "options": ["member", "write-ups", "as"],
221
222
  "summary": "Ask for an assessment of every member and the set.",
222
223
  "help": "learn-what-a-command-does/start-audit",
223
224
  "steps": [
224
225
  { "id": "snapshot-members", "actor": "cli",
225
- "does": "Refuses an empty map or, in git, an uncommitted map or member file; bases the audit on HEAD. Writes nothing.",
226
- "refuses": ["map_has_no_members", "uncommitted_files"], "refuses_like": ["read-map", "locate-text"],
226
+ "does": "Refuses an empty map or, in git, an uncommitted map or member file; bases the audit on HEAD. Fill --as template's output with your own judgement, under $TMPDIR; its left_as_printed_rule says how a field left as printed is read.",
227
+ "refuses": ["map_has_no_members", "uncommitted_files"], "refuses_like": ["read-map", "locate-text", "rewrite-audit"],
227
228
  "next": [{ "to": "assess-every-member", "when": "you passed neither --member nor --write-ups" },
228
229
  { "to": "start-acknowledgement", "when": "you passed --member" },
229
230
  { "to": "start-repointing", "when": "you passed --write-ups" }] },
@@ -254,7 +255,7 @@
254
255
  "steps": [
255
256
  { "id": "match-request", "actor": "cli",
256
257
  "does": "Reads FILE, or stdin for -, and checks that its request_id is REQUEST, an id this tool prints.",
257
- "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request"],
258
+ "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request"], "refuses_like": ["rewrite-audit"],
258
259
  "next": [{ "to": "acknowledge-the-change", "when": "the request was a one-member audit" },
259
260
  { "to": "record-the-repoints", "when": "the request was a repoint of write-ups" },
260
261
  { "to": "recheck-members", "when": "the request was an assessment or a correction" }] },
@@ -14,7 +14,7 @@ module Principles
14
14
  # .principles/maps/, committed in the audited repository. A map holds a description and its members,
15
15
  # each a project file, optionally narrowed to one Markdown section, with the role it plays.
16
16
  class MapFiles
17
- # The newest map format this version reads. Models::MemberMap says which member fields need which
17
+ # The newest map format this version reads. Models::Principle says which member fields need which
18
18
  # format, and a spec ties the two together.
19
19
  NEWEST_FORMAT = 2
20
20
 
@@ -39,7 +39,7 @@ module Principles
39
39
  @directory.exist?(id)
40
40
  end
41
41
 
42
- # The map id, which exists: Models::MemberMaps refuses one that does not, since which command creates it is
42
+ # The map id, which exists: Models::MappedPrinciples refuses one that does not, since which command creates it is
43
43
  # a decision.
44
44
  #: (String) -> Hash[String, untyped]
45
45
  def read(id)