principles 0.0.11 → 0.1.1

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/lib/principles/controllers/answer.rb +2 -2
  4. data/lib/principles/controllers/assessment.rb +19 -3
  5. data/lib/principles/controllers/audit.rb +14 -4
  6. data/lib/principles/controllers/full_audit_request.rb +16 -10
  7. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  8. data/lib/principles/controllers/member_addition.rb +4 -1
  9. data/lib/principles/controllers/member_problems_report.rb +7 -6
  10. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  11. data/lib/principles/controllers/running_tool.rb +22 -5
  12. data/lib/principles/controllers/survey.rb +3 -2
  13. data/lib/principles/data/candidate_files_found.rb +6 -4
  14. data/lib/principles/data/command-steps.json +17 -17
  15. data/lib/principles/data/committed_texts.rb +58 -0
  16. data/lib/principles/data/first_parent_log.rb +50 -10
  17. data/lib/principles/data/json_text.rb +5 -1
  18. data/lib/principles/data/parser_message.rb +61 -0
  19. data/lib/principles/data/project_files.rb +4 -2
  20. data/lib/principles/data/repository.rb +29 -37
  21. data/lib/principles/data/running_version.rb +1 -1
  22. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  23. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  24. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  25. data/lib/principles/data/working_tree_changes.rb +62 -0
  26. data/lib/principles/invocation_options.rb +1 -1
  27. data/lib/principles/launch.rb +5 -3
  28. data/lib/principles/models/after_commit_input.rb +1 -0
  29. data/lib/principles/models/assessment_basis.rb +1 -1
  30. data/lib/principles/models/audit.rb +23 -3
  31. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  32. data/lib/principles/models/audit_record.rb +5 -14
  33. data/lib/principles/models/audit_records.rb +1 -1
  34. data/lib/principles/models/audited_member_lines.rb +1 -1
  35. data/lib/principles/models/candidate_files.rb +1 -1
  36. data/lib/principles/models/candidate_inventory.rb +19 -9
  37. data/lib/principles/models/candidate_outline.rb +1 -1
  38. data/lib/principles/models/changed_regions.rb +1 -1
  39. data/lib/principles/models/command_steps.rb +1 -2
  40. data/lib/principles/models/correction_basis.rb +1 -1
  41. data/lib/principles/models/declared_map_changes.rb +1 -2
  42. data/lib/principles/models/finding_decision.rb +84 -0
  43. data/lib/principles/models/finding_write_ups.rb +2 -1
  44. data/lib/principles/models/first_full_audit.rb +1 -0
  45. data/lib/principles/models/frontmatter_fields.rb +1 -1
  46. data/lib/principles/models/guidance_search_path.rb +1 -1
  47. data/lib/principles/models/guidance_search_paths.rb +5 -1
  48. data/lib/principles/models/head_moves.rb +1 -0
  49. data/lib/principles/models/ignored_candidates.rb +1 -1
  50. data/lib/principles/models/instruction_named.rb +1 -1
  51. data/lib/principles/models/json_path_query.rb +1 -1
  52. data/lib/principles/models/json_path_selectors.rb +1 -1
  53. data/lib/principles/models/json_path_string.rb +1 -1
  54. data/lib/principles/models/last_completed_revision.rb +1 -1
  55. data/lib/principles/models/line_diff.rb +1 -1
  56. data/lib/principles/models/line_span.rb +1 -1
  57. data/lib/principles/models/loading_scope.rb +1 -0
  58. data/lib/principles/models/located_text.rb +1 -1
  59. data/lib/principles/models/map_change.rb +66 -0
  60. data/lib/principles/models/mapped_principles.rb +4 -0
  61. data/lib/principles/models/markdown_file.rb +22 -1
  62. data/lib/principles/models/member.rb +1 -1
  63. data/lib/principles/models/member_elsewhere.rb +1 -1
  64. data/lib/principles/models/member_file.rb +6 -1
  65. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  66. data/lib/principles/models/member_history.rb +1 -1
  67. data/lib/principles/models/member_lines.rb +1 -1
  68. data/lib/principles/models/member_loading_scopes.rb +1 -0
  69. data/lib/principles/models/member_mapping_run.rb +4 -4
  70. data/lib/principles/models/member_moves.rb +1 -2
  71. data/lib/principles/models/member_problems.rb +5 -1
  72. data/lib/principles/models/member_region.rb +1 -1
  73. data/lib/principles/models/members_elsewhere.rb +1 -1
  74. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  75. data/lib/principles/models/members_sharing_lines.rb +1 -1
  76. data/lib/principles/models/misspelt_member_id.rb +1 -1
  77. data/lib/principles/models/open_finding.rb +4 -3
  78. data/lib/principles/models/open_findings_decision.rb +124 -0
  79. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  80. data/lib/principles/models/other_templates_placeholders.rb +1 -0
  81. data/lib/principles/models/outline_budget.rb +1 -1
  82. data/lib/principles/models/outline_group.rb +1 -1
  83. data/lib/principles/models/outline_section.rb +1 -1
  84. data/lib/principles/models/part_named.rb +1 -1
  85. data/lib/principles/models/plain_text_file.rb +1 -1
  86. data/lib/principles/models/principle_history.rb +3 -3
  87. data/lib/principles/models/principle_members.rb +1 -1
  88. data/lib/principles/models/problem_report.rb +26 -3
  89. data/lib/principles/models/project.rb +8 -3
  90. data/lib/principles/models/project_at_commit.rb +9 -19
  91. data/lib/principles/models/project_history.rb +8 -0
  92. data/lib/principles/models/prose_line.rb +36 -0
  93. data/lib/principles/models/record_format.rb +17 -4
  94. data/lib/principles/models/recorded_finding.rb +47 -7
  95. data/lib/principles/models/recorded_findings.rb +7 -7
  96. data/lib/principles/models/recorded_hashes.rb +1 -1
  97. data/lib/principles/models/recorded_members.rb +6 -8
  98. data/lib/principles/models/report_hooks.rb +1 -0
  99. data/lib/principles/models/request_id.rb +2 -2
  100. data/lib/principles/models/sent_answer.rb +1 -0
  101. data/lib/principles/models/session_start_input.rb +1 -0
  102. data/lib/principles/models/stale_request.rb +22 -8
  103. data/lib/principles/models/submitted_answer.rb +1 -1
  104. data/lib/principles/models/survey_search_paths.rb +13 -5
  105. data/lib/principles/models/text_within.rb +1 -1
  106. data/lib/principles/models/unchecked_members.rb +1 -0
  107. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  108. data/lib/principles/models/unknown_principle.rb +1 -0
  109. data/lib/principles/models/write_up_opening.rb +5 -31
  110. data/lib/principles/models/write_up_pointer.rb +2 -1
  111. data/lib/principles/start_audit_options.rb +25 -18
  112. data/lib/principles/version.rb +2 -2
  113. data/lib/principles/views/acknowledgement_result.rb +12 -9
  114. data/lib/principles/views/added_member.rb +10 -1
  115. data/lib/principles/views/answer_in_a_file.rb +16 -4
  116. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  117. data/lib/principles/views/assessment_request.rb +2 -26
  118. data/lib/principles/views/audit_result.rb +15 -6
  119. data/lib/principles/views/candidate_files_result.rb +24 -13
  120. data/lib/principles/views/context_parts.rb +40 -9
  121. data/lib/principles/views/correction_request.rb +8 -5
  122. data/lib/principles/views/first_audit_brief.rb +2 -1
  123. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  124. data/lib/principles/views/invocation.rb +14 -4
  125. data/lib/principles/views/json_on_one_line.rb +18 -0
  126. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  127. data/lib/principles/views/problem_facts.rb +46 -0
  128. data/lib/principles/views/problem_result.rb +42 -31
  129. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  130. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  131. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  132. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  133. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  134. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +1 -1
  135. data/lib/principles/views/prompts/find-a-principle-to-map/ask-in-this-order-after-the-table.md +1 -0
  136. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner.md +1 -0
  137. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -2
  138. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +3 -2
  139. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +2 -2
  140. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +2 -2
  141. data/lib/principles/views/prompts/find-a-principle-to-map/group-rules-into-principles.md +3 -0
  142. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  143. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  144. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  145. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  146. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  147. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  148. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  149. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  150. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  151. metadata +20 -9
  152. data/lib/principles/controllers/repoint.rb +0 -67
  153. data/lib/principles/models/repoint.rb +0 -125
  154. data/lib/principles/models/write_up_repoint.rb +0 -38
  155. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +0 -1
  156. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  157. data/lib/principles/views/repoint_result.rb +0 -80
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "answer_head"
5
+ require_relative "assessment_answer_guide"
5
6
  require_relative "assessed_members"
6
7
  require_relative "context_parts"
7
8
  require_relative "instruction"
@@ -142,7 +143,7 @@ module Principles
142
143
  #: () -> Array[Instruction | GuideInstruction]
143
144
  def instructions
144
145
  [question, judge_because_instruction,
145
- carried_forward_instruction, mapped_elsewhere_instruction, answer_guide]
146
+ carried_forward_instruction, mapped_elsewhere_instruction, AssessmentAnswerGuide.new(@members).instruction]
146
147
  end
147
148
 
148
149
  # The question, defining observed only when a member is judged afresh, whose delivery it guides.
@@ -176,31 +177,6 @@ module Principles
176
177
  end
177
178
  end
178
179
 
179
- # The answer guide, showing check_result's fields only when a member has a check, so an audit
180
- # with no checks costs no more context than before, and delivery's shapes only when a member is judged
181
- # afresh, since a carried member's marker gives none. check_result's limits say how to review a check
182
- # before running it only when a check is new or changed, as that check's own template says too.
183
- #: () -> GuideInstruction
184
- def answer_guide
185
- guide = Prompts.data("assess-every-member/answer-guide")
186
- narrowed = @members.check_to_review? ? {} : guide.slice("check_result")
187
- GuideInstruction.new("answer_guide", guide.merge("check_result" => reviewed(guide.fetch("check_result"))),
188
- narrowed:) do |entry|
189
- case entry
190
- when "check_result" then @members.checked?
191
- when "member_delivery" then @members.judged_afresh?
192
- else true
193
- end
194
- end
195
- end
196
-
197
- # check_result's guide entry whole, its limits ending with how to review a new or changed check before running it.
198
- #: (Hash[String, untyped]) -> Hash[String, untyped]
199
- def reviewed(check_result)
200
- review = Prompts.text("assess-every-member/review-a-new-or-changed-check-before-running-it")
201
- check_result.merge("limits" => "#{check_result.fetch("limits")} #{review}")
202
- end
203
-
204
180
  # How to answer when the request carries some members' last assessments forward; nothing when it carries none.
205
181
  # What a compact carried member shows, and what prints one whole, only when one prints compactly.
206
182
  #: () -> Instruction
@@ -11,6 +11,7 @@ require_relative "invocation"
11
11
  require_relative "prior_finding_decisions_result"
12
12
  require_relative "prompts"
13
13
  require_relative "report_hooks_offer"
14
+ require_relative "shell_word"
14
15
  require_relative "trimmed_instructions_note"
15
16
  require_relative "../prose_list"
16
17
 
@@ -95,11 +96,10 @@ module Principles
95
96
 
96
97
  # start-audit: the assessment request, as a judgement to answer under its request id, its context naming the
97
98
  # instructions it prints only in part and the flag that prints one whole, so a trimmed field is not taken for
98
- # the whole, without the command the agent just ran. Its head names the command listing its parts, so a long
99
- # request is read in parts rather than paged by script.
100
- #: (AssessmentRequest) -> Hash[String, untyped]
101
- def assessment_request(request)
102
- output = judgement("assessment", request, { "read_in_parts" => read_in_parts(request.principle_id) },
99
+ # the whole, without the command the agent just ran, after its head, which sizes each part as part_bytes.
100
+ #: (AssessmentRequest, part_bytes: Hash[String, Integer]) -> Hash[String, untyped]
101
+ def assessment_request(request, part_bytes:)
102
+ output = judgement("assessment", request, assessment_head(request.principle_id, part_bytes),
103
103
  to_fill: { "response_template" => request.template })
104
104
  note = TrimmedInstructionsNote.new(request.trimmed_instruction_fields).to_h
105
105
  fill = AnswerInAFile.new(@invocation).assessment(request.principle_id, request_id: request.request_id)
@@ -182,6 +182,15 @@ module Principles
182
182
  result.merge(field => facts, "next_action" => [judge, result["next_action"]].compact.join("\n"))
183
183
  end
184
184
 
185
+ # What a full audit's request of principle_id prints before its context: the command listing its parts, so a
186
+ # long request is read in parts rather than paged by script, and part_bytes, each part's bytes by its name as a
187
+ # shell reads it, as the index prints them, so the agent sizes its reads without running a script for them.
188
+ #: (String, Hash[String, Integer]) -> Hash[String, untyped]
189
+ def assessment_head(principle_id, part_bytes)
190
+ { "read_in_parts" => read_in_parts(principle_id),
191
+ "part_bytes" => part_bytes.transform_keys { ShellWord.new(it).to_s } }
192
+ end
193
+
185
194
  # How to read principle_id's full-audit request in parts: the command listing them, and the flag printing one.
186
195
  #: (String) -> String
187
196
  def read_in_parts(principle_id)
@@ -192,7 +201,7 @@ module Principles
192
201
  # request as a judgement to answer in phase, under its id, which its template's head also gives, with any
193
202
  # opening fields after the phase and before the context, and to_fill, the answer to fill when this request
194
203
  # prints it, after the context.
195
- #: (String, AssessmentRequest | CorrectionRequest, ?Hash[String, String], ?to_fill: Hash[String, untyped])
204
+ #: (String, AssessmentRequest | CorrectionRequest, ?Hash[String, untyped], ?to_fill: Hash[String, untyped])
196
205
  #| -> Hash[String, untyped]
197
206
  def judgement(phase, request, opening = {}, to_fill: {})
198
207
  { "status" => "agent_judgement_required", "request_id" => request.request_id, "phase" => phase, **opening,
@@ -33,12 +33,15 @@ module Principles
33
33
  #: () -> Integer?
34
34
  def range_outlines_bytes = @inventory["range_outlines_bytes"]
35
35
 
36
+ # conventional says whether the survey looked in the places hosts load by convention, as it does
37
+ # unless --only narrowed it to its globs' matches.
36
38
  #: (inventory: Hash[String, untyped], untracked: Array[String]?,
37
- #| owner_asks: Hash[String, Array[String]]) -> void
38
- def initialize(inventory:, untracked:, owner_asks:)
39
+ #| owner_asks: Hash[String, Array[String]], ?conventional: bool) -> void
40
+ def initialize(inventory:, untracked:, owner_asks:, conventional: true)
39
41
  @inventory = inventory
40
42
  @untracked = untracked
41
43
  @owner_asks = owner_asks
44
+ @conventional = conventional
42
45
  freeze
43
46
  end
44
47
 
@@ -47,8 +50,10 @@ module Principles
47
50
  #: () -> Hash[String, untyped]
48
51
  def listed
49
52
  files = @inventory.fetch("files").map { |file| file.slice(*PRINTED_FILE_FIELDS) }
50
- listed = @inventory.merge("files" => files,
51
- "scope" => Prompts.text("find-a-principle-to-map/where-the-inventory-looks"))
53
+ scope = if @conventional then Prompts.text("find-a-principle-to-map/where-the-inventory-looks")
54
+ else Prompts.text("find-a-principle-to-map/where-a-survey-with-only-looks")
55
+ end
56
+ listed = @inventory.merge("files" => files, "scope" => scope)
52
57
  @untracked ? listed.merge("untracked" => @untracked) : listed
53
58
  end
54
59
  end
@@ -106,18 +111,24 @@ module Principles
106
111
  "To add a member to an existing principle: #{add}\nTo map a distinct principle: #{create}"
107
112
  end
108
113
 
109
- # The survey, leaving out files possibly test data, and when outlines were cut or left out how to read them, then
110
- # one item per list to ask the owner about after the table.
114
+ # The survey and how rules group into principles, leaving out files possibly test data, and when outlines were cut
115
+ # or left out how to read them, then what to ask after the table, in order: the choice, where else guidance is
116
+ # kept, and the owner about each list that names a file.
111
117
  #: (Found, survey: String, choice: String) -> String
112
118
  def principle_question(found, survey:, choice:)
113
119
  owner_asks = found.owner_asks
114
- asks = owner_asks.map { |key, paths| "- #{owner_ask(key, named: inline(paths))}" }
115
- [survey, *left_out_of_the_survey(owner_asks),
116
- *budget_notes(found),
117
- choice,
118
- Prompts.text("find-a-principle-to-map/ask-about-other-guidance-search-paths"),
119
- *([Prompts.text("find-a-principle-to-map/ask-the-owner-after-the-table"), *asks].join("\n") if asks.any?)]
120
- .join("\n\n")
120
+ owner = Prompts.text("find-a-principle-to-map/ask-the-owner")
121
+ asks = [choice, Prompts.text("find-a-principle-to-map/ask-about-other-guidance-search-paths"),
122
+ *owner_asks.map { |key, paths| "#{owner} #{owner_ask(key, named: inline(paths))}" }]
123
+ [survey, Prompts.text("find-a-principle-to-map/group-rules-into-principles"),
124
+ *left_out_of_the_survey(owner_asks), *budget_notes(found), in_order(asks)].join("\n\n")
125
+ end
126
+
127
+ # asks as one numbered list, after the line saying to ask them in that order once the table is shown.
128
+ #: (Array[String]) -> String
129
+ def in_order(asks)
130
+ [Prompts.text("find-a-principle-to-map/ask-in-this-order-after-the-table"),
131
+ *asks.each_with_index.map { |ask, index| "#{index + 1}. #{ask}" }].join("\n")
121
132
  end
122
133
 
123
134
  # How to read what the budget cut: a cut section back by its lines, and a file whose outline was left out.
@@ -1,6 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../prose_list"
4
5
  require_relative "member_lines_beside_text"
5
6
  require_relative "printed_json"
6
7
 
@@ -20,10 +21,6 @@ module Principles
20
21
  # The part holding the answer to fill, as the request prints it beside its context.
21
22
  TEMPLATE = "response_template" #: String
22
23
 
23
- # What --part prints for an optional part the request leaves out, holding nothing for it.
24
- EMPTY = { "part_empty" => "Nothing to list for this request; " \
25
- "the answer needs nothing for it." }.freeze #: Hash[String, String]
26
-
27
24
  # instruction_fields is each field the context prints an instruction under, in order. template is the answer to
28
25
  # fill, as the request prints it. texts is each member's lines now, by id, one string each, which its part
29
26
  # prints and the whole request does not. optional names each part the context lists only when it holds something.
@@ -54,12 +51,16 @@ module Principles
54
51
  #: () -> Array[String]
55
52
  def left_out = @optional - @context.keys
56
53
 
54
+ # Each part's name, as names lists it, with the bytes --part prints of its value.
55
+ #: () -> Hash[String, Integer]
56
+ def part_bytes = names.to_h { [it, bytes(shown(it))] }
57
+
57
58
  # The part name, under its key, as the context prints it; a member's entry alone under members, with its text
58
59
  # when given, its id read after the one prefix, so an id with a slash, or starting members/, is read whole.
59
60
  #: (String) -> Hash[String, untyped]
60
61
  def shown(name)
61
62
  return { INDEX => index } if name == INDEX
62
- return EMPTY if left_out.include?(name)
63
+ return empty([name]) if left_out.include?(name)
63
64
  return @template if name == TEMPLATE
64
65
  return { name => @context.fetch(name) } unless name.start_with?(MEMBER)
65
66
 
@@ -67,16 +68,46 @@ module Principles
67
68
  { "members" => members.select { it.fetch("id") == id }.map { with_text(it) } }
68
69
  end
69
70
 
71
+ # The parts names, each as shown prints it, printed together: each member's in one members list and each empty
72
+ # one named in one part_empty, in the order given, where merging the parts one by one leaves the last alone.
73
+ #: (Array[String]) -> Hash[String, untyped]
74
+ def shown_together(names)
75
+ together = names.reduce({}) { |all, name| all.merge(shown(name)) } #: Hash[String, untyped]
76
+ with_every_empty(with_every_member(together, names), names)
77
+ end
78
+
70
79
  private
71
80
 
81
+ # together with each member names names in one members list; together as it is when names name no member.
82
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
83
+ def with_every_member(together, names)
84
+ return together unless together.key?("members")
85
+
86
+ together.merge("members" => names.flat_map { shown(it).fetch("members", []) })
87
+ end
88
+
89
+ # together with one part_empty naming every empty part names; together as it is when names name none.
90
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
91
+ def with_every_empty(together, names)
92
+ empty_named = names & left_out
93
+ empty_named.empty? ? together : together.merge(empty(empty_named))
94
+ end
95
+
96
+ # What --part prints for the optional parts names, which the request leaves out for holding nothing, naming each
97
+ # in the order given, so the agent knows which of the parts it asked for were empty.
98
+ #: (Array[String]) -> Hash[String, String]
99
+ def empty(names)
100
+ { "part_empty" => "Nothing to list for #{ProseList.new(names)} in this request; " \
101
+ "the answer needs nothing for #{names.one? ? "it" : "them"}." }
102
+ end
103
+
72
104
  # Each part with the bytes --part prints of its value, and each member with whether this audit judges it, and
73
105
  # why when the request says, or carries its last assessment forward.
74
106
  #: () -> Array[Hash[String, untyped]]
75
107
  def index
76
- names.map do |name|
77
- part = shown(name)
78
- entry = { "part" => name, "bytes" => bytes(part) }
79
- name.start_with?(MEMBER) ? entry.merge(judged(part.fetch("members").fetch(0))) : entry
108
+ part_bytes.map do |name, size|
109
+ entry = { "part" => name, "bytes" => size }
110
+ name.start_with?(MEMBER) ? entry.merge(judged(shown(name).fetch("members").fetch(0))) : entry
80
111
  end
81
112
  end
82
113
 
@@ -5,6 +5,7 @@ require_relative "answer_head"
5
5
  require_relative "answer_in_a_file"
6
6
  require_relative "invocation"
7
7
  require_relative "prompts"
8
+ require_relative "shell_word"
8
9
 
9
10
  module Principles
10
11
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -67,15 +68,17 @@ module Principles
67
68
  view.request(view.correction_request(self))
68
69
  end
69
70
 
70
- # How to save and fill the correction's answer after submitting the checked assessment, naming the command that
71
- # prints it alone rather than printing it here; keep its submit last.
71
+ # How to save and fill the correction's answer after submitting the checked assessment, to the file named in full
72
+ # that its submit names too, naming the command that prints it alone rather than printing it here; keep its
73
+ # submit last.
72
74
  #: (Hash[String, untyped], Invocation, String) -> Hash[String, untyped]
73
75
  def with_correction_to_fill(acceptable, invocation, answer_file)
74
76
  assessment_id = acceptable.fetch("request_id")
77
+ file = invocation.answer_file(request_id)
75
78
  save = "Once this answer is submitted with the last line's command, save the correction's answer it leads " \
76
- "to in a file outside the project, such as under $TMPDIR, from this command's output: " \
77
- "#{alone(assessment_id, answer_file, invocation)}\nFill only its dispositions, and submit it: " \
78
- "#{invocation.submit_answer(request_id)}"
79
+ "to in a file outside the project, at this full path, the same from every shell, from this command's " \
80
+ "output: #{alone(assessment_id, answer_file, invocation)} > #{ShellWord.new(file)}\nFill only its " \
81
+ "dispositions, and submit it: #{invocation.submit_answer(request_id, file:)}"
79
82
  acceptable.merge("correction_recovery" => recovery(invocation),
80
83
  "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
81
84
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "invocation"
5
5
  require_relative "prompts"
6
+ require_relative "shell_word"
6
7
 
7
8
  module Principles
8
9
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -25,7 +26,7 @@ module Principles
25
26
  def result(id)
26
27
  { "principle" => id,
27
28
  "brief" => Prompts.text("run-a-first-audit-in-the-background/follow-the-brief",
28
- id: id,
29
+ id: id, answer_file: ShellWord.new(@invocation.answer_file(id)).to_s,
29
30
  index: @invocation.in_project("start-audit", id, options: ["--part", "index"]),
30
31
  template: @invocation.in_project("start-audit", id, options: ["--as", "template"])),
31
32
  "wrote" => [] }
@@ -6,7 +6,8 @@ require_relative "invocation"
6
6
  module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
- # The recorded list and an immediate read-only survey after a guidance-search-path write.
9
+ # The recorded list and an immediate read-only survey after a guidance-search-path write: after an addition,
10
+ # of just the files the added glob matches, since the rest were surveyed before it.
10
11
  class GuidanceSearchPathsResult
11
12
  #: (Invocation) -> void
12
13
  def initialize(invocation)
@@ -14,12 +15,18 @@ module Principles
14
15
  freeze
15
16
  end
16
17
 
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")
18
+ #: (status: String, globs: Array[String], wrote: Array[String], added: String?) -> Hash[String, untyped]
19
+ def result(status:, globs:, wrote:, added:)
20
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}" }
21
+ "next_action" => "Commit changed configuration.\n#{survey(added)}" }
22
+ end
23
+
24
+ private
25
+
26
+ #: (String?) -> String
27
+ def survey(added)
28
+ survey = @invocation.in_project("list-candidate-files", options: added ? ["--only", added] : [])
29
+ added ? "Survey just the files it matches: #{survey}" : "Survey again using the saved search paths: #{survey}"
23
30
  end
24
31
  end
25
32
  end
@@ -15,11 +15,13 @@ module Principles
15
15
  #: String
16
16
  attr_reader :project
17
17
 
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)
18
+ # named says whether each command names the project; without_project leaves it out. temp_directory is the
19
+ # temporary folder the running tool was given, where a printed next step saves an answer.
20
+ #: (executable: String, project: String, temp_directory: String, ?named: bool) -> void
21
+ def initialize(executable:, project:, temp_directory:, named: true)
21
22
  @executable = executable
22
23
  @project = project
24
+ @temp_directory = temp_directory
23
25
  @named = named
24
26
  freeze
25
27
  end
@@ -27,7 +29,9 @@ module Principles
27
29
  # The same invocation, its commands leaving out --project, for output that names the project once and whose
28
30
  # commands run from there, as list-member-problems --short's stderr does.
29
31
  #: () -> Invocation
30
- def without_project = Invocation.new(executable: @executable, project: @project, named: false)
32
+ def without_project
33
+ Invocation.new(executable: @executable, project: @project, temp_directory: @temp_directory, named: false)
34
+ end
31
35
 
32
36
  # Whether each command names the project.
33
37
  #: () -> bool
@@ -55,6 +59,12 @@ module Principles
55
59
  in_project("submit-answer", request_id, options: ["--file", file])
56
60
  end
57
61
 
62
+ # The file to save the answer name names in, a request id or a principle id, by its full path in the temporary
63
+ # folder, so every shell that runs the printed commands names the same file: a sandboxed and an unsandboxed one
64
+ # read $TMPDIR as different folders.
65
+ #: (String) -> String
66
+ def answer_file(name) = "#{@temp_directory.chomp("/")}/principles-#{name}-answer.json"
67
+
58
68
  # The same command, its values given as one list, as a refusal's repair command holds them.
59
69
  #: (String, Array[String], ?options: Array[String], ?usage: String?) -> String
60
70
  def listed_in_project(command, values, options: [], usage: nil)
@@ -0,0 +1,18 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
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
+ # An object that prints compact on one line inside a result printed a field a line, and reads as the hash it holds
10
+ # everywhere else. An answer guide's example is one: the agent copies it whole into its answer, and printed a field
11
+ # a line and unindented it ran several levels deep, where a key after closing brackets could not be placed.
12
+ class JsonOnOneLine < Hash
13
+ # The object compact, whatever layout the result around it prints in.
14
+ #: (*untyped) -> String
15
+ def to_json(*) = JSON.generate(to_h)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_in_a_file"
5
+ require_relative "invocation"
6
+ require_relative "prompts"
7
+
8
+ module Principles
9
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
+ module Views
11
+ # A decision on a principle's open findings between full audits: its request and its result.
12
+ class OpenFindingsDecisionResult
13
+ #: (Invocation) -> void
14
+ def initialize(invocation)
15
+ @invocation = invocation
16
+ freeze
17
+ end
18
+
19
+ # The request for a decision on any of findings, the open findings, each with its recorded_at and what
20
+ # list-open-findings says of its write-up, whose template names each finding alone, so one left as printed
21
+ # changes nothing, under fields, each field a decision may give with its meaning, printed at its head.
22
+ #: (request_id: String, principle_id: String, revision: String?, findings: Array[Hash[String, untyped]],
23
+ #| fields: Hash[String, String]) -> Hash[String, untyped]
24
+ def decision_request(request_id:, principle_id:, revision:, findings:, fields:)
25
+ decisions = findings.map { |finding| { "finding_id" => finding["finding_id"] } }
26
+ { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "deciding",
27
+ "context" => { "principle_id" => principle_id, "findings" => findings,
28
+ "question" => Prompts.text("decide-open-findings/give-only-what-changed-of-each") },
29
+ "response_template" => { "request_id" => request_id, "basis" => { "revision" => revision },
30
+ "decision_fields" => fields, "decisions" => decisions },
31
+ "answer_with" => @invocation.submit_answer(request_id),
32
+ "next_action" => AnswerInAFile.new(@invocation).open_findings(principle_id, request_id:) }
33
+ end
34
+
35
+ # The decisions were accepted, changing the findings changed names, and file holds them; not_found_elsewhere
36
+ # is each other principle's open finding whose write-up cannot be found, as its principle and finding_id (T16).
37
+ #: (principle_id: String, file: String, changed: Array[String], not_found_elsewhere: Array[Hash[String, String]])
38
+ #| -> Hash[String, untyped]
39
+ def decided(principle_id:, file:, changed:, not_found_elsewhere:)
40
+ { "status" => "open_findings_decided", "principle_id" => principle_id, "changed" => changed,
41
+ "other_write_ups_not_found" => not_found_elsewhere, "files_to_commit" => [file],
42
+ "next_action" => "Commit #{file}. Then check each change as the session-start line will state it: " \
43
+ "#{@invocation.in_project("list-open-findings", principle_id, usage: "--lines")}" \
44
+ "#{elsewhere(not_found_elsewhere.map { it.fetch("principle") }.uniq)}" }
45
+ end
46
+
47
+ private
48
+
49
+ # The request that decides each other principle's open findings, one per line, or nothing when there is none.
50
+ #: (Array[String]) -> String
51
+ def elsewhere(principle_ids)
52
+ return "" if principle_ids.empty?
53
+
54
+ commands = principle_ids.map { |id| "#{@invocation.in_project("start-audit", id, usage: "--open-findings")}\n" }
55
+ "\nWrite-ups of other principles cannot be found either, listed under other_write_ups_not_found. " \
56
+ "Check each, and point it at its write-up with its own request:\n#{commands.join}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,46 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "record_waiting_on_an_upgrade"
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
+ # What list-member-problems' result says beside the report the models check, as plain values: the older files
10
+ # left unread, by principle the files to commit so its members with no baseline gain one, and those an audit of
11
+ # it refuses until they are committed, by the principles that acknowledge them together the changed members a
12
+ # one-member audit may judge, and each principle whose record a later copy wrote, whose members are not checked.
13
+ class ProblemFacts
14
+ #: Array[String]
15
+ attr_reader :not_read
16
+
17
+ #: Hash[String, Array[String]]
18
+ attr_reader :no_baseline_files
19
+
20
+ #: Hash[String, Array[String]]
21
+ attr_reader :audit_files
22
+
23
+ #: Hash[Array[String], Array[String]]
24
+ attr_reader :acknowledgeable
25
+
26
+ #: Array[RecordWaitingOnAnUpgrade]
27
+ attr_reader :waiting
28
+
29
+ #: (?not_read: Array[String], ?no_baseline_files: Hash[String, Array[String]],
30
+ #| ?audit_files: Hash[String, Array[String]], ?acknowledgeable: Hash[Array[String], Array[String]],
31
+ #| ?waiting: Array[RecordWaitingOnAnUpgrade]) -> void
32
+ def initialize(not_read: [], no_baseline_files: {}, audit_files: {}, acknowledgeable: {}, waiting: [])
33
+ @not_read = not_read
34
+ @no_baseline_files = no_baseline_files
35
+ @audit_files = audit_files
36
+ @acknowledgeable = acknowledgeable
37
+ @waiting = waiting
38
+ freeze
39
+ end
40
+
41
+ # The principles waiting on an upgrade, by id.
42
+ #: () -> Array[String]
43
+ def waits = @waiting.map(&:principle)
44
+ end
45
+ end
46
+ end
@@ -1,10 +1,12 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../prose_list"
4
5
  require_relative "invocation"
5
6
  require_relative "members_with_no_baseline"
6
7
  require_relative "maps_needing_members_or_audit"
7
8
  require_relative "principles_with_no_completed_audit"
9
+ require_relative "problem_facts"
8
10
  require_relative "record_waiting_on_an_upgrade"
9
11
 
10
12
  module Principles
@@ -28,29 +30,21 @@ module Principles
28
30
  freeze
29
31
  end
30
32
 
31
- # report holds "members", the changed members, and "counts"; not_read names older files left unread;
32
- # no_baseline_files names, by principle, the files to commit so its members with no baseline gain one.
33
- # acknowledgeable names, by the principles that acknowledge them together, the changed members a one-member
34
- # audit may judge.
35
- # waiting names each principle whose record a later copy wrote, whose members are not checked.
36
- #: (Hash[String, untyped], ?not_read: Array[String], ?no_baseline_files: Hash[String, Array[String]],
37
- #| ?acknowledgeable: Hash[Array[String], Array[String]], ?waiting: Array[RecordWaitingOnAnUpgrade])
38
- #| -> Hash[String, untyped]
39
- def checked(report, not_read: [], no_baseline_files: {}, acknowledgeable: {}, waiting: [])
40
- checked_naming_commands(report, not_read:, no_baseline_files:, acknowledgeable:, waiting:).first
33
+ # report holds "members", the changed members, and "counts"; facts what the result says beside it.
34
+ #: (Hash[String, untyped], ?ProblemFacts) -> Hash[String, untyped]
35
+ def checked(report, facts = ProblemFacts.new)
36
+ checked_naming_commands(report, facts).first
41
37
  end
42
38
 
43
39
  # The same result, and whether its next_action names a command, before which --short names the project once,
44
40
  # so no view reads the action's text to find one.
45
- #: (Hash[String, untyped], ?not_read: Array[String], ?no_baseline_files: Hash[String, Array[String]],
46
- #| ?acknowledgeable: Hash[Array[String], Array[String]], ?waiting: Array[RecordWaitingOnAnUpgrade])
47
- #| -> [Hash[String, untyped], bool]
48
- def checked_naming_commands(report, not_read: [], no_baseline_files: {}, acknowledgeable: {}, waiting: [])
49
- unless not_read.empty?
50
- report = report.merge("not_read" => not_read.map { |file| { "file" => file, "because" => OLDER_STATE } })
41
+ #: (Hash[String, untyped], ?ProblemFacts) -> [Hash[String, untyped], bool]
42
+ def checked_naming_commands(report, facts = ProblemFacts.new)
43
+ unless facts.not_read.empty?
44
+ report = report.merge("not_read" => facts.not_read.map { { "file" => it, "because" => OLDER_STATE } })
51
45
  end
52
- report = report.merge("records_waiting_on_an_upgrade" => waiting.map(&:to_h)) unless waiting.empty?
53
- action, commands = next_action(report, no_baseline_files:, acknowledgeable:, waiting:)
46
+ report = report.merge("records_waiting_on_an_upgrade" => facts.waiting.map(&:to_h)) unless facts.waiting.empty?
47
+ action, commands = next_action(report, facts)
54
48
  [report.merge("next_action" => action), commands]
55
49
  end
56
50
 
@@ -78,23 +72,40 @@ module Principles
78
72
 
79
73
  private
80
74
 
81
- # What to do next for report, each kind of action on lines of its own, or NOTHING_CHANGED when none applies,
82
- # and whether it names a command: every changed, unaudited and mapping action does, a no-baseline one as it
83
- # says, and neither the mapping notice nor a waiting principle's update sentence does.
84
- #: (Hash[String, untyped], no_baseline_files: Hash[String, Array[String]],
85
- #| acknowledgeable: Hash[Array[String], Array[String]], waiting: Array[RecordWaitingOnAnUpgrade])
86
- #| -> [String, bool]
87
- def next_action(report, no_baseline_files:, acknowledgeable:, waiting:)
88
- waits = waiting.map(&:principle)
89
- mapping = MapsNeedingMembersOrAudit.new(@invocation, report: report, files_to_commit: no_baseline_files,
90
- waiting: waits)
91
- commanding = [changed_action(report, acknowledgeable, waits), unaudited_action(report, waits)].compact
92
- no_baseline = no_baseline_actions(report, no_baseline_files)
75
+ # What to do next for report, given facts, each kind of action on lines of its own, or NOTHING_CHANGED when
76
+ # none applies, and whether it names a command: every changed, unaudited and mapping action does, a no-baseline
77
+ # one as it says, and neither the mapping notice nor a waiting principle's update sentence does.
78
+ #: (Hash[String, untyped], ProblemFacts) -> [String, bool]
79
+ def next_action(report, facts)
80
+ mapping = MapsNeedingMembersOrAudit.new(@invocation, report: report, files_to_commit: facts.no_baseline_files,
81
+ waiting: facts.waits)
82
+ commanding = commanding_actions(report, facts)
83
+ no_baseline = no_baseline_actions(report, facts.no_baseline_files)
93
84
  action = [*commanding, mapping.notice, *no_baseline.map(&:to_s), *mapping.actions,
94
- *waiting.map(&:to_s)].compact.join("\n")
85
+ *facts.waiting.map(&:to_s)].compact.join("\n")
95
86
  [action.empty? ? NOTHING_CHANGED : action, names_a_command?(commanding, no_baseline, mapping)]
96
87
  end
97
88
 
89
+ # The actions for report that name a command each, given facts: the audits of changed members, after the
90
+ # files to commit before them, then the audits of members no audit has assessed.
91
+ #: (Hash[String, untyped], ProblemFacts) -> Array[String]
92
+ def commanding_actions(report, facts)
93
+ [commit_first(report, facts), changed_action(report, facts.acknowledgeable, facts.waits),
94
+ unaudited_action(report, facts.waits)].compact
95
+ end
96
+
97
+ # The line asking to commit, before the audits of report's changed members, the files facts names an audit of
98
+ # their principles refusing, but for principles waiting on an upgrade, whose audits wait.
99
+ #: (Hash[String, untyped], ProblemFacts) -> String?
100
+ def commit_first(report, facts)
101
+ audited = report.fetch("members").map { it.fetch("principle") }
102
+ files = facts.audit_files.slice(*audited).except(*facts.waits).values.flatten.uniq
103
+ return if files.empty?
104
+
105
+ "Commit #{ProseList.new(files)} first: an audit judges committed text, and start-audit refuses a file " \
106
+ "that differs from the last commit."
107
+ end
108
+
98
109
  # Whether any of the actions that may name a command does.
99
110
  #: (Array[String], Array[MembersWithNoBaseline], MapsNeedingMembersOrAudit) -> bool
100
111
  def names_a_command?(commanding, no_baseline, mapping)
@@ -1,4 +1,4 @@
1
- Save the answer alone in a file outside the project, such as under $TMPDIR: %{save} > FILE
1
+ Save the answer alone in a file outside the project, at this full path, the same from every shell: %{save}
2
2
 
3
3
  Fill %{what} with your own file-edit tool, not a shell heredoc; JSON escapes only a double quote, a backslash and a line
4
4
  break, as \", \\ and \n, never an apostrophe.
@@ -1 +1,2 @@
1
- List this request's parts with their bytes, then print one alone with `--part NAME`: %{index}
1
+ `part_bytes` sizes each part below; print one alone with `--part NAME`, or list them with whether this audit judges
2
+ each member and how to answer: %{index}
@@ -0,0 +1,6 @@
1
+ Each open finding in `findings` is as list-open-findings prints it. For each finding you decide, add to its entry in
2
+ `decisions` only the fields that change, as the template's `decision_fields` names them, each with a one-line
3
+ `reason`. A field left out keeps its value, so an entry left as printed changes nothing. Closing a finding as resolved
4
+ or withdrawn judges the problem against the text now, which is a full audit's work: record an owner's ruling that there
5
+ is no problem as `accepted`, with that reason, for the next full audit to withdraw. That audit sees each change under
6
+ `changed_since_audit`. Do not edit the audit record by hand: nothing would check the change.