principles 0.0.5 → 0.0.6

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/command_line.rb +12 -28
  4. data/lib/principles/command_routes.rb +7 -1
  5. data/lib/principles/controllers/acknowledgement.rb +36 -26
  6. data/lib/principles/controllers/answer.rb +7 -5
  7. data/lib/principles/controllers/assessment.rb +14 -3
  8. data/lib/principles/controllers/audit_completion.rb +3 -1
  9. data/lib/principles/controllers/command.rb +2 -2
  10. data/lib/principles/controllers/correction.rb +3 -1
  11. data/lib/principles/controllers/full_audit_request.rb +1 -1
  12. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  13. data/lib/principles/controllers/inventory.rb +3 -22
  14. data/lib/principles/controllers/mapping.rb +9 -1
  15. data/lib/principles/controllers/member_addition.rb +65 -0
  16. data/lib/principles/controllers/member_entries.rb +6 -24
  17. data/lib/principles/controllers/member_problems_report.rb +2 -2
  18. data/lib/principles/controllers/members_to_assess.rb +1 -1
  19. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  20. data/lib/principles/controllers/repoint.rb +5 -2
  21. data/lib/principles/controllers/survey.rb +60 -0
  22. data/lib/principles/data/audit_files.rb +4 -0
  23. data/lib/principles/data/candidate_files_found.rb +48 -13
  24. data/lib/principles/data/command-steps.json +77 -16
  25. data/lib/principles/data/committed_tree.rb +84 -0
  26. data/lib/principles/data/first_parent_log.rb +48 -0
  27. data/lib/principles/data/first_parent_range.rb +122 -0
  28. data/lib/principles/data/git_command.rb +37 -0
  29. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  30. data/lib/principles/data/map_files.rb +35 -10
  31. data/lib/principles/data/principles_directory.rb +40 -0
  32. data/lib/principles/data/principles_subfolder.rb +39 -16
  33. data/lib/principles/data/project_files.rb +11 -3
  34. data/lib/principles/data/repository.rb +55 -29
  35. data/lib/principles/data/requested_candidate_files.rb +43 -0
  36. data/lib/principles/data/running_version.rb +3 -5
  37. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +4 -5
  38. data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
  39. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  40. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  41. data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
  42. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  43. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  44. data/lib/principles/data/verified_head.rb +162 -0
  45. data/lib/principles/invocation_options.rb +2 -2
  46. data/lib/principles/models/acknowledgement.rb +28 -6
  47. data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
  48. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  49. data/lib/principles/models/audit_record.rb +4 -0
  50. data/lib/principles/models/audit_records.rb +34 -8
  51. data/lib/principles/models/candidate_files.rb +17 -6
  52. data/lib/principles/models/candidate_inventory.rb +51 -7
  53. data/lib/principles/models/captured_head.rb +72 -0
  54. data/lib/principles/models/check_since_last_audit.rb +4 -8
  55. data/lib/principles/models/declared_map_changes.rb +25 -9
  56. data/lib/principles/models/declared_member_removals.rb +75 -0
  57. data/lib/principles/models/disposition.rb +4 -2
  58. data/lib/principles/models/fix_only_fields.rb +12 -0
  59. data/lib/principles/models/guidance_search_path.rb +26 -0
  60. data/lib/principles/models/guidance_search_paths.rb +57 -0
  61. data/lib/principles/models/line_span.rb +6 -0
  62. data/lib/principles/models/loaded_files.rb +1 -2
  63. data/lib/principles/models/loading_scope.rb +61 -0
  64. data/lib/principles/models/locator.rb +6 -0
  65. data/lib/principles/models/mapped_principles.rb +39 -37
  66. data/lib/principles/models/member_file.rb +20 -71
  67. data/lib/principles/models/member_history.rb +7 -5
  68. data/lib/principles/models/member_loading_scopes.rb +49 -0
  69. data/lib/principles/models/member_loads.rb +4 -0
  70. data/lib/principles/models/member_mapping_run.rb +30 -0
  71. data/lib/principles/models/member_moves.rb +4 -0
  72. data/lib/principles/models/member_problems.rb +48 -24
  73. data/lib/principles/models/member_region.rb +129 -0
  74. data/lib/principles/models/member_repair_moves.rb +9 -11
  75. data/lib/principles/models/member_snapshots.rb +14 -1
  76. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  77. data/lib/principles/models/meta_principle.rb +14 -0
  78. data/lib/principles/models/missing_files.rb +2 -2
  79. data/lib/principles/models/other_templates_placeholders.rb +1 -1
  80. data/lib/principles/models/outline_budget.rb +29 -14
  81. data/lib/principles/models/principle.rb +14 -7
  82. data/lib/principles/models/principle_file_revision.rb +48 -0
  83. data/lib/principles/models/principle_history.rb +46 -19
  84. data/lib/principles/models/principle_lineage.rb +118 -0
  85. data/lib/principles/models/principle_map_revision.rb +39 -0
  86. data/lib/principles/models/principle_mapping_history.rb +132 -0
  87. data/lib/principles/models/principle_members.rb +14 -0
  88. data/lib/principles/models/principle_predecessor.rb +45 -0
  89. data/lib/principles/models/principle_publication.rb +177 -0
  90. data/lib/principles/models/principle_revision.rb +104 -0
  91. data/lib/principles/models/problem_report.rb +17 -5
  92. data/lib/principles/models/project.rb +43 -27
  93. data/lib/principles/models/project_history.rb +45 -25
  94. data/lib/principles/models/record_format.rb +6 -0
  95. data/lib/principles/models/reported_check.rb +2 -1
  96. data/lib/principles/models/sent_answer.rb +10 -0
  97. data/lib/principles/models/survey_search_paths.rb +26 -0
  98. data/lib/principles/models/uncommitted_files.rb +50 -0
  99. data/lib/principles/models/unknown_principle.rb +29 -0
  100. data/lib/principles/positional_arguments.rb +37 -0
  101. data/lib/principles/version.rb +2 -2
  102. data/lib/principles/views/acknowledgement_result.rb +16 -12
  103. data/lib/principles/views/added_member.rb +41 -0
  104. data/lib/principles/views/answered_request.rb +21 -0
  105. data/lib/principles/views/assessment_request.rb +2 -1
  106. data/lib/principles/views/audit_result.rb +21 -26
  107. data/lib/principles/views/candidate_files_result.rb +56 -12
  108. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  109. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  110. data/lib/principles/views/correction_request.rb +32 -1
  111. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  112. data/lib/principles/views/json_with_entries_on_lines.rb +12 -4
  113. data/lib/principles/views/map_added_to.rb +56 -2
  114. data/lib/principles/views/map_result.rb +22 -42
  115. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  116. data/lib/principles/views/member_change_since_baseline.rb +2 -1
  117. data/lib/principles/views/member_repairs.rb +2 -1
  118. data/lib/principles/views/new_loading_scope.rb +31 -0
  119. data/lib/principles/views/one_member_check_result_template.rb +25 -21
  120. data/lib/principles/views/principle_read_result.rb +4 -1
  121. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  122. data/lib/principles/views/problem_lines.rb +3 -1
  123. data/lib/principles/views/problem_result.rb +8 -3
  124. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -3
  125. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -6
  126. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -43
  127. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  128. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +12 -0
  129. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  130. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  131. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  132. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +4 -2
  133. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  134. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +2 -2
  135. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  136. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  137. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  138. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  139. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  140. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  141. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +37 -4
  142. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +5 -4
  143. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  144. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  145. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  146. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +26 -0
  147. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  148. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +2 -2
  149. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  150. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  151. metadata +55 -4
  152. data/lib/principles/models/candidate_listing.rb +0 -41
@@ -13,7 +13,8 @@ module Principles
13
13
  # One member's check and the result an agent reports for it (D30). This tool never runs the check: it
14
14
  # refuses a report that cannot be about the member's own check, and cannot confirm the run happened.
15
15
  class ReportedCheck
16
- SHAPES = "Give check_result as answer_guide.check_result shows."
16
+ SHAPES = "Merge one inner example from answer_guide.check_result.examples into that member's " \
17
+ "response_template.check_result as copy_from says."
17
18
  # How review_basis records a review the agent made itself, which the placeholder and the repair both give.
18
19
  SELF_REVIEWED = "\"Self-reviewed by the agent: <what you checked it against>\"" #: String
19
20
  # The not_run_reason a template prints beside exit_status's placeholder, which an answer that leaves it as
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../data/schema_check"
5
+ require_relative "../data/project_files"
5
6
  require_relative "../error"
6
7
  require_relative "refusal_before_shape"
7
8
 
@@ -22,6 +23,15 @@ module Principles
22
23
 
23
24
  REPAIR = "Repair each field listed, starting from the request's response_template." #: String
24
25
 
26
+ # The answer read from the file or stdin the agent named, using its phase's schema.
27
+ #: (Data::ProjectFiles, String, stdin: String?, phase: String) -> SentAnswer
28
+ def self.read(files, file, stdin:, phase:)
29
+ parsed = if file == "-" then files.parse_json(stdin.to_s, "-", named: NAMED)
30
+ else files.read_json(file, named: FILE_NAMED)
31
+ end
32
+ new(parsed, file, Data::SchemaCheck.new("#{phase}-answer"))
33
+ end
34
+
25
35
  # parsed is the answer as its source, a file or - for stdin, holds it; check is its phase's answer schema.
26
36
  #: (untyped, String, Data::SchemaCheck) -> void
27
37
  def initialize(parsed, source, check)
@@ -0,0 +1,26 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "guidance_search_path"
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 project's recorded guidance search paths and this invocation's temporary selections, combined once.
10
+ class SurveySearchPaths
11
+ #: Array[String]
12
+ attr_reader :globs
13
+
14
+ #: (recorded: Array[String], also: Array[String]) -> void
15
+ def initialize(recorded:, also:)
16
+ @recorded = recorded.map { |glob| GuidanceSearchPath.new(glob).glob }.uniq.freeze #: Array[String]
17
+ @globs = (@recorded | also.map { |glob| GuidanceSearchPath.new(glob).glob }).freeze #: Array[String]
18
+ freeze
19
+ end
20
+
21
+ # Saved provenance is distinct from all match counts; omit it when the project records no search paths.
22
+ #: () -> Hash[String, untyped]
23
+ def recorded_listing = @recorded.empty? ? {} : { "recorded_guidance_search_paths" => @recorded }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The files, and the files their links lead to, that differ from HEAD or are not yet committed, as ProjectHistory
10
+ # found them for a write-up or an audit's members, and the refusal each gives while there are any.
11
+ class UncommittedFiles
12
+ # An existing assessment keeps its prepared answer while these whole files are brought back to a commit.
13
+ ASSESSMENT_REPAIR = "An audit requires the whole map and member files to be committed, even when an edit " \
14
+ "is outside a judged passage.\nCommit the intended changes in the named files, then retry " \
15
+ "the same answer unchanged. If that retry is refused as stale, follow its repair to " \
16
+ "start a new audit."
17
+
18
+ #: (Array[String]) -> void
19
+ def initialize(paths)
20
+ @paths = paths
21
+ freeze
22
+ end
23
+
24
+ # Refuses the write-up at path while it, or a file its links lead to, differs from HEAD: the record is committed
25
+ # pointing at it, so a fresh clone would find nothing there (#760).
26
+ #: (String) -> void
27
+ def refuse_write_up(path)
28
+ return if @paths.empty?
29
+
30
+ linked = @paths - [path]
31
+ raise Error.new("uncommitted_files",
32
+ "The write-up at #{path} differs from the last commit" +
33
+ (linked.empty? ? "" : ", through #{linked.join(", ")}"),
34
+ "The record will point at the write-up as committed.\n" \
35
+ "Commit the write-up, then submit the same answer again.")
36
+ end
37
+
38
+ # Refuses an audit of id while any of its map or members differs from HEAD.
39
+ #: (String) -> void
40
+ def refuse_audit(id)
41
+ return if @paths.empty?
42
+
43
+ raise Error.new("uncommitted_files", "The map or members of #{id} differ from the last commit: " \
44
+ "#{@paths.join(", ")}",
45
+ "An audit assesses the map and members as committed, so its record can name the commit " \
46
+ "it began from.\nCommit them, then start it again: #{Error::EXECUTABLE} start-audit #{id}")
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "meta_principle"
6
+
7
+ module Principles
8
+ module Models
9
+ # An absent principle id, whose repair creates an ordinary map or sets up the keeping principle.
10
+ class UnknownPrinciple
11
+ #: (String) -> void
12
+ def initialize(id)
13
+ @id = id.dup.freeze #: String
14
+ freeze
15
+ end
16
+
17
+ #: () -> Error
18
+ def refusal
19
+ creating = if @id == MetaPrinciple::ID
20
+ MetaPrinciple::SET_UP
21
+ else
22
+ "To create it: #{Error::EXECUTABLE} create-principle #{@id} --description TEXT"
23
+ end
24
+ Error.new("unknown_principle", "No map named #{@id}",
25
+ "#{creating}\nTo see the mapped ids: #{Error::EXECUTABLE} list-principles")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The positional words a command takes and the values the invocation gives them, after option parsing.
6
+ class PositionalArguments
7
+ #: (Array[String], Array[String]) -> void
8
+ def initialize(names, values)
9
+ @names = names.dup.freeze #: Array[String]
10
+ @values = values.dup.freeze #: Array[String]
11
+ freeze
12
+ end
13
+
14
+ #: () -> String?
15
+ def id = %w[id id?].include?(@names.first) ? @values.first : nil
16
+
17
+ # Every named argument other than the principle id, as the controller receives it.
18
+ #: () -> Hash[String, untyped]
19
+ def bindings
20
+ bound = @names.zip(@values).to_h.except("id", "id?")
21
+ repeated = @names.last
22
+ return bound unless repeated == "path..."
23
+
24
+ bound.except(repeated).merge("path" => @values.drop(@names.length - 1))
25
+ end
26
+
27
+ #: () -> Array[String]
28
+ def missing = @names.drop(@values.length).reject { |name| name.end_with?("?") }.map(&:upcase)
29
+
30
+ #: () -> bool
31
+ def too_many? = @names.last != "path..." && @values.length > @names.length
32
+
33
+ # The command's positional arguments as usage shows them, optional ones in brackets.
34
+ #: () -> String
35
+ def shown = @names.map { |name| name.end_with?("?") ? "[#{name.chomp("?").upcase}]" : name.upcase }.join(" ")
36
+ end
37
+ end
@@ -3,9 +3,9 @@
3
3
 
4
4
  module Principles
5
5
  # The next production release, as major.minor.patch. A production build is versioned with this alone.
6
- RELEASE = "0.0.5"
6
+ RELEASE = "0.0.6"
7
7
  # The version a built gem prints. `rake build[production]` stamps RELEASE here, in the copy of lib/ it
8
8
  # packages, and `rake build[development]` stamps RELEASE.g<short sha>. A checkout leaves it nil, and
9
9
  # Data::RunningVersion reads the commit this tool runs from instead.
10
- BUILT_VERSION = "0.0.5" #: String?
10
+ BUILT_VERSION = "0.0.6" #: String?
11
11
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "invocation"
5
+ require_relative "answered_request"
5
6
  require_relative "member_change_since_baseline"
6
7
  require_relative "prompts"
7
8
 
@@ -16,36 +17,39 @@ module Principles
16
17
  freeze
17
18
  end
18
19
 
19
- # change is the member's change since its baseline; open_findings, the record's findings on the member;
20
- # placeholders, the text the template prints in each field the agent writes. What the agent judges is under
21
- # context, the question last, as in a full audit's request (D60).
20
+ # change is the member's change since its baseline; context, what the request's context shows beside it, such
21
+ # as the record's findings on the member; placeholders, the text the template prints in each field the agent
22
+ # writes. What the agent judges is under context, the question last, as in a full audit's request (D60).
22
23
  #: (request_id: String, principle_id: String, change: MemberChangeSinceBaseline,
23
- #| open_findings: Hash[String, Array[String]], placeholders: Hash[String, untyped]) -> Hash[String, untyped]
24
- def request(request_id:, principle_id:, change:, open_findings:, placeholders:)
24
+ #| context: Hash[String, untyped], placeholders: Hash[String, untyped]) -> Hash[String, untyped]
25
+ def request(request_id:, principle_id:, change:, context:, placeholders:)
25
26
  { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "acknowledgement",
26
- "context" => { "principle_id" => principle_id, **change.to_h, **open_findings,
27
+ "context" => { "principle_id" => principle_id, **change.to_h, **context,
27
28
  "question" => Prompts.text("acknowledge-a-change/say-whether-the-change-keeps-the-meaning") },
28
29
  "response_template" => answer_to_fill(request_id:, change:, placeholders:),
29
30
  "answer_with" => @invocation.submit_answer(request_id) }
30
31
  end
31
32
 
32
33
  # The answer to the request request_id names, to fill: the request prints it as response_template, and
33
- # start-audit --member --as template prints it alone, each field the agent writes holding its placeholder (#773).
34
+ # start-audit --member --as template prints it alone, each field the agent writes holding its placeholder (#773),
35
+ # and only those: the fields the answer may add, the question names (#1170).
34
36
  #: (request_id: String, change: MemberChangeSinceBaseline, placeholders: Hash[String, untyped])
35
37
  #| -> Hash[String, untyped]
36
38
  def answer_to_fill(request_id:, change:, placeholders:)
37
- { "request_id" => request_id,
38
- "basis" => { "base_commit" => change.base_commit, "member_id" => change.member_id }, **placeholders }
39
+ { "request_id" => request_id, "basis" => { "member_id" => change.member_id }, **placeholders }
39
40
  end
40
41
 
41
42
  # The acknowledgement was accepted and file holds it.
42
- #: (principle_id: String, member_id: String, file: String) -> Hash[String, untyped]
43
+ #: (principle_id: String, member_id: String, file: String) -> AnsweredRequest
43
44
  def acknowledged(principle_id:, member_id:, file:)
44
- { "status" => "acknowledged", "principle_id" => principle_id, "member_id" => member_id,
45
+ fields = {
46
+ "status" => "acknowledged", "principle_id" => principle_id, "member_id" => member_id,
45
47
  "files_to_commit" => [file],
46
48
  "next_action" => "Commit #{file}. #{member_id} reads as judged until it is edited again.\n" \
47
49
  "After committing, this no longer lists it: " \
48
- "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}" }
50
+ "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
51
+ }
52
+ AnsweredRequest.new(fields)
49
53
  end
50
54
  end
51
55
  end
@@ -0,0 +1,41 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "lines_shared_with_member"
5
+ require_relative "consecutive_sections_elsewhere"
6
+
7
+ module Principles
8
+ module Views
9
+ # The member just added: its id, current lines and check, beside its shared/consecutive location facts.
10
+ class AddedMember
11
+ #: (Hash[String, untyped], shared: LinesSharedWithMember, consecutive: ConsecutiveSectionsElsewhere) -> void
12
+ def initialize(added, shared:, consecutive:)
13
+ @added = added.merge(shared.to_h).merge(consecutive.to_h) #: Hash[String, untyped]
14
+ @shared = shared
15
+ @consecutive = consecutive
16
+ freeze
17
+ end
18
+
19
+ #: () -> String
20
+ def id = @added.fetch("id")
21
+
22
+ #: () -> Hash[String, untyped]
23
+ def to_h = @added
24
+
25
+ # The same location/remapping opening precedes the map's own after-add guidance.
26
+ #: () -> String
27
+ def opening
28
+ "#{span}#{@shared.note}#{@consecutive.note}Add the next member the same way. "
29
+ end
30
+
31
+ private
32
+
33
+ # The lines a member spans, said so that a passage cut short shows; it ends with a space.
34
+ #: () -> String
35
+ def span
36
+ "#{id} spans lines #{@added.fetch("first_line")} to #{@added.fetch("last_line")}; " \
37
+ "if that is not the passage you meant, move it with move-member. "
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ module Views
6
+ # An answered request's terminal result fields, with no further correction template to fill.
7
+ class AnsweredRequest
8
+ #: (Hash[String, untyped]) -> void
9
+ def initialize(fields)
10
+ @fields = fields
11
+ freeze
12
+ end
13
+
14
+ #: (AuditResult, String, String) -> Hash[String, untyped]
15
+ def presented_with(_view, _source_request_id, _answer_file) = @fields
16
+
17
+ #: (Hash[String, untyped], Invocation, String) -> Hash[String, untyped]
18
+ def with_correction_to_fill(acceptable, _invocation, _answer_file) = acceptable
19
+ end
20
+ end
21
+ end
@@ -15,7 +15,8 @@ module Principles
15
15
  class AssessmentRequest
16
16
  # The recent_decision the request's template prints, which names the other form in the guide beside it.
17
17
  IN_GUIDE = {
18
- "unavailable_reason" => "Or use the assessed shape in answer_guide.recent_decision."
18
+ "unavailable_reason" => "Or replace this object with answer_guide.recent_decision.examples.assessed " \
19
+ "as copy_from says."
19
20
  }.freeze #: Hash[String, String]
20
21
  # How mapped_elsewhere_instruction's paragraph on open findings elsewhere begins, which prints only when an
21
22
  # entry names one (#808).
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "../prose_list"
5
5
  require_relative "assessment_request"
6
+ require_relative "answered_request"
6
7
  require_relative "audit_changes"
7
8
  require_relative "correction_request"
8
9
  require_relative "invocation"
@@ -25,25 +26,16 @@ module Principles
25
26
  end
26
27
 
27
28
  # An answer's result as submit-answer prints it: a correction request in full, with how to answer it.
28
- #: (Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
29
- def present(output)
30
- output = correction_request(output) if output.is_a?(CorrectionRequest)
31
- output["status"] == "agent_judgement_required" ? request(output) : output
29
+ #: (AnsweredRequest | CorrectionRequest, source_request_id: String, answer_file: String)
30
+ #| -> Hash[String, untyped]
31
+ def present(output, source_request_id:, answer_file:)
32
+ output.presented_with(self, source_request_id, answer_file)
32
33
  end
33
34
 
34
- # show-answer-check's acceptable result, with the correction's answer an accepted assessment leads to, alone, to
35
- # save and fill, and how to submit it after the assessment, which outside git writes the open record it is
36
- # checked against; next_action still ends with the checked answer's submit command (#859). The result is
37
- # unchanged for any other answer (D81 step 3).
38
- #: (Hash[String, untyped], Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
39
- def with_correction_to_fill(acceptable, output)
40
- return acceptable unless output.is_a?(CorrectionRequest)
41
-
42
- save = "Once this answer is submitted with the last line's command, save correction_template, the " \
43
- "correction's answer it leads to, to a file outside the project, such as under $TMPDIR, fill only " \
44
- "its dispositions, and submit it: #{@invocation.submit_answer(output.request_id)}"
45
- acceptable.merge("correction_template" => output.template,
46
- "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
35
+ # A correction request adds its answer to fill; a terminal result leaves the acceptable preview alone.
36
+ #: (Hash[String, untyped], AnsweredRequest | CorrectionRequest, answer_file: String) -> Hash[String, untyped]
37
+ def with_correction_to_fill(acceptable, output, answer_file:)
38
+ output.with_correction_to_fill(acceptable, @invocation, answer_file)
47
39
  end
48
40
 
49
41
  # show-answer-check: the answer passed every check, and what submitting it would write. open_findings_will_print
@@ -81,9 +73,11 @@ module Principles
81
73
 
82
74
  # submit-answer: the correction request that follows an assessment with findings, as a judgement to answer
83
75
  # under its request id, saying what submitting the assessment stored.
84
- #: (CorrectionRequest) -> Hash[String, untyped]
85
- def correction_request(request)
86
- judgement("correction", request).merge("stored" => request.stored)
76
+ #: (CorrectionRequest, source_request_id: String, answer_file: String) -> Hash[String, untyped]
77
+ def correction_request(request, source_request_id:, answer_file:)
78
+ judgement("correction", request).merge("stored" => request.stored,
79
+ "correction_recovery" => request.recovery(source_request_id, answer_file,
80
+ @invocation))
87
81
  end
88
82
 
89
83
  # A completed audit: its resolved and open findings, the files to commit and, in git, each changed
@@ -120,6 +114,13 @@ module Principles
120
114
  "The last audit's record, #{file}, is not committed. Commit it, so the project keeps it."
121
115
  end
122
116
 
117
+ # Wraps a known judgement request with this run's project and answer command.
118
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
119
+ def request(output)
120
+ submit = @invocation.submit_answer(output.fetch("request_id"))
121
+ output.merge("project" => @invocation.project, "answer_with" => submit)
122
+ end
123
+
123
124
  private
124
125
 
125
126
  # request as a judgement to answer in phase, under its id, which its template's head also gives.
@@ -130,12 +131,6 @@ module Principles
130
131
  "limits" => Prompts.text("answer-any-judgement-request/what-a-self-audit-cannot-show") }
131
132
  end
132
133
 
133
- #: (Hash[String, untyped]) -> Hash[String, untyped]
134
- def request(output)
135
- submit = @invocation.submit_answer(output.fetch("request_id"))
136
- output.merge("project" => @invocation.project, "answer_with" => submit)
137
- end
138
-
139
134
  # A completed audit's next step, from what it changed and how to commit it.
140
135
  #: (String, AuditChanges, AuditCommit | AuditCommit::ByHand) -> String
141
136
  def completed_next_action(id, changes, commit)
@@ -15,7 +15,7 @@ module Principles
15
15
  # name in it (#405, #412).
16
16
  class Found
17
17
  # What each listed file prints: where it is, how big, where a link leads, and what the survey reads of it.
18
- PRINTED_FILE_FIELDS = %w[path characters symlink_to description opening_line outline].freeze
18
+ PRINTED_FILE_FIELDS = %w[path characters symlink_to changed_in_range description opening_line outline].freeze
19
19
 
20
20
  #: Hash[String, Array[String]]
21
21
  attr_reader :owner_asks
@@ -28,6 +28,10 @@ module Principles
28
28
  #: () -> bool
29
29
  def left_out? = @inventory.key?("outlines_left_out")
30
30
 
31
+ # What the outlines of the files a range changed print, when every cut left them past the budget (#1171).
32
+ #: () -> Integer?
33
+ def range_outlines_bytes = @inventory["range_outlines_bytes"]
34
+
31
35
  #: (inventory: Hash[String, untyped], untracked: Array[String]?,
32
36
  #| owner_asks: Hash[String, Array[String]]) -> void
33
37
  def initialize(inventory:, untracked:, owner_asks:)
@@ -59,25 +63,58 @@ module Principles
59
63
 
60
64
  # The inventory, and the question of which principle to map, with one item for each list under found's owner_asks
61
65
  # to ask the owner about.
62
- #: (Found, existing_maps: Array[String], map_file: String) -> Hash[String, untyped]
63
- def question(found, existing_maps:, map_file:)
64
- { "status" => "question", "inventory" => found.listed, "existing_maps" => existing_maps,
65
- "writes" => Prompts.text("find-a-principle-to-map/what-each-command-writes", map_file: map_file),
66
- "question" => principle_question(found),
67
- "answer_with" => @invocation.in_project("create-principle", usage: CREATE_PRINCIPLE_USAGE) }
66
+ #: (Found, existing_maps: Array[String], map_file: String,
67
+ #| mapped_principles: Array[Hash[String, untyped]]) -> Hash[String, untyped]
68
+ def question(found, existing_maps:, map_file:, mapped_principles:)
69
+ survey, choice = survey_questions(existing_maps)
70
+ result = { "status" => "question", "inventory" => found.listed, "existing_maps" => existing_maps,
71
+ "writes" => Prompts.text("find-a-principle-to-map/what-each-command-writes", map_file: map_file),
72
+ "question" => principle_question(found, survey: survey, choice: choice),
73
+ "answer_with" => mapping_answer(existing_maps),
74
+ **(mapped_principles.empty? ? {} : { "mapped_principles" => mapped_principles }) }
75
+ existing_maps.empty? ? result : instructions_first(result)
68
76
  end
69
77
 
70
78
  private
71
79
 
80
+ # Keep the survey's next action and existing-map comparison ahead of a potentially large inventory.
81
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
82
+ def instructions_first(result)
83
+ result.slice("status", "question", "answer_with", "mapped_principles", "existing_maps").merge(result)
84
+ end
85
+
86
+ # The table instructions and its later choice, with or without mapped rules to compare against.
87
+ #: (Array[String]) -> [String, String]
88
+ def survey_questions(existing_maps)
89
+ if existing_maps.empty?
90
+ [Prompts.text("find-a-principle-to-map/choose-one-principle"),
91
+ Prompts.text("find-a-principle-to-map/ask-which-principle-to-map")]
92
+ else
93
+ [Prompts.text("find-a-principle-to-map/compare-with-mapped-principles"),
94
+ Prompts.text("find-a-principle-to-map/choose-an-existing-or-new-principle")]
95
+ end
96
+ end
97
+
98
+ # The map writes available after the table: extending an existing principle or starting a distinct one.
99
+ #: (Array[String]) -> String
100
+ def mapping_answer(existing_maps)
101
+ create = @invocation.in_project("create-principle", usage: CREATE_PRINCIPLE_USAGE)
102
+ return create if existing_maps.empty?
103
+
104
+ add = @invocation.in_project("add-member", usage: "ID PATH --role ROLE")
105
+ "To add a member to an existing principle: #{add}\nTo map a distinct principle: #{create}"
106
+ end
107
+
72
108
  # The survey, leaving out files possibly test data, and when outlines were cut or left out how to read them, then
73
109
  # one item per list to ask the owner about after the table.
74
- #: (Found) -> String
75
- def principle_question(found)
110
+ #: (Found, survey: String, choice: String) -> String
111
+ def principle_question(found, survey:, choice:)
76
112
  owner_asks = found.owner_asks
77
113
  asks = owner_asks.map { |key, paths| "- #{owner_ask(key, named: inline(paths))}" }
78
- [Prompts.text("find-a-principle-to-map/choose-one-principle"), *left_out_of_the_survey(owner_asks),
114
+ [survey, *left_out_of_the_survey(owner_asks),
79
115
  *budget_notes(found),
80
- Prompts.text("find-a-principle-to-map/ask-which-principle-to-map"),
116
+ choice,
117
+ Prompts.text("find-a-principle-to-map/ask-about-other-guidance-search-paths"),
81
118
  *([Prompts.text("find-a-principle-to-map/ask-the-owner-after-the-table"), *asks].join("\n") if asks.any?)]
82
119
  .join("\n\n")
83
120
  end
@@ -86,7 +123,14 @@ module Principles
86
123
  #: (Found) -> Array[String]
87
124
  def budget_notes(found)
88
125
  [*(Prompts.text("find-a-principle-to-map/read-a-cut-section-back") if found.cut?),
89
- *(Prompts.text("find-a-principle-to-map/read-left-out-files") if found.left_out?)]
126
+ *(Prompts.text("find-a-principle-to-map/read-left-out-files") if found.left_out?),
127
+ *range_past_budget(found.range_outlines_bytes)]
128
+ end
129
+
130
+ # How to survey a range whose own outlines pass the budget, given what they print; nothing when they do not.
131
+ #: (Integer?) -> Array[String]
132
+ def range_past_budget(bytes)
133
+ bytes ? [Prompts.text("find-a-principle-to-map/survey-a-later-range", bytes: bytes.to_s)] : []
90
134
  end
91
135
 
92
136
  # The line leaving files possibly test data out of the survey, when any is listed.
@@ -0,0 +1,25 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "prompts"
5
+ require_relative "json_with_entries_on_lines"
6
+
7
+ module Principles
8
+ module Views
9
+ # The requested outlines, with the same omissions as a survey and the way to request less at once.
10
+ class CandidateOutlinesResult
11
+ #: (Hash[String, untyped]) -> void
12
+ def initialize(inventory)
13
+ @inventory = inventory
14
+ freeze
15
+ end
16
+
17
+ #: () -> JsonWithEntriesOnLines
18
+ def result
19
+ values = { "status" => "ok", "question" => Prompts.text("read-requested-outlines/continue-the-survey"),
20
+ "inventory" => @inventory, "wrote" => [] }
21
+ JsonWithEntriesOnLines.new(values, under: "inventory", key: "files")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -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,11 +41,41 @@ 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
80
  # twice plainly replaced nothing: in git, where the audit has a base commit, nothing; outside git, the open
50
81
  # record, which keeps what the audit began from.