principles 0.0.5 → 0.0.7

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 (192) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/cli.rb +9 -0
  4. data/lib/principles/command_line.rb +31 -30
  5. data/lib/principles/command_routes.rb +9 -3
  6. data/lib/principles/controllers/acknowledgement.rb +82 -95
  7. data/lib/principles/controllers/answer.rb +14 -11
  8. data/lib/principles/controllers/assessment.rb +27 -24
  9. data/lib/principles/controllers/audit.rb +24 -4
  10. data/lib/principles/controllers/audit_completion.rb +10 -4
  11. data/lib/principles/controllers/command.rb +2 -2
  12. data/lib/principles/controllers/correction.rb +16 -7
  13. data/lib/principles/controllers/full_audit_request.rb +8 -3
  14. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  15. data/lib/principles/controllers/inventory.rb +3 -22
  16. data/lib/principles/controllers/mapping.rb +9 -1
  17. data/lib/principles/controllers/member_acknowledgement.rb +137 -0
  18. data/lib/principles/controllers/member_addition.rb +65 -0
  19. data/lib/principles/controllers/member_entries.rb +6 -24
  20. data/lib/principles/controllers/member_problems_report.rb +33 -25
  21. data/lib/principles/controllers/members_to_assess.rb +1 -1
  22. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  23. data/lib/principles/controllers/repoint.rb +5 -2
  24. data/lib/principles/controllers/survey.rb +60 -0
  25. data/lib/principles/data/audit_files.rb +4 -0
  26. data/lib/principles/data/candidate_files_found.rb +48 -13
  27. data/lib/principles/data/command-steps.json +86 -25
  28. data/lib/principles/data/committed_tree.rb +84 -0
  29. data/lib/principles/data/first_parent_log.rb +48 -0
  30. data/lib/principles/data/first_parent_range.rb +122 -0
  31. data/lib/principles/data/git_command.rb +37 -0
  32. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  33. data/lib/principles/data/map_files.rb +35 -10
  34. data/lib/principles/data/principles_directory.rb +40 -0
  35. data/lib/principles/data/principles_subfolder.rb +39 -16
  36. data/lib/principles/data/project_files.rb +11 -3
  37. data/lib/principles/data/repository.rb +55 -29
  38. data/lib/principles/data/requested_candidate_files.rb +43 -0
  39. data/lib/principles/data/running_version.rb +3 -5
  40. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +6 -6
  41. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +88 -0
  42. data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
  43. data/lib/principles/data/schemas/assessment-answer.schema.json +15 -1
  44. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  45. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  46. data/lib/principles/data/schemas/correction-answer.schema.json +12 -54
  47. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  48. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  49. data/lib/principles/data/verified_head.rb +162 -0
  50. data/lib/principles/invocation_options.rb +5 -4
  51. data/lib/principles/list_open_findings_options.rb +23 -0
  52. data/lib/principles/models/acknowledged_check.rb +94 -0
  53. data/lib/principles/models/acknowledgement.rb +40 -36
  54. data/lib/principles/models/acknowledgement_left_as_printed.rb +72 -0
  55. data/lib/principles/models/acknowledgements.rb +99 -0
  56. data/lib/principles/models/answered_time.rb +9 -0
  57. data/lib/principles/models/assessment_report.rb +13 -13
  58. data/lib/principles/models/audit.rb +17 -4
  59. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  60. data/lib/principles/models/audit_record.rb +9 -0
  61. data/lib/principles/models/audit_records.rb +34 -8
  62. data/lib/principles/models/candidate_files.rb +17 -6
  63. data/lib/principles/models/candidate_inventory.rb +51 -7
  64. data/lib/principles/models/captured_head.rb +72 -0
  65. data/lib/principles/models/check_since_last_audit.rb +4 -8
  66. data/lib/principles/models/correction_basis.rb +14 -5
  67. data/lib/principles/models/declared_map_changes.rb +25 -9
  68. data/lib/principles/models/declared_member_removals.rb +75 -0
  69. data/lib/principles/models/disposition.rb +4 -2
  70. data/lib/principles/models/fix_only_fields.rb +12 -0
  71. data/lib/principles/models/guidance_search_path.rb +26 -0
  72. data/lib/principles/models/guidance_search_paths.rb +57 -0
  73. data/lib/principles/models/line_span.rb +6 -0
  74. data/lib/principles/models/list_member_problems_check.rb +80 -0
  75. data/lib/principles/models/listed_members.rb +49 -0
  76. data/lib/principles/models/loaded_files.rb +1 -2
  77. data/lib/principles/models/loading_decision.rb +17 -8
  78. data/lib/principles/models/loading_scope.rb +61 -0
  79. data/lib/principles/models/loads_to_check.rb +0 -1
  80. data/lib/principles/models/locator.rb +6 -0
  81. data/lib/principles/models/mapped_principles.rb +39 -37
  82. data/lib/principles/models/member_assessments.rb +11 -2
  83. data/lib/principles/models/member_file.rb +20 -71
  84. data/lib/principles/models/member_history.rb +7 -5
  85. data/lib/principles/models/member_loading_scopes.rb +49 -0
  86. data/lib/principles/models/member_loads.rb +4 -0
  87. data/lib/principles/models/member_mapping_run.rb +30 -0
  88. data/lib/principles/models/member_moves.rb +4 -0
  89. data/lib/principles/models/member_problems.rb +57 -29
  90. data/lib/principles/models/member_region.rb +129 -0
  91. data/lib/principles/models/member_repair_moves.rb +9 -11
  92. data/lib/principles/models/member_sighting.rb +5 -8
  93. data/lib/principles/models/member_snapshots.rb +14 -1
  94. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  95. data/lib/principles/models/meta_principle.rb +14 -0
  96. data/lib/principles/models/missing_files.rb +2 -2
  97. data/lib/principles/models/other_templates_placeholders.rb +1 -1
  98. data/lib/principles/models/outline_budget.rb +29 -14
  99. data/lib/principles/models/principle.rb +14 -7
  100. data/lib/principles/models/principle_file_revision.rb +48 -0
  101. data/lib/principles/models/principle_history.rb +46 -19
  102. data/lib/principles/models/principle_lineage.rb +118 -0
  103. data/lib/principles/models/principle_map_revision.rb +39 -0
  104. data/lib/principles/models/principle_mapping_history.rb +132 -0
  105. data/lib/principles/models/principle_members.rb +14 -0
  106. data/lib/principles/models/principle_predecessor.rb +45 -0
  107. data/lib/principles/models/principle_publication.rb +177 -0
  108. data/lib/principles/models/principle_revision.rb +104 -0
  109. data/lib/principles/models/problem_report.rb +36 -9
  110. data/lib/principles/models/project.rb +47 -30
  111. data/lib/principles/models/project_history.rb +45 -25
  112. data/lib/principles/models/record_format.rb +6 -0
  113. data/lib/principles/models/reported_check.rb +16 -12
  114. data/lib/principles/models/request_id.rb +1 -1
  115. data/lib/principles/models/sent_answer.rb +35 -5
  116. data/lib/principles/models/survey_search_paths.rb +26 -0
  117. data/lib/principles/models/uncommitted_files.rb +50 -0
  118. data/lib/principles/models/unknown_principle.rb +29 -0
  119. data/lib/principles/positional_arguments.rb +38 -0
  120. data/lib/principles/session_start_options.rb +3 -3
  121. data/lib/principles/start_audit_options.rb +10 -2
  122. data/lib/principles/version.rb +2 -2
  123. data/lib/principles/views/acknowledgement_result.rb +54 -16
  124. data/lib/principles/views/added_member.rb +41 -0
  125. data/lib/principles/views/answered_request.rb +21 -0
  126. data/lib/principles/views/assessed_members.rb +26 -5
  127. data/lib/principles/views/assessment_request.rb +24 -4
  128. data/lib/principles/views/audit_result.rb +30 -27
  129. data/lib/principles/views/candidate_files_result.rb +56 -12
  130. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  131. data/lib/principles/views/check_result_template.rb +18 -17
  132. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  133. data/lib/principles/views/correction_request.rb +38 -10
  134. data/lib/principles/views/findings_result.rb +21 -0
  135. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  136. data/lib/principles/views/invocation.rb +19 -4
  137. data/lib/principles/views/json_with_entries_on_lines.rb +12 -4
  138. data/lib/principles/views/loads_to_check_result.rb +3 -2
  139. data/lib/principles/views/map_added_to.rb +56 -2
  140. data/lib/principles/views/map_result.rb +22 -42
  141. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  142. data/lib/principles/views/member_change_since_baseline.rb +2 -1
  143. data/lib/principles/views/member_repairs.rb +2 -1
  144. data/lib/principles/views/member_row.rb +61 -0
  145. data/lib/principles/views/members_a_commit_changed.rb +2 -1
  146. data/lib/principles/views/members_with_no_baseline.rb +8 -1
  147. data/lib/principles/views/new_loading_scope.rb +31 -0
  148. data/lib/principles/views/one_member_check_result_template.rb +37 -21
  149. data/lib/principles/views/open_findings_line.rb +2 -1
  150. data/lib/principles/views/principle_read_result.rb +4 -1
  151. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  152. data/lib/principles/views/problem_lines.rb +50 -45
  153. data/lib/principles/views/problem_result.rb +59 -25
  154. data/lib/principles/views/prompts/acknowledge-a-change/report-the-exit-status-its-own-listing-gives.md +3 -0
  155. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -3
  156. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-each-change-keeps-its-meaning.md +8 -0
  157. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -6
  158. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -43
  159. data/lib/principles/views/prompts/assess-every-member/decide-each-member-loading.md +2 -1
  160. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  161. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +5 -3
  162. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  163. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +12 -0
  164. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  165. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  166. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  167. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +4 -2
  168. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  169. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +2 -2
  170. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  171. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  172. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  173. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  174. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  175. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  176. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -2
  177. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +37 -4
  178. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +20 -19
  179. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +65 -61
  180. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  181. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  182. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  183. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +33 -7
  184. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  185. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +10 -10
  186. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  187. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  188. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +1 -1
  189. data/lib/principles/views/prompts/start-a-session/every-loaded-line-costs-every-session.md +1 -0
  190. data/lib/principles/views/prompts/start-a-session/start-with-the-principles-skill.md +1 -0
  191. metadata +67 -4
  192. data/lib/principles/models/candidate_listing.rb +0 -41
@@ -0,0 +1,27 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ module Views
6
+ # The optional consecutive-section facts beside an added member and the question they ask the agent.
7
+ class ConsecutiveSectionsElsewhere
8
+ #: (?Array[Hash[String, untyped]]) -> void
9
+ def initialize(facts = [])
10
+ @facts = facts
11
+ freeze
12
+ end
13
+
14
+ #: () -> Hash[String, untyped]
15
+ def to_h = @facts.empty? ? {} : { "consecutive_sections_elsewhere" => @facts }
16
+
17
+ #: () -> String
18
+ def note
19
+ return "" if @facts.empty?
20
+
21
+ "Members of other principles occupy consecutive complete Markdown sections in the same underlying file " \
22
+ "(consecutive_sections_elsewhere). These maps have no completed full audit. " \
23
+ "Do they carry one rule or distinct principles? Location alone does not decide. "
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "answer_head"
5
+ require_relative "invocation"
5
6
  require_relative "prompts"
6
7
 
7
8
  module Principles
@@ -40,24 +41,51 @@ module Principles
40
41
  def template
41
42
  @head.leading("dispositions" => @findings.map do |finding|
42
43
  { "finding_id" => finding["id"], "action" => @placeholders.fetch("action"),
43
- "reason" => @placeholders.fetch("reason"), "changed_members" => [], "evidence" => [],
44
+ "reason" => @placeholders.fetch("reason"), "changed_members" => [], "removed_members" => [],
45
+ "evidence" => [],
44
46
  "reassessment" => @placeholders.fetch("reassessment"), "recorded_at" => nil, "waits_on" => nil }
45
47
  end)
46
48
  end
47
49
 
50
+ #: (AuditResult, String, String) -> Hash[String, untyped]
51
+ def presented_with(view, source_request_id, answer_file)
52
+ view.request(view.correction_request(self, source_request_id:, answer_file:))
53
+ end
54
+
55
+ # The correction's answer to save and fill after submitting the checked assessment; keep its submit last.
56
+ #: (Hash[String, untyped], Invocation, String) -> Hash[String, untyped]
57
+ def with_correction_to_fill(acceptable, invocation, answer_file)
58
+ save = "Once this answer is submitted with the last line's command, save correction_template, the " \
59
+ "correction's answer it leads to, to a file outside the project, such as under $TMPDIR, fill only " \
60
+ "its dispositions, and submit it: #{invocation.submit_answer(request_id)}"
61
+ acceptable.merge("correction_template" => template,
62
+ "correction_recovery" => recovery(acceptable.fetch("request_id"), answer_file, invocation),
63
+ "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
64
+ end
65
+
66
+ # Preserve both inputs before fixes; only a commit-based request has the reviewed replay route.
67
+ #: (String, String, Invocation) -> String
68
+ def recovery(assessment_request_id, assessment_file, invocation)
69
+ keep = Prompts.text("dispose-of-each-finding/retain-assessment-and-correction")
70
+ return keep unless @head.based_on_a_commit?
71
+
72
+ command = invocation.in_project("show-answer-check", assessment_request_id,
73
+ options: ["--file", assessment_file])
74
+ "#{keep}\nAfter submitting the assessment in Git, while its request inputs remain unchanged, " \
75
+ "recover a lost correction with this read-only command. For --file -, supply the saved exact stdin bytes " \
76
+ "again. Stale and newer-record checks still apply:\n#{command}"
77
+ end
78
+
48
79
  # What submitting the assessment stored, and what submitting it again would do, so an assessment submitted
49
- # twice plainly replaced nothing: in git, where the audit has a base commit, nothing; outside git, the open
50
- # record, which keeps what the audit began from.
80
+ # twice plainly replaced nothing: the open record, which keeps the assessment and, outside git, what the audit
81
+ # began from, and which in git is never committed, since the correction completes it (D87).
51
82
  #: () -> String
52
83
  def stored
53
- again = "Submitting the same assessment again prints this same request"
54
- unless @head.based_on_a_commit?
55
- return "This audit's open record, listed under wrote when it was first written, keeps what the audit " \
56
- "began from. #{again} and leaves that record as it is."
57
- end
84
+ kept = "This audit's open record, listed under wrote when it was first written, keeps your assessment"
85
+ again = "Submitting the same assessment again prints this same request and leaves that record as it is."
86
+ return "#{kept} and what the audit began from. #{again}" unless @head.based_on_a_commit?
58
87
 
59
- "Nothing is stored yet: this request was computed from your assessment and the project. #{again} and " \
60
- "replaces nothing; the audit record is written when the audit completes."
88
+ "#{kept} until this correction completes the audit; do not commit it. #{again}"
61
89
  end
62
90
  end
63
91
  end
@@ -2,6 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "invocation"
5
+ require_relative "problem_lines"
6
+ require_relative "visible_text"
5
7
 
6
8
  module Principles
7
9
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -27,8 +29,27 @@ module Principles
27
29
  { "findings" => findings, "scope" => SCOPE, "next_action" => next_action(findings) }
28
30
  end
29
31
 
32
+ # list-open-findings --lines: each finding on a line, its principle, id and whom it waits on, so the agent can
33
+ # see which to raise without a script over the list (#1156). Free text is escaped, and its line breaks read as
34
+ # spaces, so each finding stays on its own line (#227).
35
+ #: (Array[Hash[String, untyped]]) -> Lines
36
+ def lines(findings)
37
+ text = findings.map { |finding| "#{line(finding)}\n" }.join
38
+ Lines.new(stdout: findings.empty? ? "#{NONE_OPEN}\n" : text, stderr: "", status: 0)
39
+ end
40
+
30
41
  private
31
42
 
43
+ #: (Hash[String, untyped]) -> String
44
+ def line(finding)
45
+ waits_on = finding["waits_on"]
46
+ waits = waits_on ? "waits on: #{one_line(waits_on)}" : "waits on no one named"
47
+ "#{finding.fetch("principle")}\t#{one_line(finding.fetch("finding_id"))}\t#{waits}"
48
+ end
49
+
50
+ #: (String) -> String
51
+ def one_line(text) = VisibleText.new(text.gsub(/\s+/, " ")).to_s
52
+
32
53
  #: (Array[Hash[String, untyped]]) -> String
33
54
  def next_action(findings)
34
55
  return NONE_OPEN if findings.empty?
@@ -0,0 +1,26 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # The recorded list and an immediate read-only survey after a guidance-search-path write.
10
+ class GuidanceSearchPathsResult
11
+ #: (Invocation) -> void
12
+ def initialize(invocation)
13
+ @invocation = invocation
14
+ freeze
15
+ end
16
+
17
+ #: (status: String, globs: Array[String], wrote: Array[String]) -> Hash[String, untyped]
18
+ def result(status:, globs:, wrote:)
19
+ survey = @invocation.in_project("list-candidate-files")
20
+ { "status" => status, "recorded_guidance_search_paths" => globs, "wrote" => wrote,
21
+ "next_action" => "Commit changed configuration.\n" \
22
+ "Survey again using the saved search paths: #{survey}" }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -15,13 +15,24 @@ module Principles
15
15
  #: String
16
16
  attr_reader :project
17
17
 
18
- #: (executable: String, project: String) -> void
19
- def initialize(executable:, project:)
18
+ # named says whether each command names the project; without_project leaves it out.
19
+ #: (executable: String, project: String, ?named: bool) -> void
20
+ def initialize(executable:, project:, named: true)
20
21
  @executable = executable
21
22
  @project = project
23
+ @named = named
22
24
  freeze
23
25
  end
24
26
 
27
+ # The same invocation, its commands leaving out --project, for output that names the project once and whose
28
+ # commands run from there, as list-member-problems --short's stderr does (#1263).
29
+ #: () -> Invocation
30
+ def without_project = Invocation.new(executable: @executable, project: @project, named: false)
31
+
32
+ # The project as a shell word, as --project gives it.
33
+ #: () -> String
34
+ def project_word = shell_word(@project)
35
+
25
36
  # A command to run in this project, which it names right after the executable, as model repairs do (#580).
26
37
  # Each value is shell-quoted, because ids, paths and headings come from project files that anyone may have
27
38
  # written (#227). options are flags with their values, such as
@@ -46,10 +57,10 @@ module Principles
46
57
  flags = options.map { |value| shell_word(value) }
47
58
  words = values.map { |value| shell_word(value) }
48
59
  if values.any? { |value| value.start_with?("-") }
49
- return [@executable, project_option, command, *flags, usage, "--", *words].compact.join(" ")
60
+ return [@executable, named_project, command, *flags, usage, "--", *words].compact.join(" ")
50
61
  end
51
62
 
52
- [@executable, project_option, command, *words, *flags, usage].compact.join(" ")
63
+ [@executable, named_project, command, *words, *flags, usage].compact.join(" ")
53
64
  end
54
65
 
55
66
  #: () -> String
@@ -59,6 +70,10 @@ module Principles
59
70
 
60
71
  private
61
72
 
73
+ # --project and the project, or nil when the commands leave it out.
74
+ #: () -> String?
75
+ def named_project = @named ? project_option : nil
76
+
62
77
  #: (String) -> String
63
78
  def shell_word(value) = ShellWord.new(value).to_s
64
79
  end
@@ -11,8 +11,8 @@ module Principles
11
11
  # line of 36 KB is the worst shape to read by lines (#1155). It is the first case of ticket 007's decision on the
12
12
  # output format; every other result prints pretty.
13
13
  class JsonWithEntriesOnLines
14
- # Stands in for the array while the rest prints pretty. Only its first place is replaced, so text from a project
15
- # file that holds it, which prints after the array, is left as it is.
14
+ # Stands in for the array while the rest prints pretty. Replacement targets its root object and direct key,
15
+ # so an identical project string elsewhere stays untouched regardless of the result's field order.
16
16
  MARKER = "\u0000entries on lines of their own\u0000"
17
17
 
18
18
  # The array is result[under][key].
@@ -32,12 +32,20 @@ module Principles
32
32
  #: () -> String
33
33
  def text
34
34
  marked = JSON.pretty_generate(@result.merge(@under => @result.fetch(@under).merge(@key => MARKER)))
35
- place = /^( *)(.*)#{Regexp.escape(JSON.generate(MARKER))}/
36
- marked.sub(place) { "#{Regexp.last_match(1)}#{Regexp.last_match(2)}#{lines(Regexp.last_match(1).to_s)}" }
35
+ marked.sub(array_place) { "#{Regexp.last_match(1)}#{lines(" ")}" }
37
36
  end
38
37
 
39
38
  private
40
39
 
40
+ # The designated array placeholder at its known depth in JSON.pretty_generate's two-space layout.
41
+ #: () -> Regexp
42
+ def array_place
43
+ parent = Regexp.escape(JSON.generate(@under))
44
+ child = Regexp.escape(JSON.generate(@key))
45
+ marker = Regexp.escape(JSON.generate(MARKER))
46
+ /(^ #{parent}: \{.*?^ #{child}: )#{marker}/m
47
+ end
48
+
41
49
  # The array's entries, each compact on its own line, one step in from indent.
42
50
  #: (String) -> String
43
51
  def lines(indent)
@@ -11,8 +11,9 @@ module Principles
11
11
  # How a full audit's request shows the members to check against the principle's activation (#355 slice 3).
12
12
  class LoadsToCheckResult
13
13
  # What a decision may be, as the answer printed alone says where it is written (#746).
14
- DECISION = "accepted, with reason saying why the member loads as it does; if the activation is wrong " \
15
- "instead, change it and start the audit again" #: String
14
+ DECISION = "accepted, with reason saying why the member loads as it does; kept, with no reason, where " \
15
+ "last_accepted.since_accepted is unchanged; if the activation is wrong instead, change it and " \
16
+ "start the audit again" #: String
16
17
 
17
18
  # listed is the members to check, nil when there are none, and id the principle they belong to; placeholders
18
19
  # is the text the template alone prints in each field of a decision beside it, which left is not given (#994).
@@ -1,6 +1,9 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "first_audit"
5
+ require_relative "new_loading_scope"
6
+
4
7
  module Principles
5
8
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
9
  module Views
@@ -10,6 +13,9 @@ module Principles
10
13
  # what to do after mapping: with a principle's first member, or in git the first since the map's last commit, so
11
14
  # members mapped in one sitting do not each repeat it (#1025).
12
15
  class MapAddedTo
16
+ COMPLETENESS_QUESTION = "Is every carrier of the same rule mapped, and should any member belong to another " \
17
+ "principle? "
18
+
13
19
  #: bool
14
20
  attr_reader :keeps_others_held
15
21
 
@@ -19,13 +25,61 @@ module Principles
19
25
  #: bool
20
26
  attr_reader :reminded
21
27
 
22
- #: (?keeps_others_held: bool, ?correction_may_be_open: bool, ?reminded: bool) -> void
23
- def initialize(keeps_others_held: false, correction_may_be_open: false, reminded: true)
28
+ #: (?keeps_others_held: bool, ?correction_may_be_open: bool, ?reminded: bool,
29
+ #| ?asks_about_completeness: bool, ?new_scope: NewLoadingScope) -> void
30
+ def initialize(keeps_others_held: false, correction_may_be_open: false, reminded: true,
31
+ asks_about_completeness: false, new_scope: NewLoadingScope.new)
24
32
  @keeps_others_held = keeps_others_held
25
33
  @correction_may_be_open = correction_may_be_open
26
34
  @reminded = reminded
35
+ @asks_about_completeness = asks_about_completeness
36
+ @new_scope = new_scope
27
37
  freeze
28
38
  end
39
+
40
+ # This immutable reminder context with the model's decision to ask about coverage, not a completeness verdict.
41
+ #: (asks: bool) -> MapAddedTo
42
+ def with_completeness_question(asks:)
43
+ MapAddedTo.new(keeps_others_held: @keeps_others_held, correction_may_be_open: @correction_may_be_open,
44
+ reminded: @reminded, asks_about_completeness: asks, new_scope: @new_scope)
45
+ end
46
+
47
+ # This immutable addition context with the model's new-scope facts, preserving its original reminder flags.
48
+ #: (NewLoadingScope) -> MapAddedTo
49
+ def with_loading_scope(scope)
50
+ MapAddedTo.new(keeps_others_held: @keeps_others_held, correction_may_be_open: @correction_may_be_open,
51
+ reminded: @reminded, asks_about_completeness: @asks_about_completeness, new_scope: scope)
52
+ end
53
+
54
+ #: () -> Hash[String, untyped]
55
+ def added_facts = @new_scope.to_h
56
+
57
+ # The guidance after adding member, from this map's before-save reminder and correction facts.
58
+ #: (PrintedPrinciple, member: String, invocation: Invocation, in_git: bool) -> String
59
+ def after_member(principle, member:, invocation:, in_git:)
60
+ "#{@new_scope.note}#{COMPLETENESS_QUESTION if @asks_about_completeness && @reminded}" \
61
+ "#{claimed_by_a_fix(member, invocation) if @correction_may_be_open && @reminded}" \
62
+ "#{after_adding(principle, invocation, in_git:) if @reminded}"
63
+ end
64
+
65
+ private
66
+
67
+ # How an added member joins an open correction, ending its command's line.
68
+ #: (String, Invocation) -> String
69
+ def claimed_by_a_fix(member, invocation)
70
+ "If you hold a correction request from submit-answer (phase correction) and this member fixes one of its " \
71
+ "findings, name #{member} in the changed_members of the fixed disposition; the next full audit assesses " \
72
+ "it.\nTo submit the correction instead: #{invocation.submit_answer("REQUEST_ID")}\n"
73
+ end
74
+
75
+ # Commit/inspection guidance and the first audit's place, once the map lists every member.
76
+ #: (PrintedPrinciple, Invocation, in_git: bool) -> String
77
+ def after_adding(principle, invocation, in_git:)
78
+ "Commit #{principle.file} as it changes, so the project's history shows each change; in git, start-audit " \
79
+ "refuses a map that is not committed.\n" \
80
+ "To see the map so far: #{invocation.in_project("show-principle", principle.id)}\n" \
81
+ "#{FirstAudit.new(invocation, in_git:).after_mapping(principle.id, keeps_others_held: @keeps_others_held)}"
82
+ end
29
83
  end
30
84
  end
31
85
  end
@@ -4,6 +4,8 @@
4
4
  require_relative "invocation"
5
5
  require_relative "printed_principle"
6
6
  require_relative "lines_shared_with_member"
7
+ require_relative "consecutive_sections_elsewhere"
8
+ require_relative "added_member"
7
9
  require_relative "map_added_to"
8
10
  require_relative "activation_in_hand"
9
11
  require_relative "first_audit"
@@ -17,7 +19,7 @@ module Principles
17
19
  class MapResult
18
20
  # The placeholders each printed command leaves for the agent to fill.
19
21
  ADD_MEMBER_USAGE = "PATH [--section \"Exact heading text\"] [--starting-at \"text that occurs once\" " \
20
- "[--ending-at \"text that closes the passage\"]] [--query '$.description'] " \
22
+ "[--ending-at \"text occurring once after the opening\"]] [--query '$.description'] " \
21
23
  "--role \"The part it plays\""
22
24
 
23
25
  CREATED = "Which files or Markdown sections reinforce this principle? Add each one with the part it plays, " \
@@ -40,6 +42,17 @@ module Principles
40
42
  question(principle, CREATED, add_member_command(principle.id))
41
43
  end
42
44
 
45
+ # Removal changes an entry rather than writing a file; an untracked deleted map needs no git commit.
46
+ #: (String, file: String) -> Hash[String, untyped]
47
+ def removed(id, file:)
48
+ commit = @in_git ? "If this map was tracked, commit its removal.\n" : ""
49
+ { "status" => "removed", "principle_id" => id, "wrote" => [], "removed" => [file],
50
+ "next_action" => "This map is inactive in routine reports. Any retained findings remain unresolved.\n" \
51
+ "Inspect a readable retained record, if one exists: " \
52
+ "#{@invocation.in_project("show-audit", id)}\n" \
53
+ "#{commit}Inspect the remaining maps: #{@invocation.in_project("list-principles")}" }
54
+ end
55
+
43
56
  #: (PrintedPrinciple) -> Hash[String, untyped]
44
57
  def description_changed(principle)
45
58
  question(principle, "Changed the description of #{principle.id}.", start_audit(principle.id))
@@ -63,14 +76,16 @@ module Principles
63
76
 
64
77
  # shared says which members share a line with the new one; added lists them only when there are some, as it
65
78
  # carries a check only when one is named. joined is what the result says of the map the member joined.
66
- #: (PrintedPrinciple, added: Hash[String, untyped], ?shared: LinesSharedWithMember, ?joined: MapAddedTo)
79
+ #: (PrintedPrinciple, added: Hash[String, untyped], ?shared: LinesSharedWithMember, ?joined: MapAddedTo,
80
+ #| ?consecutive: ConsecutiveSectionsElsewhere)
67
81
  #| -> Hash[String, untyped]
68
- def member_added(principle, added:, shared: LinesSharedWithMember.new, joined: MapAddedTo.new)
69
- added = added.merge(shared.to_h)
70
- question(principle, "#{span(added)}#{shared.note}Add the next member the same way. " \
71
- "#{after_the_member(principle, added.fetch("id"), joined)}".rstrip,
82
+ def member_added(principle, added:, shared: LinesSharedWithMember.new, joined: MapAddedTo.new,
83
+ consecutive: ConsecutiveSectionsElsewhere.new)
84
+ member = AddedMember.new(added, shared: shared, consecutive: consecutive)
85
+ after = joined.after_member(principle, member: member.id, invocation: @invocation, in_git: @in_git)
86
+ question(principle, "#{member.opening}#{after}".rstrip,
72
87
  add_member_command(principle.id), shown: { "member_count" => principle.members.length })
73
- .merge("added" => added)
88
+ .merge("added" => member.to_h.merge(joined.added_facts))
74
89
  end
75
90
 
76
91
  # add-member's report of the map it started, with the description and activation it wrote, which the agent
@@ -127,41 +142,6 @@ module Principles
127
142
 
128
143
  private
129
144
 
130
- # What add-member's question says after the member it added, id, as joined says of the map: how a fix claims
131
- # it while a correction may be open, then what to do after mapping, each only when joined says to remind, once
132
- # per sitting (#1025, #1057).
133
- #: (PrintedPrinciple, String, MapAddedTo) -> String
134
- def after_the_member(principle, id, joined)
135
- "#{claimed_by_a_fix(id) if joined.correction_may_be_open && joined.reminded}" \
136
- "#{after_adding(principle, keeps_others_held: joined.keeps_others_held) if joined.reminded}"
137
- end
138
-
139
- # How a member added while a correction is open joins it: a fix claims it, and the next full audit assesses it
140
- # (D72). It ends its own line, since it ends with a command.
141
- #: (String) -> String
142
- def claimed_by_a_fix(member)
143
- "If you hold a correction request from submit-answer (phase correction) and this member fixes one of its " \
144
- "findings, name #{member} in the changed_members of the fixed disposition; the next full audit assesses " \
145
- "it.\nTo submit the correction instead: #{@invocation.submit_answer("REQUEST_ID")}\n"
146
- end
147
-
148
- # What add-member says after the member it added: to commit the map as it changes, how to see it, and the full
149
- # audit's place once it lists every member.
150
- #: (PrintedPrinciple, keeps_others_held: bool) -> String
151
- def after_adding(principle, keeps_others_held:)
152
- "Commit #{principle.file} as it changes, so the project's history shows each change; in git, start-audit " \
153
- "refuses a map that is not committed.\n" \
154
- "To see the map so far: #{@invocation.in_project("show-principle", principle.id)}\n" \
155
- "#{FirstAudit.new(@invocation, in_git: @in_git).after_mapping(principle.id, keeps_others_held:)}"
156
- end
157
-
158
- # The lines a member spans, said so that a passage cut short shows; it ends with a space.
159
- #: (Hash[String, untyped]) -> String
160
- def span(member)
161
- "#{member.fetch("id")} spans lines #{member.fetch("first_line")} to #{member.fetch("last_line")}; " \
162
- "if that is not the passage you meant, move it with move-member. "
163
- end
164
-
165
145
  # shown is what the result prints of the map: the whole map unless the caller names less, as add-member
166
146
  # does (#400).
167
147
  #: (PrintedPrinciple, String, String, ?shown: Hash[String, untyped]) -> Hash[String, untyped]
@@ -0,0 +1,47 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation"
5
+ require_relative "principles_with_no_completed_audit"
6
+
7
+ module Principles
8
+ module Views
9
+ # Mapping facts that precede baseline instructions, and their next steps once those instructions are met.
10
+ class MapsNeedingMembersOrAudit
11
+ #: (Invocation, report: Hash[String, untyped], files_to_commit: Hash[String, Array[String]],
12
+ #| ?waiting: Array[String]) -> void
13
+ def initialize(invocation, report:, files_to_commit:, waiting: [])
14
+ @invocation = invocation
15
+ awaiting = report.fetch("awaiting_first_audit", [])
16
+ @ids = report.fetch("no_completed_audit", []) - awaiting - waiting #: Array[String]
17
+ @empty = report.fetch("empty_maps", []) - waiting #: Array[String]
18
+ @files = files_to_commit
19
+ freeze
20
+ end
21
+
22
+ #: () -> String?
23
+ def notice
24
+ PrinciplesWithNoCompletedAudit.new(ids: @ids, audits: []).notice unless @ids.empty?
25
+ end
26
+
27
+ #: () -> Array[String]
28
+ def actions
29
+ [*@empty.map { |id| empty_map(id) }, *(@ids - @empty).map { |id| first_audit(id) }]
30
+ end
31
+
32
+ private
33
+
34
+ #: (String) -> String
35
+ def empty_map(id)
36
+ "#{id} has no members. Add its first member: " \
37
+ "#{@invocation.in_project("add-member", id, usage: "PATH --role ROLE")}"
38
+ end
39
+
40
+ #: (String) -> String
41
+ def first_audit(id)
42
+ after = @files.fetch(id, []).empty? ? "To" : "After committing the required files,"
43
+ "#{after} start #{id}'s first full audit: #{@invocation.in_project("start-audit", id)}"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -25,7 +25,8 @@ module Principles
25
25
  freeze
26
26
  end
27
27
 
28
- # The first line on each side the other lacks, which the template's quotes print (#1111).
28
+ # The first line on each side the other lacks, which an answer leaving its quotes out reads them as (#1111,
29
+ # #1166).
29
30
  #: Hash[String, String]
30
31
  attr_reader :first_changed_lines
31
32
 
@@ -13,7 +13,8 @@ module Principles
13
13
  FLAGS = { "section" => "--section", "starting_at" => "--starting-at", "ending_at" => "--ending-at",
14
14
  "query" => "--query", "path" => "--path" }.freeze #: Hash[String, String]
15
15
  # The placeholder the agent fills in for each field a move leaves to it.
16
- PLACEHOLDERS = { "section" => "HEADING", "starting_at" => "NEW_OPENING_TEXT", "query" => "QUERY",
16
+ PLACEHOLDERS = { "section" => "HEADING", "starting_at" => "NEW_OPENING_TEXT",
17
+ "ending_at" => "NEW_ENDING_TEXT", "query" => "QUERY",
17
18
  "path" => "NEW_PATH" }.freeze #: Hash[String, String]
18
19
 
19
20
  #: (Invocation) -> void
@@ -0,0 +1,61 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "visible_text"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # One changed member as a line of tab-separated fields, each written through VisibleText: its principle, id,
10
+ # newest commit that changed it (or "uncommitted"), that commit's subject, and what it was compared with:
11
+ # "audit" or "mapping_commit", then "waiting_on_an_upgrade" for one compared with hashes a later copy wrote.
12
+ # The after-commit hook prints it (D73), and list-member-problems --short its short form, without the subject.
13
+ class MemberRow
14
+ # member is one entry of list-member-problems' "members", with its "history".
15
+ #: (Hash[String, untyped]) -> void
16
+ def initialize(member)
17
+ @member = member
18
+ freeze
19
+ end
20
+
21
+ #: () -> String
22
+ def to_s
23
+ history = @member.fetch("history", {})
24
+ newest = history.fetch("commits", []).first
25
+ joined([*head, newest ? described(newest, history) : "not committed yet", *tail])
26
+ end
27
+
28
+ # The row without the commit's subject, which repeats on every row one commit changed and which
29
+ # list-member-problems' JSON keeps (#1263).
30
+ #: () -> String
31
+ def short = joined([*head, *tail])
32
+
33
+ private
34
+
35
+ # The principle, id and newest commit that changed the member, or "uncommitted".
36
+ #: () -> Array[String]
37
+ def head
38
+ newest = @member.fetch("history", {}).fetch("commits", []).first
39
+ [@member.fetch("principle"), @member.fetch("id"), newest ? newest.fetch("commit") : "uncommitted"]
40
+ end
41
+
42
+ # What the member was compared with, and whether its audit waits on an upgrade.
43
+ #: () -> Array[String]
44
+ def tail = [@member.dig("since", "baseline").to_s, *("waiting_on_an_upgrade" if @member["waiting_on_an_upgrade"])]
45
+
46
+ #: (Array[String]) -> String
47
+ def joined(fields) = fields.map { |field| VisibleText.new(field).to_s }.join("\t")
48
+
49
+ # The newest commit's subject, with how many earlier commits changed the member, and whether it changed
50
+ # again on disk.
51
+ #: (Hash[String, untyped], Hash[String, untyped]) -> String
52
+ def described(newest, history)
53
+ earlier = history.fetch("commits").length - 1
54
+ more = history.dig("stopped_at", "reason") == "limit" ? " or more" : ""
55
+ notes = [("+#{earlier}#{more} earlier" if earlier.positive?),
56
+ ("also uncommitted" if history["uncommitted"])].compact
57
+ notes.empty? ? newest.fetch("subject") : "#{newest.fetch("subject")} (#{notes.join("; ")})"
58
+ end
59
+ end
60
+ end
61
+ end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "json"
5
5
  require_relative "invocation"
6
+ require_relative "member_row"
6
7
  require_relative "problem_lines"
7
8
  require_relative "prompts"
8
9
  require_relative "record_waiting_on_an_upgrade"
@@ -70,7 +71,7 @@ module Principles
70
71
  end
71
72
 
72
73
  #: (Array[Hash[String, untyped]]) -> Array[String]
73
- def rows(members) = members.map { |member| ProblemLines.new(@invocation).row(member) }
74
+ def rows(members) = members.map { MemberRow.new(it).to_s }
74
75
 
75
76
  # The line saying how many other changed members list-member-problems still lists, or none when it lists none.
76
77
  #: (Integer) -> Array[String]
@@ -27,17 +27,24 @@ module Principles
27
27
  "#{one? ? "it" : "they"} changed is not yet known.#{remedy}"
28
28
  end
29
29
 
30
+ # Whether its remedy names the audit command, as it does unless committing files gives the baseline (#1279).
31
+ #: () -> bool
32
+ def names_a_command? = !committing?
33
+
30
34
  private
31
35
 
32
36
  #: () -> bool
33
37
  def one? = @count == 1
34
38
 
39
+ #: () -> bool
40
+ def committing? = @because == "not_committed" && !@files.empty?
41
+
35
42
  # What gives the members a baseline: a completed audit outside git, or in git committing the files that
36
43
  # differ from HEAD, or an audit again when none does, since every file is committed already (#710 X3). The
37
44
  # audit command starts a line of its own, after its purpose.
38
45
  #: () -> String
39
46
  def remedy
40
- return " Committing #{ProseList.new(@files)} #{gives}." if @because == "not_committed" && !@files.empty?
47
+ return " Committing #{ProseList.new(@files)} #{gives}." if committing?
41
48
 
42
49
  "#{all_committed if @because == "not_committed"}\nA completed audit #{gives}: #{@audit}"
43
50
  end