principles 0.0.10 → 0.1.0

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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +0 -2
  4. data/lib/principles/controllers/acknowledgement.rb +11 -4
  5. data/lib/principles/controllers/acknowledgements.rb +4 -4
  6. data/lib/principles/controllers/answer.rb +2 -2
  7. data/lib/principles/controllers/assessment.rb +20 -4
  8. data/lib/principles/controllers/audit.rb +16 -5
  9. data/lib/principles/controllers/broken_member_repairs.rb +60 -0
  10. data/lib/principles/controllers/command.rb +8 -30
  11. data/lib/principles/controllers/correction.rb +7 -5
  12. data/lib/principles/controllers/full_audit_request.rb +44 -22
  13. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  14. data/lib/principles/controllers/inventory.rb +3 -3
  15. data/lib/principles/controllers/member_acknowledgement.rb +5 -5
  16. data/lib/principles/controllers/member_addition.rb +5 -2
  17. data/lib/principles/controllers/member_entries.rb +1 -1
  18. data/lib/principles/controllers/member_problems_report.rb +11 -7
  19. data/lib/principles/controllers/members_to_assess.rb +1 -1
  20. data/lib/principles/controllers/meta_principle_setup.rb +4 -3
  21. data/lib/principles/controllers/open_correction.rb +3 -3
  22. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  23. data/lib/principles/controllers/running_tool.rb +22 -5
  24. data/lib/principles/controllers/survey.rb +3 -2
  25. data/lib/principles/data/candidate_files_found.rb +6 -4
  26. data/lib/principles/data/command-steps.json +20 -20
  27. data/lib/principles/data/json_text.rb +5 -1
  28. data/lib/principles/data/parser_message.rb +61 -0
  29. data/lib/principles/data/project_files.rb +4 -2
  30. data/lib/principles/data/repository.rb +4 -4
  31. data/lib/principles/data/running_version.rb +1 -1
  32. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  33. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  34. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  35. data/lib/principles/invocation_options.rb +4 -4
  36. data/lib/principles/launch.rb +5 -3
  37. data/lib/principles/models/acknowledgement.rb +1 -27
  38. data/lib/principles/models/acknowledgement_left_as_printed.rb +2 -1
  39. data/lib/principles/models/acknowledgement_placeholders.rb +48 -0
  40. data/lib/principles/models/after_commit_input.rb +1 -0
  41. data/lib/principles/models/assessment_answer.rb +2 -2
  42. data/lib/principles/models/assessment_basis.rb +1 -1
  43. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  44. data/lib/principles/models/audit.rb +24 -4
  45. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  46. data/lib/principles/models/audit_record.rb +5 -14
  47. data/lib/principles/models/audit_records.rb +2 -2
  48. data/lib/principles/models/audited_member_lines.rb +1 -1
  49. data/lib/principles/models/candidate_files.rb +1 -1
  50. data/lib/principles/models/candidate_inventory.rb +20 -10
  51. data/lib/principles/models/candidate_outline.rb +1 -1
  52. data/lib/principles/models/changed_regions.rb +1 -1
  53. data/lib/principles/models/command_steps.rb +1 -2
  54. data/lib/principles/models/correction_basis.rb +1 -1
  55. data/lib/principles/models/declared_map_changes.rb +1 -2
  56. data/lib/principles/models/disposition.rb +12 -76
  57. data/lib/principles/models/disposition_placeholders.rb +48 -0
  58. data/lib/principles/models/disposition_text_field.rb +41 -0
  59. data/lib/principles/models/evidence_item.rb +1 -1
  60. data/lib/principles/models/finding_decision.rb +84 -0
  61. data/lib/principles/models/finding_write_ups.rb +2 -1
  62. data/lib/principles/models/first_full_audit.rb +1 -0
  63. data/lib/principles/models/fix_only_fields.rb +4 -3
  64. data/lib/principles/models/frontmatter_fields.rb +1 -1
  65. data/lib/principles/models/guidance_search_path.rb +1 -1
  66. data/lib/principles/models/guidance_search_paths.rb +5 -1
  67. data/lib/principles/models/head_moves.rb +1 -0
  68. data/lib/principles/models/ignored_candidates.rb +1 -1
  69. data/lib/principles/models/instruction_named.rb +1 -1
  70. data/lib/principles/models/json_path_query.rb +1 -1
  71. data/lib/principles/models/json_path_selectors.rb +1 -1
  72. data/lib/principles/models/json_path_string.rb +1 -1
  73. data/lib/principles/models/last_completed_revision.rb +1 -1
  74. data/lib/principles/models/line_diff.rb +1 -1
  75. data/lib/principles/models/line_span.rb +1 -1
  76. data/lib/principles/models/loading_scope.rb +1 -0
  77. data/lib/principles/models/located_text.rb +20 -12
  78. data/lib/principles/models/map_change.rb +66 -0
  79. data/lib/principles/models/mapped_principles.rb +4 -0
  80. data/lib/principles/models/markdown_file.rb +22 -1
  81. data/lib/principles/models/member.rb +1 -1
  82. data/lib/principles/models/member_assessments.rb +11 -4
  83. data/lib/principles/models/member_elsewhere.rb +1 -1
  84. data/lib/principles/models/member_file.rb +15 -13
  85. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  86. data/lib/principles/models/member_history.rb +1 -1
  87. data/lib/principles/models/member_lines.rb +1 -1
  88. data/lib/principles/models/member_loading_scopes.rb +1 -0
  89. data/lib/principles/models/member_mapping_run.rb +4 -4
  90. data/lib/principles/models/member_moves.rb +1 -2
  91. data/lib/principles/models/member_problems.rb +5 -1
  92. data/lib/principles/models/member_region.rb +1 -1
  93. data/lib/principles/models/member_repair_moves.rb +20 -4
  94. data/lib/principles/models/member_snapshots.rb +10 -10
  95. data/lib/principles/models/members_elsewhere.rb +1 -1
  96. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  97. data/lib/principles/models/members_sharing_lines.rb +2 -2
  98. data/lib/principles/models/misspelt_member_id.rb +10 -4
  99. data/lib/principles/models/named_placeholder.rb +32 -0
  100. data/lib/principles/models/open_finding.rb +4 -3
  101. data/lib/principles/models/open_findings_decision.rb +124 -0
  102. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  103. data/lib/principles/models/other_templates_placeholders.rb +26 -6
  104. data/lib/principles/models/outline_budget.rb +1 -1
  105. data/lib/principles/models/outline_group.rb +1 -1
  106. data/lib/principles/models/outline_section.rb +1 -1
  107. data/lib/principles/models/part_named.rb +1 -1
  108. data/lib/principles/models/plain_text_file.rb +1 -1
  109. data/lib/principles/models/principle_history.rb +5 -4
  110. data/lib/principles/models/principle_members.rb +1 -1
  111. data/lib/principles/models/problem_report.rb +13 -1
  112. data/lib/principles/models/project.rb +15 -16
  113. data/lib/principles/models/project_at_commit.rb +60 -0
  114. data/lib/principles/models/project_history.rb +10 -52
  115. data/lib/principles/models/prose_line.rb +36 -0
  116. data/lib/principles/models/record_format.rb +17 -4
  117. data/lib/principles/models/recorded_finding.rb +47 -7
  118. data/lib/principles/models/recorded_findings.rb +7 -7
  119. data/lib/principles/models/recorded_hashes.rb +1 -1
  120. data/lib/principles/models/recorded_members.rb +6 -8
  121. data/lib/principles/models/report_hooks.rb +1 -0
  122. data/lib/principles/models/request_id.rb +2 -2
  123. data/lib/principles/models/sent_answer.rb +5 -3
  124. data/lib/principles/models/session_start_input.rb +1 -0
  125. data/lib/principles/models/stale_request.rb +22 -8
  126. data/lib/principles/models/submitted_answer.rb +1 -1
  127. data/lib/principles/models/survey_search_paths.rb +13 -5
  128. data/lib/principles/models/template_placeholders.rb +22 -7
  129. data/lib/principles/models/text_size.rb +11 -3
  130. data/lib/principles/models/text_within.rb +1 -1
  131. data/lib/principles/models/unchecked_members.rb +1 -0
  132. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  133. data/lib/principles/models/unfinished_field.rb +34 -0
  134. data/lib/principles/models/unknown_principle.rb +1 -0
  135. data/lib/principles/models/write_up_opening.rb +5 -31
  136. data/lib/principles/models/write_up_pointer.rb +2 -1
  137. data/lib/principles/start_audit_options.rb +35 -20
  138. data/lib/principles/version.rb +2 -2
  139. data/lib/principles/views/acknowledged_result.rb +59 -0
  140. data/lib/principles/views/acknowledgement_result.rb +44 -51
  141. data/lib/principles/views/added_member.rb +10 -1
  142. data/lib/principles/views/answer_in_a_file.rb +65 -0
  143. data/lib/principles/views/assessed_members.rb +4 -2
  144. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  145. data/lib/principles/views/assessment_request.rb +2 -26
  146. data/lib/principles/views/audit_result.rb +18 -7
  147. data/lib/principles/views/candidate_files_result.rb +9 -4
  148. data/lib/principles/views/context_parts.rb +41 -10
  149. data/lib/principles/views/correction_request.rb +27 -18
  150. data/lib/principles/views/first_audit_brief.rb +2 -1
  151. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  152. data/lib/principles/views/invocation.rb +14 -4
  153. data/lib/principles/views/json_on_one_line.rb +18 -0
  154. data/lib/principles/views/member_repairs.rb +21 -5
  155. data/lib/principles/views/meta_principle_result.rb +26 -5
  156. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  157. data/lib/principles/views/parts_index_result.rb +8 -6
  158. data/lib/principles/views/principle_read_result.rb +2 -2
  159. data/lib/principles/views/problem_facts.rb +46 -0
  160. data/lib/principles/views/problem_lines.rb +8 -3
  161. data/lib/principles/views/problem_result.rb +53 -31
  162. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
  163. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  164. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  165. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  166. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  167. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  168. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  169. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  170. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  171. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-check.md +4 -3
  172. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +4 -3
  173. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  174. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +7 -8
  175. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  176. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +4 -3
  177. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member-check.md +4 -3
  178. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +4 -3
  179. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +13 -12
  180. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  181. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  182. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +12 -12
  183. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  184. data/lib/principles/views/prompts/start-a-session/act-on-the-changed-principles.md +2 -0
  185. data/lib/principles/views/prompts.rb +7 -4
  186. metadata +26 -8
  187. data/lib/principles/controllers/repoint.rb +0 -67
  188. data/lib/principles/models/repoint.rb +0 -125
  189. data/lib/principles/models/write_up_repoint.rb +0 -38
  190. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  191. data/lib/principles/views/repoint_result.rb +0 -80
@@ -4,21 +4,25 @@
4
4
  require_relative "../error"
5
5
  require_relative "../prose_list"
6
6
  require_relative "request_id"
7
+ require_relative "map_change"
7
8
 
8
9
  module Principles
9
10
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
11
  module Models
11
12
  # The refusal of an answer to one principle's audit request that no longer matches the project: its cause, the
12
- # members changed since the request's base commit when any are known, or else every input the request depends on,
13
- # and its repair: to answer the audit's open correction when members alone changed, or else to start again.
13
+ # members changed since the request's base commit when any are known, or how its map changed since then, or else
14
+ # every input the request depends on, and its repair: to answer the audit's open correction when members alone
15
+ # changed, or else to start again.
14
16
  class StaleRequest
15
17
  # principle_id is the principle audited; changed names the members whose text differs from the base commit's;
16
- # correction_open says whether the principle's record is open, its correction asked for and not yet answered.
17
- #: (String, ?Array[String], ?correction_open: bool) -> void
18
- def initialize(principle_id, changed = [], correction_open: false)
18
+ # correction_open says whether the principle's record is open, its correction asked for and not yet answered;
19
+ # map_change is how the map differs from the one the request was printed from, when that is known.
20
+ #: (String, ?Array[String], ?correction_open: bool, ?map_change: MapChange?) -> void
21
+ def initialize(principle_id, changed = [], correction_open: false, map_change: nil)
19
22
  @principle_id = principle_id
20
23
  @changed = changed
21
24
  @correction_open = correction_open
25
+ @map_change = map_change
22
26
  freeze
23
27
  end
24
28
 
@@ -29,13 +33,14 @@ module Principles
29
33
 
30
34
  private
31
35
 
32
- # The members changed since the base commit, which a request is printed only once they are committed; otherwise
33
- # every input that may have changed.
36
+ # The members changed since the base commit, which a request is printed only once they are committed; or else
37
+ # how its map changed since then; otherwise every input that may have changed.
34
38
  #: () -> String
35
39
  def cause
36
40
  unless @changed.empty?
37
41
  return "#{ProseList.new(@changed)} #{@changed.one? ? "has" : "have"} changed since its base commit"
38
42
  end
43
+ return "its map has changed since its base commit: #{@map_change}" if @map_change
39
44
 
40
45
  "its map, a member, the commit it was based on, or what says when a listed member loads and how big it is " \
41
46
  "(project settings, frontmatter or a listed file), has changed since it was printed, or another release " \
@@ -44,16 +49,25 @@ module Principles
44
49
 
45
50
  # To start the audit again; but while its correction is open and only members changed, that correction stays
46
51
  # answerable, since it is checked against the members at the base commit, so the repair names the command that
47
- # prints its answer again from the open record.
52
+ # prints its answer again from the open record; and after a map change alone, the answer stays worth keeping.
48
53
  #: () -> String
49
54
  def repair
50
55
  start = "#{Error::EXECUTABLE} start-audit #{@principle_id}"
56
+ return carried_over(start, @map_change) if @map_change && @changed.empty?
51
57
  return "Start the audit again and answer the new request: #{start}" unless @correction_open && @changed.any?
52
58
 
53
59
  "This audit's correction is still open, and fixing members leaves it current: answer it rather than start " \
54
60
  "again, saving its answer from this command's output, filling only its dispositions, and submitting it: " \
55
61
  "#{Error::EXECUTABLE} show-open-correction #{@principle_id}"
56
62
  end
63
+
64
+ # To carry the answer to a new request, judging again what map_change touched, or to undo map_change.
65
+ #: (String, MapChange) -> String
66
+ def carried_over(start, map_change)
67
+ "Keep this answer. To carry it to a new request, copy that request's request_id and basis into it, judge " \
68
+ "#{map_change.to_judge_again}, and submit it; or change the map back as it was at the base commit, " \
69
+ "commit it, and submit this answer unchanged.\nStart the new request: #{start}"
70
+ end
57
71
  end
58
72
  end
59
73
  end
@@ -5,7 +5,7 @@ require_relative "prior_findings"
5
5
  require_relative "request_id"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # An answer submitted to the request request_id names, its shape checked, with the prior findings a full
11
11
  # audit's request listed, which checking its head found, or nil for any other phase.
@@ -4,20 +4,28 @@
4
4
  require_relative "guidance_search_path"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # The project's recorded guidance search paths and this invocation's temporary selections, combined once.
10
+ # Selections made with only replace both the recorded paths and the places hosts load by convention, so a
11
+ # survey after a search path is added reads just the files it matches.
10
12
  class SurveySearchPaths
11
13
  #: Array[String]
12
14
  attr_reader :globs
13
15
 
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]
16
+ #: (recorded: Array[String], also: Array[String], ?only: Array[String]) -> void
17
+ def initialize(recorded:, also:, only: [])
18
+ @conventional = only.empty? #: bool
19
+ kept = @conventional ? recorded : [] #: Array[String]
20
+ @recorded = kept.map { |glob| GuidanceSearchPath.new(glob).glob }.uniq.freeze #: Array[String]
21
+ @globs = (@recorded | (also + only).map { |glob| GuidanceSearchPath.new(glob).glob }).freeze #: Array[String]
18
22
  freeze
19
23
  end
20
24
 
25
+ # Whether the survey lists the places hosts load by convention as well as these globs' matches.
26
+ #: () -> bool
27
+ def conventional? = @conventional
28
+
21
29
  # Saved provenance is distinct from all match counts; omit it when the project records no search paths.
22
30
  #: () -> Hash[String, untyped]
23
31
  def recorded_listing = @recorded.empty? ? {} : { "recorded_guidance_search_paths" => @recorded }
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "left_as_printed"
5
+ require_relative "named_placeholder"
5
6
  require_relative "refusal_before_shape"
6
7
 
7
8
  module Principles
@@ -16,26 +17,32 @@ module Principles
16
17
  # placeholders is the text printed in each field, by field name, or for a field that takes pointers, one pointer
17
18
  # whose fields hold that text, so the template shows their shape; empty_lists names the fields a template
18
19
  # may instead start as an empty list, which is not given either; also_printed, the other text a template
19
- # may print in a field, refused alike.
20
- #: (Hash[String, untyped], ?empty_lists: Array[String], ?also_printed: Hash[String, String]) -> void
20
+ # may print in a field, refused alike. A NamedPlaceholder in either prints with its slot, which the view fills
21
+ # with the id of the entry it prints in, and is left as printed for any id.
22
+ #: (Hash[String, untyped], ?empty_lists: Array[String], ?also_printed: Hash[String, untyped]) -> void
21
23
  def initialize(placeholders, empty_lists: [], also_printed: {})
22
24
  @placeholders = placeholders.freeze #: Hash[String, untyped]
23
25
  @empty_lists = empty_lists.freeze #: Array[String]
24
- @also_printed = also_printed.freeze #: Hash[String, String]
26
+ @also_printed = also_printed.freeze #: Hash[String, untyped]
25
27
  freeze
26
28
  end
27
29
 
28
30
  # The text printed in each field, with field's other text in place of its own.
29
31
  #: (String) -> Hash[String, untyped]
30
- def with_other_text_in(field) = @placeholders.merge(field => @also_printed.fetch(field))
32
+ def with_other_text_in(field) = to_h.merge(field => shown(@also_printed.fetch(field)))
33
+
34
+ # Each placeholder printed in its own field naming its entry's id; a field's other text is printed only by
35
+ # some of its requests, so another template leaving it is not read as this one's.
36
+ #: () -> Array[NamedPlaceholder]
37
+ def named = @placeholders.values.grep(NamedPlaceholder)
31
38
 
32
39
  # The text printed in each field, for the view that prints it.
33
40
  #: () -> Hash[String, untyped]
34
- def to_h = @placeholders
41
+ def to_h = @placeholders.transform_values { shown(it) }
35
42
 
36
43
  # The text printed in field.
37
44
  #: (String) -> untyped
38
- def fetch(field) = @placeholders.fetch(field)
45
+ def fetch(field) = shown(@placeholders.fetch(field))
39
46
 
40
47
  # fields, without each one left as its placeholder, which is not given.
41
48
  #: (Hash[String, untyped]) -> Hash[String, untyped]
@@ -65,7 +72,15 @@ module Principles
65
72
 
66
73
  # Whether value is a text the template prints in field.
67
74
  #: (String, untyped) -> bool
68
- def printed?(field, value) = [@placeholders[field], @also_printed[field]].compact.include?(value)
75
+ def printed?(field, value)
76
+ [@placeholders[field], @also_printed[field]].compact.any? do |printed|
77
+ printed.is_a?(NamedPlaceholder) ? printed.left?(value) : printed == value
78
+ end
79
+ end
80
+
81
+ # placeholder as the template prints it, a NamedPlaceholder with its slot.
82
+ #: (untyped) -> untyped
83
+ def shown(placeholder) = placeholder.is_a?(NamedPlaceholder) ? placeholder.slotted : placeholder
69
84
  end
70
85
  end
71
86
  end
@@ -13,13 +13,21 @@ module Principles
13
13
  freeze
14
14
  end
15
15
 
16
+ # Its bytes, none for a text not measured.
17
+ #: () -> Integer
18
+ def bytes = @text.to_s.bytesize
19
+
20
+ # Its tokens, estimated as characters / 4, rounded up; none for a text not measured.
21
+ #: () -> Integer
22
+ def estimated_tokens = (@text.to_s.length / 4.0).ceil
23
+
16
24
  # The size under fields' two names, its bytes then its tokens; empty when there is no text.
17
25
  #: ([String, String]) -> Hash[String, Integer]
18
26
  def under(fields)
19
- text = @text or return {}
27
+ return {} unless @text
20
28
 
21
- bytes, tokens = fields
22
- { bytes => text.bytesize, tokens => (text.length / 4.0).ceil }
29
+ bytes_field, tokens_field = fields
30
+ { bytes_field => bytes, tokens_field => estimated_tokens }
23
31
  end
24
32
  end
25
33
  end
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # A text cut to at most some characters, as a candidate file's outline prints its items, opening line and
8
8
  # description: whole when it fits, else back to a sentence end or a whole word.
@@ -8,6 +8,7 @@ require_relative "principle_members"
8
8
  require_relative "refusal_before_shape"
9
9
 
10
10
  module Principles
11
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
12
  module Models
12
13
  # The members of a principle that name no check, whose assessments take no check_result. An answer is read for
13
14
  # one before its shape is checked, since the shape would ask for the command such a check_result lacks, sending
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The project's files outside a principle's map that differ from the audit's base commit, as an assessment
8
8
  # request names them. A project with many untracked files would put every one into each request, so
@@ -0,0 +1,34 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_place"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # A field the agent left unfinished: empty, the template's placeholder, the answer guide's sample, or
10
+ # an action not one of the four. It says where it sits in the answer and what to write there, which one
11
+ # refusal lists beside every other.
12
+ class UnfinishedField
13
+ #: String
14
+ attr_reader :repair
15
+
16
+ #: (AnswerPlace, String, problem: String, repair: String) -> void
17
+ def initialize(place, name, problem:, repair:)
18
+ @place = place
19
+ @name = name
20
+ @problem = problem
21
+ @repair = repair
22
+ freeze
23
+ end
24
+
25
+ # Whose field it is, such as "Finding F1 reason".
26
+ #: () -> String
27
+ def to_s = "#{@place.subject} #{@name}"
28
+
29
+ # Its entry in the refusal's fields, as a malformed answer's are.
30
+ #: () -> Hash[String, String]
31
+ def field = { "pointer" => @place.pointer, "problem" => @problem }
32
+ end
33
+ end
34
+ end
@@ -5,6 +5,7 @@ require_relative "../error"
5
5
  require_relative "meta_principle"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # An absent principle id, whose repair creates an ordinary map or sets up the keeping principle.
10
11
  class UnknownPrinciple
@@ -1,6 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "prose_line"
5
+
4
6
  module Principles
5
7
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
8
  module Models
@@ -9,41 +11,13 @@ module Principles
9
11
  class WriteUpOpening
10
12
  # The longest opening printed whole; a longer one is cut and marked truncated.
11
13
  LIMIT = 200
12
- # A line that starts a new block, a list item or a heading, rather than continuing the paragraph before it.
13
- NEW_BLOCK = /\A(([-*+]|\d+[.)])\s|#)/
14
- # What a heading line starts with, a block of its own line.
15
- HEADING = "#"
16
14
  # The end of a sentence: its mark and any closing quotes or brackets, before a space or the end.
17
15
  SENTENCE_END = /[.!?]["')\]]*(?=\s|\z)/
18
16
 
19
- # One line of the file, as the opening reads it.
20
- class Line
21
- #: (String) -> void
22
- def initialize(text)
23
- @text = text
24
- freeze
25
- end
26
-
27
- # The line without its indentation or line break.
28
- #: () -> String
29
- def text = @text.strip
30
-
31
- #: () -> bool
32
- def blank? = text.empty?
33
-
34
- #: () -> bool
35
- def heading? = text.start_with?(HEADING)
36
-
37
- # Whether the line continues the paragraph before it: it is not blank and starts no new block. It keeps its
38
- # line break, which NEW_BLOCK's \s may match, so a bare "-" line still starts a list item.
39
- #: () -> bool
40
- def continues? = !blank? && !@text.lstrip.match?(NEW_BLOCK)
41
- end
42
-
43
17
  # lines are the file's lines; the region runs from index first up to, not including, index last.
44
18
  #: (lines: Array[String], first: Integer, last: Integer) -> void
45
19
  def initialize(lines:, first:, last:)
46
- @lines = lines.map { |each| Line.new(each) } #: Array[Line]
20
+ @lines = lines.map { |each| ProseLine.new(each) } #: Array[ProseLine]
47
21
  @first = first
48
22
  @last = last
49
23
  freeze
@@ -103,8 +77,8 @@ module Principles
103
77
  def closed?(text) = text.count("(") <= text.count(")")
104
78
 
105
79
  # The line at index, or a blank one past the file's end.
106
- #: (Integer) -> Line
107
- def line(index) = @lines[index] || Line.new("")
80
+ #: (Integer) -> ProseLine
81
+ def line(index) = @lines[index] || ProseLine.new("")
108
82
  end
109
83
  end
110
84
  end
@@ -25,7 +25,8 @@ module Principles
25
25
  #: () -> bool
26
26
  def starting_at? = !@locator.starting_at.nil?
27
27
 
28
- # The same heading or starting_at in the file at path, as a repoint checks git's match for a missing file.
28
+ # The same heading or starting_at in the file at path, as a decision on open findings checks git's match for a
29
+ # missing file.
29
30
  #: (String) -> WriteUpPointer
30
31
  def in_file(path) = WriteUpPointer.new(to_h.merge("path" => path))
31
32
 
@@ -4,36 +4,50 @@
4
4
  require_relative "invocation_options"
5
5
 
6
6
  module Principles
7
- # The options that choose which audit start-audit begins, --member and --write-ups, and the form --as prints
8
- # it in, and what is wrong with them as given, which CommandLine refuses as a usage error.
7
+ # The options that choose which audit start-audit begins, --member or --open-findings, and the form
8
+ # --as prints it in, and what is wrong with them as given, which CommandLine refuses as a usage error.
9
9
  class StartAuditOptions
10
+ # The part that prints the answer to fill bare, saved as it stands, so no other part may print beside it.
11
+ TEMPLATE_PART = "response_template" #: String
12
+ # Each option that starts an audit other than a full one, by its key among the options, and its flag.
13
+ AUDITS = { "member" => "--member",
14
+ "open_findings" => "--open-findings" }.freeze #: Hash[String, String]
15
+
10
16
  # several_ids is whether start-audit was given more than one principle id.
11
17
  #: (InvocationOptions, ?several_ids: bool) -> void
12
18
  def initialize(options, several_ids: false)
13
19
  @several_ids = several_ids
14
20
  @members = options.value("member") || [] #: Array[String]
15
- @member = !@members.empty? #: bool
16
- @write_ups = !options.value("write_ups").nil? #: bool
21
+ @audits = AUDITS.reject { |key, _| options.value(key).nil? }.values #: Array[String]
17
22
  @form = options.value("as") #: String?
18
23
  @instruction = !options.value("instruction").nil? #: bool
19
- @part = !options.value("part").nil? #: bool
24
+ @parts = options.value("part") || [] #: Array[String]
25
+ @part = !@parts.empty? #: bool
20
26
  freeze
21
27
  end
22
28
 
23
29
  # What is wrong with the options as given, or nil when they fit.
24
30
  #: () -> String?
25
31
  def fault
26
- return "--member and --write-ups each start a different audit; give one" if @member && @write_ups
27
-
28
- several_ids_fault || member_fault || part_fault || instruction_fault || form_fault
32
+ audits_fault || several_ids_fault || member_fault || part_fault || instruction_fault || form_fault
29
33
  end
30
34
 
31
35
  private
32
36
 
37
+ # Two of the options that each start a different audit; nil when at most one is given.
38
+ #: () -> String?
39
+ def audits_fault
40
+ "#{@audits.first(2).join(" and ")} each start a different audit; give one" if @audits.size > 1
41
+ end
42
+
43
+ # Whether flag, one of AUDITS, was given.
44
+ #: (String) -> bool
45
+ def audit?(flag) = @audits.include?(flag)
46
+
33
47
  # Several principle ids, which only an acknowledgement of members they each map spans; nil otherwise.
34
48
  #: () -> String?
35
49
  def several_ids_fault
36
- return unless @several_ids && !@member
50
+ return unless @several_ids && !audit?("--member")
37
51
 
38
52
  "several principle ids start one acknowledgement of the members they map, with --member; give one id for " \
39
53
  "any other audit"
@@ -53,7 +67,11 @@ module Principles
53
67
  return unless @part
54
68
 
55
69
  other = other_audit || ("the whole field --instruction prints" if @instruction)
56
- "--part prints one part of a full audit's request, not of #{other}" if other
70
+ return "--part prints one part of a full audit's request, not of #{other}" if other
71
+
72
+ return unless @parts.include?(TEMPLATE_PART) && @parts.size > 1
73
+
74
+ "--part #{TEMPLATE_PART} prints the bare answer to save as it stands; give it alone"
57
75
  end
58
76
 
59
77
  # --instruction prints one field of a full audit's request whole; nil when nothing beside it prints
@@ -66,29 +84,26 @@ module Principles
66
84
  "--instruction prints one field of a full audit's request, not of #{other}" if other
67
85
  end
68
86
 
69
- # What --as, --member or --write-ups prints instead of a full audit's request, which --part and --instruction each
70
- # read from; nil when none is given.
87
+ # What --as, --member or --open-findings prints instead of a full audit's request, which --part and --instruction
88
+ # each read from; nil when none is given.
71
89
  #: () -> String?
72
90
  def other_output
73
91
  @form ? "the answer --as template prints" : other_audit
74
92
  end
75
93
 
76
- # What --member or --write-ups starts instead of a full audit; nil when neither is given.
94
+ # What --member or --open-findings starts instead of a full audit; nil when neither is given.
77
95
  #: () -> String?
78
96
  def other_audit
79
- if @member then "the one-member audit --member starts"
80
- elsif @write_ups then "the repoint --write-ups starts"
97
+ if audit?("--member") then "the one-member audit --member starts"
98
+ elsif audit?("--open-findings") then "the decision --open-findings starts"
81
99
  end
82
100
  end
83
101
 
84
- # --as template prints a full audit's answer alone, or a one-member audit's, the one form
85
- # built so far; nil when it fits.
102
+ # --as template prints an audit's answer alone, the one form built so far; nil when it fits.
86
103
  #: () -> String?
87
104
  def form_fault
88
105
  form = @form or return
89
- return "--as takes template, the answer alone, not #{form}" unless form == "template"
90
-
91
- "--as template prints a full or one-member audit's answer, not one --write-ups starts" if @write_ups
106
+ "--as takes template, the answer alone, not #{form}" unless form == "template"
92
107
  end
93
108
  end
94
109
  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.10"
6
+ RELEASE = "0.1.0"
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.10" #: String?
10
+ BUILT_VERSION = "0.1.0" #: String?
11
11
  end
@@ -0,0 +1,59 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answered_request"
5
+ require_relative "invocation"
6
+ require_relative "../prose_list"
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
+ # An acknowledgement's answer accepted: the members that now read as judged, the files that hold them to
12
+ # commit, and the command that no longer lists them.
13
+ class AcknowledgedResult
14
+ #: (Invocation) -> void
15
+ def initialize(invocation)
16
+ @invocation = invocation
17
+ freeze
18
+ end
19
+
20
+ # The acknowledgement of each of member_ids was accepted, and file holds them all.
21
+ #: (principle_id: String, member_ids: Array[String], file: String) -> AnsweredRequest
22
+ def several_acknowledged(principle_id:, member_ids:, file:)
23
+ AnsweredRequest.new(
24
+ "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => member_ids,
25
+ "files_to_commit" => [file],
26
+ "next_action" => "Commit #{file}. #{ProseList.new(member_ids)} read as judged until each is edited again.\n" \
27
+ "This no longer lists them: " \
28
+ "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
29
+ )
30
+ end
31
+
32
+ # The acknowledgement of each of member_ids was accepted for every principle that maps it, each principle's in its
33
+ # file, under its id in files.
34
+ #: (member_ids: Array[String], files: Hash[String, String]) -> AnsweredRequest
35
+ def across_acknowledged(member_ids:, files:)
36
+ AnsweredRequest.new(
37
+ "status" => "acknowledged", "principle_ids" => files.keys, "member_ids" => member_ids,
38
+ "files_to_commit" => files.values,
39
+ "next_action" => "Commit #{ProseList.new(files.values)}. #{ProseList.new(member_ids)} read as judged until " \
40
+ "each is edited again.\nThis no longer lists them: " \
41
+ "#{@invocation.in_project("list-member-problems", usage: "--short")}"
42
+ )
43
+ end
44
+
45
+ # The acknowledgement was accepted and file holds it.
46
+ #: (principle_id: String, member_id: String, file: String) -> AnsweredRequest
47
+ def acknowledged(principle_id:, member_id:, file:)
48
+ fields = {
49
+ "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => [member_id],
50
+ "files_to_commit" => [file],
51
+ "next_action" => "Commit #{file}. #{member_id} reads as judged until it is edited again.\n" \
52
+ "This no longer lists it: " \
53
+ "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
54
+ }
55
+ AnsweredRequest.new(fields)
56
+ end
57
+ end
58
+ end
59
+ end