principles 0.0.4 → 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 (227) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/cli.rb +3 -1
  4. data/lib/principles/command_line.rb +38 -26
  5. data/lib/principles/command_routes.rb +11 -4
  6. data/lib/principles/controllers/acknowledgement.rb +93 -17
  7. data/lib/principles/controllers/answer.rb +45 -76
  8. data/lib/principles/controllers/answer_phase.rb +54 -0
  9. data/lib/principles/controllers/assessment.rb +46 -11
  10. data/lib/principles/controllers/audit.rb +17 -6
  11. data/lib/principles/controllers/audit_completion.rb +9 -5
  12. data/lib/principles/controllers/command.rb +5 -4
  13. data/lib/principles/controllers/correction.rb +22 -10
  14. data/lib/principles/controllers/full_audit_request.rb +11 -1
  15. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  16. data/lib/principles/controllers/inventory.rb +15 -29
  17. data/lib/principles/controllers/mapping.rb +9 -1
  18. data/lib/principles/controllers/member_addition.rb +65 -0
  19. data/lib/principles/controllers/member_entries.rb +6 -24
  20. data/lib/principles/controllers/member_problems_report.rb +13 -6
  21. data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
  22. data/lib/principles/controllers/members_to_assess.rb +21 -13
  23. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  24. data/lib/principles/controllers/repoint.rb +22 -23
  25. data/lib/principles/controllers/survey.rb +60 -0
  26. data/lib/principles/data/audit_files.rb +4 -0
  27. data/lib/principles/data/bounded_file.rb +9 -4
  28. data/lib/principles/data/candidate_files_found.rb +48 -13
  29. data/lib/principles/data/command-steps.json +85 -24
  30. data/lib/principles/data/committed_tree.rb +84 -0
  31. data/lib/principles/data/first_parent_log.rb +48 -0
  32. data/lib/principles/data/first_parent_range.rb +122 -0
  33. data/lib/principles/data/git_command.rb +37 -0
  34. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  35. data/lib/principles/data/map_files.rb +35 -10
  36. data/lib/principles/data/principles_directory.rb +40 -0
  37. data/lib/principles/data/principles_subfolder.rb +39 -16
  38. data/lib/principles/data/project_files.rb +22 -11
  39. data/lib/principles/data/repository.rb +55 -29
  40. data/lib/principles/data/requested_candidate_files.rb +43 -0
  41. data/lib/principles/data/running_version.rb +3 -5
  42. data/lib/principles/data/schema_check.rb +16 -6
  43. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +18 -5
  44. data/lib/principles/data/schemas/answer-guide.schema.json +255 -68
  45. data/lib/principles/data/schemas/audit-record.schema.json +10 -1
  46. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  47. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  48. data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
  49. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  50. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  51. data/lib/principles/data/verified_head.rb +162 -0
  52. data/lib/principles/invocation_options.rb +3 -3
  53. data/lib/principles/models/acknowledgement.rb +95 -84
  54. data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
  55. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  56. data/lib/principles/models/answer_place.rb +4 -0
  57. data/lib/principles/models/assessment_answer.rb +0 -45
  58. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  59. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  60. data/lib/principles/models/audit_record.rb +12 -16
  61. data/lib/principles/models/audit_records.rb +52 -23
  62. data/lib/principles/models/candidate_files.rb +44 -10
  63. data/lib/principles/models/candidate_inventory.rb +69 -8
  64. data/lib/principles/models/candidate_outline.rb +195 -0
  65. data/lib/principles/models/captured_head.rb +72 -0
  66. data/lib/principles/models/carried_member.rb +42 -0
  67. data/lib/principles/models/check_since_last_audit.rb +20 -11
  68. data/lib/principles/models/command_steps.rb +17 -1
  69. data/lib/principles/models/declared_map_changes.rb +29 -12
  70. data/lib/principles/models/declared_member_removals.rb +75 -0
  71. data/lib/principles/models/disposition.rb +4 -2
  72. data/lib/principles/models/fix_only_fields.rb +12 -0
  73. data/lib/principles/models/frontmatter_fields.rb +9 -8
  74. data/lib/principles/models/guidance_search_path.rb +26 -0
  75. data/lib/principles/models/guidance_search_paths.rb +57 -0
  76. data/lib/principles/models/instruction_named.rb +35 -0
  77. data/lib/principles/models/left_as_printed.rb +39 -0
  78. data/lib/principles/models/line_span.rb +6 -0
  79. data/lib/principles/models/loaded_files.rb +1 -2
  80. data/lib/principles/models/loading_scope.rb +61 -0
  81. data/lib/principles/models/locator.rb +6 -0
  82. data/lib/principles/models/mapped_principles.rb +39 -37
  83. data/lib/principles/models/member_assessments.rb +9 -31
  84. data/lib/principles/models/member_file.rb +20 -47
  85. data/lib/principles/models/member_hashes_as_written.rb +10 -6
  86. data/lib/principles/models/member_history.rb +7 -5
  87. data/lib/principles/models/member_lines.rb +63 -15
  88. data/lib/principles/models/member_loading_scopes.rb +49 -0
  89. data/lib/principles/models/member_loads.rb +4 -0
  90. data/lib/principles/models/member_mapping_run.rb +30 -0
  91. data/lib/principles/models/member_moves.rb +4 -0
  92. data/lib/principles/models/member_problems.rb +63 -33
  93. data/lib/principles/models/member_region.rb +129 -0
  94. data/lib/principles/models/member_repair_moves.rb +52 -0
  95. data/lib/principles/models/member_snapshots.rb +14 -1
  96. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  97. data/lib/principles/models/meta_principle.rb +14 -0
  98. data/lib/principles/models/missing_files.rb +2 -2
  99. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  100. data/lib/principles/models/other_templates_placeholders.rb +81 -42
  101. data/lib/principles/models/outline_budget.rb +142 -0
  102. data/lib/principles/models/outline_group.rb +31 -0
  103. data/lib/principles/models/outline_section.rb +56 -0
  104. data/lib/principles/models/principle.rb +14 -7
  105. data/lib/principles/models/principle_file_revision.rb +48 -0
  106. data/lib/principles/models/principle_history.rb +46 -19
  107. data/lib/principles/models/principle_lineage.rb +118 -0
  108. data/lib/principles/models/principle_map_revision.rb +39 -0
  109. data/lib/principles/models/principle_mapping_history.rb +132 -0
  110. data/lib/principles/models/principle_members.rb +25 -0
  111. data/lib/principles/models/principle_predecessor.rb +45 -0
  112. data/lib/principles/models/principle_publication.rb +177 -0
  113. data/lib/principles/models/principle_revision.rb +104 -0
  114. data/lib/principles/models/prior_decision_fields.rb +3 -2
  115. data/lib/principles/models/prior_finding_decision.rb +14 -4
  116. data/lib/principles/models/problem_report.rb +17 -5
  117. data/lib/principles/models/project.rb +46 -39
  118. data/lib/principles/models/project_history.rb +45 -25
  119. data/lib/principles/models/quoted_change.rb +137 -0
  120. data/lib/principles/models/record_format.rb +12 -2
  121. data/lib/principles/models/recorded_entry.rb +6 -0
  122. data/lib/principles/models/recorded_hashes.rb +7 -3
  123. data/lib/principles/models/recorded_members.rb +27 -15
  124. data/lib/principles/models/refusal_before_shape.rb +21 -0
  125. data/lib/principles/models/repoint.rb +13 -0
  126. data/lib/principles/models/reported_check.rb +5 -14
  127. data/lib/principles/models/sent_answer.rb +61 -0
  128. data/lib/principles/models/shape_problems_beside.rb +40 -0
  129. data/lib/principles/models/submitted_answer.rb +34 -0
  130. data/lib/principles/models/survey_search_paths.rb +26 -0
  131. data/lib/principles/models/template_placeholders.rb +34 -4
  132. data/lib/principles/models/text_within.rb +55 -0
  133. data/lib/principles/models/unchecked_members.rb +76 -0
  134. data/lib/principles/models/uncommitted_files.rb +50 -0
  135. data/lib/principles/models/unknown_principle.rb +29 -0
  136. data/lib/principles/models/write_up_opening.rb +21 -4
  137. data/lib/principles/positional_arguments.rb +37 -0
  138. data/lib/principles/session_start_options.rb +2 -2
  139. data/lib/principles/start_audit_options.rb +19 -4
  140. data/lib/principles/version.rb +2 -2
  141. data/lib/principles/views/acknowledgement_result.rb +23 -11
  142. data/lib/principles/views/added_member.rb +41 -0
  143. data/lib/principles/views/answered_request.rb +21 -0
  144. data/lib/principles/views/assessed_members.rb +43 -10
  145. data/lib/principles/views/assessment_request.rb +91 -31
  146. data/lib/principles/views/audit_result.rb +40 -28
  147. data/lib/principles/views/candidate_files_result.rb +85 -19
  148. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  149. data/lib/principles/views/check_notes.rb +44 -0
  150. data/lib/principles/views/check_result_template.rb +14 -23
  151. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  152. data/lib/principles/views/correction_request.rb +32 -1
  153. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  154. data/lib/principles/views/instruction.rb +74 -0
  155. data/lib/principles/views/json_with_entries_on_lines.rb +59 -0
  156. data/lib/principles/views/loads_to_check_result.rb +2 -2
  157. data/lib/principles/views/map_added_to.rb +56 -2
  158. data/lib/principles/views/map_result.rb +23 -43
  159. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  160. data/lib/principles/views/member_change_since_baseline.rb +23 -5
  161. data/lib/principles/views/member_repairs.rb +22 -52
  162. data/lib/principles/views/members_a_commit_changed.rb +16 -6
  163. data/lib/principles/views/new_loading_scope.rb +31 -0
  164. data/lib/principles/views/one_member_check_result_template.rb +47 -0
  165. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  166. data/lib/principles/views/open_findings_line.rb +77 -23
  167. data/lib/principles/views/principle_read_result.rb +24 -29
  168. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  169. data/lib/principles/views/prior_findings_result.rb +23 -15
  170. data/lib/principles/views/problem_lines.rb +3 -1
  171. data/lib/principles/views/problem_result.rb +8 -3
  172. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  173. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  174. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -48
  175. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  176. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  177. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
  178. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  179. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  180. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  181. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  182. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  183. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  184. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  185. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +16 -3
  186. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  187. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  188. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  189. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  190. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  191. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +11 -5
  192. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  193. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  194. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  195. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  196. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  197. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  198. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  199. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  200. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  201. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  202. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +55 -7
  203. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +9 -8
  204. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  205. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
  206. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  207. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  208. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  209. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +27 -1
  210. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  211. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
  212. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
  213. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  214. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  215. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  216. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  217. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  218. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
  219. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  220. data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
  221. data/lib/principles/views/request_part.rb +16 -8
  222. data/lib/principles/views/request_parts.rb +4 -0
  223. metadata +92 -7
  224. data/lib/principles/models/candidate_listing.rb +0 -32
  225. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  226. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
  227. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -2,9 +2,11 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
+ require_relative "acknowledgement_refusal"
5
6
  require_relative "audit_record"
6
7
  require_relative "principle_members"
7
8
  require_relative "principle_history"
9
+ require_relative "principle_mapping_history"
8
10
  require_relative "member_state"
9
11
  require_relative "locate_refusal"
10
12
 
@@ -21,15 +23,19 @@ module Principles
21
23
  class Baselines
22
24
  # The last audit's hashes for members' map, and each member's hash and commit at the commit that mapped it
23
25
  # where it is, read with the map as that commit held it; none outside git.
24
- #: (Project, PrincipleMembers) -> Baselines
25
- def self.of(project, members)
26
- id = members.principle_id
27
- audit, hashes = project.audit_records.for_comparison(id)
28
- mapped = PrincipleHistory.new(id: id, history: project.history, principles: project.principles)
29
- .mapped_baselines(members.keys)
30
- new(audit: audit, mapped: mapped.transform_values { |each| each.fetch("sha256") },
31
- mapped_in: mapped.transform_values { |each| each.fetch("commit") }, in_git: project.history.inside_git?,
32
- hashes: hashes)
26
+ #: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Baselines
27
+ def self.of(project, members, mapping: nil)
28
+ records = project.audit_records
29
+ mapped = mapped_where_it_is(project, members, mapping: mapping)
30
+ new(audit: records.readable(members.principle_id), mapped: mapped, in_git: project.history.inside_git?,
31
+ hashes: records.hashes_to_compare(members.principle_id), mapping: mapping)
32
+ end
33
+
34
+ # Each member's hash and commit at the commit that mapped it where it is, read with the map as that commit
35
+ # held it.
36
+ #: (Project, PrincipleMembers, ?mapping: PrincipleMappingHistory?) -> Hash[String, Hash[String, String]]
37
+ def self.mapped_where_it_is(project, members, mapping: nil)
38
+ project.principle_history(members.principle_id, mapping: mapping).mapped_baselines(members.keys)
33
39
  end
34
40
 
35
41
  # Whether the project is in git, so a member with no baseline is one no commit holds yet.
@@ -37,34 +43,42 @@ module Principles
37
43
  attr_reader :in_git
38
44
 
39
45
  # Whether a later copy wrote the principle's record, so its audits and acknowledgements wait on an upgrade.
40
- #: bool
41
- attr_reader :waiting
46
+ #: () -> bool
47
+ def waiting? = @hashes.waiting?
42
48
 
43
49
  # audit is the principle's audit record, if any: its hashes, the commit it began from and whether it is
44
50
  # completed, so a one-member audit is offered only where one would be accepted (#626). hashes is the member
45
51
  # hashes the record holds, which a later copy may have written, so its members are compared read-only (#1066).
46
- #: (audit: AuditRecord?, mapped: Hash[String, String], mapped_in: Hash[String, String], in_git: bool,
47
- #| ?hashes: RecordedHashes) -> void
48
- def initialize(audit:, mapped:, mapped_in:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE)
49
- @audited = hashes.by_key #: Hash[String, String]
52
+ #: (audit: AuditRecord?, mapped: Hash[String, Hash[String, String]], in_git: bool,
53
+ #| ?hashes: RecordedHashes, ?mapping: PrincipleMappingHistory?) -> void
54
+ def initialize(audit:, mapped:, in_git:, hashes: audit&.members&.hashes || RecordedHashes::NONE, mapping: nil)
55
+ @hashes = hashes
50
56
  @audit = audit #: AuditRecord?
51
57
  @audit_base = audit&.base_commit #: String?
52
58
  @mapped = mapped
53
- @mapped_in = mapped_in
54
59
  @in_git = in_git
55
- @waiting = hashes.waiting? #: bool
60
+ @mapping = mapping #: PrincipleMappingHistory?
56
61
  freeze
57
62
  end
58
63
 
64
+ # Only a mapping baseline supplies automatic history; a recorded hash needs its own provenance.
65
+ #: (String) -> PrincipleMappingHistory?
66
+ def mapping_for(key)
67
+ return if @hashes.hash_for(key)
68
+
69
+ @mapping if @mapped.key?(key)
70
+ end
71
+
59
72
  # The hash this tool last knew for the member known by key, and what it was: the last audit's, or else its
60
73
  # hash at the commit that mapped it, with why no audit gave one; neither when it has no baseline.
61
74
  #: (String) -> [String?, Hash[String, untyped]?]
62
75
  def of(key)
63
- if @audited.key?(key)
64
- [@audited[key], { "baseline" => "audit", "commit" => @audit_base }]
76
+ if (audited = @hashes.hash_for(key))
77
+ [audited, { "baseline" => "audit", "commit" => @audit_base }]
65
78
  elsif @mapped.key?(key)
66
- [@mapped[key], { "baseline" => "mapping_commit", "commit" => @mapped_in[key],
67
- "no_audit_because" => @audited.empty? ? "no_audit_record" : "not_in_last_audit" }]
79
+ mapped = @mapped.fetch(key)
80
+ [mapped.fetch("sha256"), { "baseline" => "mapping_commit", "commit" => mapped.fetch("commit"),
81
+ "no_audit_because" => @hashes.empty? ? "no_audit_record" : "not_in_last_audit" }]
68
82
  else
69
83
  [nil, nil]
70
84
  end
@@ -89,7 +103,7 @@ module Principles
89
103
  #: (Member, String?) -> bool
90
104
  def acknowledgeable?(member, now_sha256)
91
105
  audit = @audit
92
- @in_git && !@waiting && !audit.nil? && audit.acknowledgement_refusal(member, now_sha256:).nil?
106
+ @in_git && !waiting? && !audit.nil? && AcknowledgementRefusal.of(audit, member, now_sha256:).nil?
93
107
  end
94
108
  end
95
109
 
@@ -97,8 +111,11 @@ module Principles
97
111
  # refused when it was asked for, and listed as broken among every map.
98
112
  #: (Project, String, ?listing_all: bool) -> MemberProblems
99
113
  def self.for(project, id, listing_all: false)
100
- members = project.principles.find(id).members
101
- new(members: members, now: project.current_by_key(members), baselines: Baselines.of(project, members))
114
+ map = project.principles.find(id)
115
+ members = map.members
116
+ mapping = PrincipleMappingHistory.load_if_linked(current: map, project: project)
117
+ new(members: members, now: project.current_by_key(members),
118
+ baselines: Baselines.of(project, members, mapping: mapping))
102
119
  rescue Error => e
103
120
  raise unless listing_all
104
121
 
@@ -146,15 +163,13 @@ module Principles
146
163
 
147
164
  # The entries whose own text changed since this tool last knew it, those an audit assessed first. Given a
148
165
  # block, each gains "history", what the block makes of its member, the hash it was compared with, and its
149
- # hash now.
150
- #: () ?{ (Member, String, String) -> Hash[String, untyped] } -> Array[Hash[String, untyped]]
166
+ # hash now and the selected automatic history when that mapping supplies its baseline.
167
+ #: () ?{ (Member, String, String, PrincipleMappingHistory?) -> Hash[String, untyped] }
168
+ #| -> Array[Hash[String, untyped]]
151
169
  def changed(&history)
152
170
  assessed, unassessed = changed_members.partition { |member| assessed?(member) }
153
171
  (assessed + unassessed).map do |member|
154
- listed = entry(member)
155
- next listed unless history
156
-
157
- listed.merge("history" => history.call(member, baseline(member.key).first.to_s, @now[member.key].to_s))
172
+ history ? history_entry(member, history) : entry(member)
158
173
  end
159
174
  end
160
175
 
@@ -195,12 +210,21 @@ module Principles
195
210
  found.map { |member| baseline(member.key).last&.fetch("baseline") || "no_baseline" }.tally.sort.to_h
196
211
  end
197
212
 
213
+ # Whether this readable map has no completed audit, independent of baseline readiness; a newer record is
214
+ # unknown to this copy, rather than evidence that no audit completed.
215
+ #: () -> bool
216
+ def no_completed_audit? = @unreadable.nil? && !@baselines.waiting? && @baselines.no_completed_audit?
217
+
218
+ # Whether this readable map has no members, even when an older full audit completed before it was emptied.
219
+ #: () -> bool
220
+ def empty_map? = @unreadable.nil? && @members.empty?
221
+
198
222
  # Whether the principle awaits its first full audit: none has completed and a member is found, in git one a
199
223
  # commit or an open audit gives a baseline, since until a commit holds its map committing gives its members
200
224
  # one (D58, #731 R7).
201
225
  #: () -> bool
202
226
  def awaits_first_audit?
203
- return false if @baselines.waiting || !@baselines.no_completed_audit?
227
+ return false if @baselines.waiting? || !@baselines.no_completed_audit?
204
228
 
205
229
  bases = compared_with.keys
206
230
  @baselines.in_git ? bases.any? { it != "no_baseline" } : !bases.empty?
@@ -226,6 +250,12 @@ module Principles
226
250
 
227
251
  private
228
252
 
253
+ #: (Member, ^(Member, String, String, PrincipleMappingHistory?) -> Hash[String, untyped]) -> Hash[String, untyped]
254
+ def history_entry(member, history)
255
+ entry(member).merge("history" => history.call(member, baseline(member.key).first.to_s, @now[member.key].to_s,
256
+ @baselines.mapping_for(member.key)))
257
+ end
258
+
229
259
  # The members whose own text changed since this tool last knew it; none in a map that cannot be read.
230
260
  #: () -> Array[Member]
231
261
  def changed_members
@@ -237,7 +267,7 @@ module Principles
237
267
  # The changed members this copy can act on: none while a later copy's record makes them wait on an upgrade,
238
268
  # so they give --short neither exit 3 nor 4 (D85 V8, #1066).
239
269
  #: () -> Array[Member]
240
- def changes_to_act_on = @baselines.waiting ? [] : changed_members
270
+ def changes_to_act_on = @baselines.waiting? ? [] : changed_members
241
271
 
242
272
  #: (Member) -> bool
243
273
  def assessed?(member) = baseline(member.key).last&.fetch("baseline") == "audit"
@@ -260,7 +290,7 @@ module Principles
260
290
  return listed.merge("state" => "no_baseline") unless since
261
291
  unless then_sha == sha
262
292
  return listed.merge("state" => "changed", "since" => since,
263
- **(@baselines.waiting ? { "waiting_on_an_upgrade" => true } : {}))
293
+ **(@baselines.waiting? ? { "waiting_on_an_upgrade" => true } : {}))
264
294
  end
265
295
 
266
296
  listed.merge("state" => since["baseline"] == "mapping_commit" ? "unchanged_since_mapping" : "unchanged")
@@ -0,0 +1,129 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "member_file"
7
+ require_relative "line_span"
8
+
9
+ module Principles
10
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # A file-selected region's text and full-file character origin, for literal passage matching.
13
+ class MemberRegion
14
+ # How many ambiguous passage openings the refusal names, so one character cannot list the whole file.
15
+ OPENINGS_NAMED = 5 #: Integer
16
+ ENDINGS_NAMED = 5 #: Integer
17
+
18
+ #: (MemberFile, span: LineSpan) -> void
19
+ def initialize(file, span:)
20
+ @path = file.path.dup.freeze #: String
21
+ @text = file.text.dup.freeze #: String
22
+ region = captured_region(span)
23
+ @before = region[0] #: Integer
24
+ @selected = region[1] #: String
25
+ freeze
26
+ end
27
+
28
+ # Existing references use one opening and the first eligible ending, or the opening's whole line.
29
+ #: (String, String?) -> [Integer, Integer, String]
30
+ def passage(start_text, end_text)
31
+ start = only_opening(@selected, start_text, @before)
32
+ found = @selected[start...passage_end(@selected, start, start_text, end_text)].to_s
33
+ line = @text[0, @before + start].to_s.count("\n")
34
+ [line, line + line_count(found), found]
35
+ end
36
+
37
+ # The narrower constraint applied only before persisting a newly authored locator.
38
+ #: (String, String) -> void
39
+ def check_authored_ending(start_text, end_text)
40
+ start = only_opening(@selected, start_text, @before)
41
+ offsets = ending_offsets(start + start_text.length, end_text)
42
+ ambiguous_ending(end_text, offsets) if offsets.length > 1
43
+ end
44
+
45
+ private
46
+
47
+ # Every eligible literal start counts, including endings that overlap a previous ending.
48
+ #: (Integer, String) -> Array[Integer]
49
+ def ending_offsets(after, ending)
50
+ offsets = [] #: Array[Integer]
51
+ while (found = @selected.index(ending, after))
52
+ offsets << (@before + found)
53
+ after = found + 1
54
+ end
55
+ offsets
56
+ end
57
+
58
+ #: (String, Array[Integer]) -> bot
59
+ def ambiguous_ending(ending, offsets)
60
+ candidates = offsets.first(ENDINGS_NAMED).map { ending_candidate(it) }
61
+ raise Error.new("ambiguous_passage_end", "#{ending.inspect} has #{offsets.length} eligible endings",
62
+ "Give a more specific --ending-at closing quote that occurs once after the complete opening.",
63
+ @path).including("eligible_ending_count" => offsets.length, "ending_candidates" => candidates,
64
+ "ending_candidates_omitted" => offsets.length - candidates.length)
65
+ end
66
+
67
+ # Coordinates use characters, consistently with String#index and the complete-opening boundary.
68
+ #: (Integer) -> Hash[String, Integer]
69
+ def ending_candidate(offset)
70
+ prefix = @text[0, offset].to_s
71
+ { "line" => prefix.count("\n") + 1, "column" => offset - (prefix.rindex("\n") || -1) }
72
+ end
73
+
74
+ # Selected text and its character origin from the file-type's inclusive line span.
75
+ #: (LineSpan) -> [Integer, String]
76
+ def captured_region(span)
77
+ lines = @text.lines
78
+ first = span.first_line - 1
79
+ [lines[0...first].to_a.join.length, lines[first...span.last_line].to_a.join.freeze]
80
+ end
81
+
82
+ #: (String) -> Integer
83
+ def line_count(found)
84
+ found.count("\n") + (found.end_with?("\n") ? 0 : 1)
85
+ end
86
+
87
+ #: (String, String, Integer) -> Integer
88
+ def only_opening(text, start_text, before)
89
+ starts = text.enum_for(:scan, start_text).filter_map { Regexp.last_match&.begin(0) }
90
+ return starts.first.to_i if starts.length == 1
91
+
92
+ starts.empty? ? opening_not_found(start_text) : ambiguous_opening(start_text, starts.map { before + it })
93
+ end
94
+
95
+ #: (String) -> bot
96
+ def opening_not_found(start_text)
97
+ raise Error.new("passage_not_found", "The passage starting #{start_text.inspect} is not in the file",
98
+ "Quote the passage's opening text exactly.", @path)
99
+ end
100
+
101
+ #: (String, Array[Integer]) -> bot
102
+ def ambiguous_opening(start_text, offsets)
103
+ raise Error.new("ambiguous_passage",
104
+ "#{start_text.inspect} occurs #{offsets.length} times, at lines #{lines_named(offsets)}",
105
+ "Quote more of the passage's start so it occurs once.", @path)
106
+ end
107
+
108
+ #: (Array[Integer]) -> String
109
+ def lines_named(offsets)
110
+ named = offsets.first(OPENINGS_NAMED).map { (@text[0, it].to_s.count("\n") + 1).to_s }
111
+ more = offsets.length - named.length
112
+ more.zero? ? ProseList.new(named).to_s : "#{named.join(", ")} and #{more} more"
113
+ end
114
+
115
+ #: (String, Integer, String, String?) -> Integer
116
+ def passage_end(text, start, start_text, end_text)
117
+ return (text.index("\n", start) || (text.length - 1)) + 1 unless end_text
118
+
119
+ found = text.index(end_text, start + start_text.length)
120
+ unless found
121
+ raise Error.new("passage_end_not_found", "No #{end_text.inspect} after #{start_text.inspect}",
122
+ "Quote the passage's closing text exactly.", @path)
123
+ end
124
+
125
+ found + end_text.length
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,52 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # The moves that may repair a member this tool cannot find, each as the locator fields it keeps and those the agent
8
+ # fills in, which Views::MemberRepairs prints as move-member commands. A member whose file is gone moves to the
9
+ # path the agent finds, keeping its own section, passage or query, so a rename keeps its audit (#268). A member
10
+ # whose place in its file is gone moves within it, or into another file its text moved to (#378); a passage keeps
11
+ # its anchors, so a move cannot silently widen it to its whole new section (#251), but not an opening or ending text
12
+ # that is gone, which a move repeating it would fail on again as printed (#1104, #1139); and it is given no section
13
+ # a passage located by its opening alone never had (#1134). Which fits is the agent's to judge.
14
+ class MemberRepairMoves
15
+ # The locator fields a member may give beside its path.
16
+ LOCATOR = %w[section starting_at ending_at query].freeze #: Array[String]
17
+ # The passage anchor each refusal code says is no longer in its file, which a move fills in afresh.
18
+ LOST_ANCHOR = { "passage_not_found" => %w[starting_at],
19
+ "passage_end_not_found" => %w[ending_at] }.freeze #: Hash[String, Array[String]]
20
+
21
+ # member is the member's locator fields, as its map holds them; code is that of the refusal saying why it cannot
22
+ # be found.
23
+ #: (Hash[String, untyped], code: String?) -> void
24
+ def initialize(member, code:)
25
+ @member = given(member, LOCATOR) #: Hash[String, untyped]
26
+ @code = code
27
+ freeze
28
+ end
29
+
30
+ # Each move, as { "keep" => the locator fields it keeps, by name, "fill" => the fields the agent fills in }.
31
+ #: () -> Array[Hash[String, untyped]]
32
+ def to_a
33
+ return [move(@member, %w[path])] if @code == "unreadable_file"
34
+ return [move({}, %w[query])] if @member["query"]
35
+
36
+ lost = LOST_ANCHOR.fetch(@code.to_s, [])
37
+ anchors = given(@member, %w[starting_at ending_at] - lost)
38
+ section = @member.key?("section") ? %w[section] : []
39
+ [move(anchors, [*lost, *section]), move(anchors, [*lost, "path", *section])]
40
+ end
41
+
42
+ private
43
+
44
+ # The fields of member named in fields that it gives, in the order fields names them.
45
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
46
+ def given(member, fields) = fields.filter_map { [it, member[it]] unless member[it].nil? }.to_h.freeze
47
+
48
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
49
+ def move(keep, fill) = { "keep" => keep, "fill" => fill }
50
+ end
51
+ end
52
+ end
@@ -8,8 +8,21 @@ module Principles
8
8
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # Each of a map's members by id, where it is in its file now and the hash of what it says there, as
11
- # Project#snapshots located them all.
11
+ # the project located them all.
12
12
  class MemberSnapshots
13
+ # Locate every member before refusing, so one broken reference never hides another.
14
+ #: (Project, Principle) -> MemberSnapshots
15
+ def self.read(project, map)
16
+ broken = [] #: Array[Hash[String, untyped]]
17
+ found = map.members.to_h do |member|
18
+ [member.id, project.locate(member.locator)]
19
+ rescue Error => e
20
+ broken << { "id" => member.id }.merge(e.payload.except("status"))
21
+ [member.id, {}]
22
+ end
23
+ broken.empty? ? new(found) : project.refuse_broken(map.id, broken)
24
+ end
25
+
13
26
  #: (Hash[String, Hash[String, untyped]]) -> void
14
27
  def initialize(by_id)
15
28
  @by_id = by_id.freeze #: Hash[String, Hash[String, untyped]]
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "member"
6
+ require_relative "located_text"
7
+
8
+ module Principles
9
+ module Models
10
+ # Members in complete sections meeting the new section at a literal line boundary, in other unaudited maps.
11
+ class MembersInConsecutiveSections
12
+ #: (Project, Member) -> void
13
+ def initialize(project, member)
14
+ @project = project
15
+ @member = member
16
+ @located = project.located_text(member.locator) #: LocatedText
17
+ @records = project.audit_records #: AuditRecords
18
+ freeze
19
+ end
20
+
21
+ # Literal section boundaries are not evidence that the rules belong to one principle.
22
+ #: (except: String) -> Array[Hash[String, untyped]]
23
+ def elsewhere(except:)
24
+ return [] unless @member.locator.complete_section? && @records.known_no_completed_audit?(except)
25
+
26
+ maps = @project.principles
27
+ (maps.ids - [except]).flat_map { |id| in_map(maps, id) }
28
+ end
29
+
30
+ private
31
+
32
+ # Optional feedback leaves unreadable maps to list-member-problems rather than blocking the write.
33
+ #: (MappedPrinciples, String) -> Array[Hash[String, untyped]]
34
+ def in_map(maps, id)
35
+ return [] unless @records.known_no_completed_audit?(id)
36
+
37
+ maps.find(id).members.to_a.filter_map { |member| consecutive(member, id) }
38
+ rescue Error
39
+ []
40
+ end
41
+
42
+ #: (Member, String) -> Hash[String, untyped]?
43
+ def consecutive(member, id)
44
+ return unless member.locator.complete_section? && @project.same_file?(member.path, @located.path)
45
+
46
+ found = @project.located_text(member.locator)
47
+ return unless @located.span.consecutive_with?(found.span)
48
+
49
+ { "principle_id" => id, "member_id" => member.id, "path" => member.path,
50
+ "role" => member.role }.merge(found.lines)
51
+ rescue Error
52
+ nil
53
+ end
54
+ end
55
+ end
56
+ end
@@ -46,6 +46,20 @@ module Principles
46
46
  # writes the map with its first member (T74).
47
47
  #: () -> Hash[String, untyped]
48
48
  def self.starting_fields = { "description" => DESCRIPTION, "members" => [], "activation" => ACTIVATION.to_h }
49
+
50
+ # Whether this is the built-in principle whose first member setup maps.
51
+ #: (String) -> bool
52
+ def self.id?(id) = id == ID
53
+
54
+ # Setup's add-member writes this map with its first member, preserving its shipped description/activation.
55
+ #: (String) -> void
56
+ def self.refuse_explicit_creation(id)
57
+ return unless id?(id)
58
+
59
+ raise Error.new("meta_principle_id",
60
+ "#{id} is set up by show-meta-principle-passage, whose printed add-member creates its map " \
61
+ "with its first member", SET_UP)
62
+ end
49
63
  end
50
64
  end
51
65
  end
@@ -47,8 +47,8 @@ module Principles
47
47
  def refusal(message, rerun: nil, note: "")
48
48
  Error.new("broken_members", message,
49
49
  "For each member listed, say whether it moved or is gone, and run the matching command in its " \
50
- "repair_with: the move-member, with its NEW_PATH, HEADING or QUERY filled in, if it moved, or the " \
51
- "remove-member if it is gone. #{note}#{REPAIR}" \
50
+ "repair_with: the move-member, with its NEW_PATH, HEADING, NEW_OPENING_TEXT, NEW_ENDING_TEXT or " \
51
+ "QUERY filled in, if it moved, or the remove-member if it is gone. #{note}#{REPAIR}" \
52
52
  "#{rerun ? "\nThen run it again: #{rerun}" : " Then run the command again."}")
53
53
  .including(**({ "principle" => @principle } if @principle), "members" => members, "missing_files" => to_a)
54
54
  end
@@ -31,6 +31,10 @@ module Principles
31
31
  #: (String) -> Array[Hash[String, untyped]]
32
32
  def beside(member_id) = @sharing.fetch(member_id).naming(@left_open_by_principle)
33
33
 
34
+ # Whether another principle leaves a finding open on a member sharing the lines of the audited member member_id.
35
+ #: (String) -> bool
36
+ def open_beside?(member_id) = @sharing.fetch(member_id).open_among(@left_open_by_principle).any?
37
+
34
38
  # Each finding left open on any of them, once, with its principle, and what its evidence's lines are beside
35
39
  # lines, this audit's members, where locate finds each item now (D64): a finding is the same one when its
36
40
  # principle and id are.
@@ -2,32 +2,77 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
+ require_relative "acknowledgement"
6
+ require_relative "assessment_answer"
7
+ require_relative "disposition"
8
+ require_relative "loading_decision"
9
+ require_relative "member_assessments"
10
+ require_relative "prior_decision_fields"
11
+ require_relative "recent_decision"
12
+ require_relative "refusal_before_shape"
13
+ require_relative "reported_check"
14
+ require_relative "shape_problems_beside"
5
15
 
6
16
  module Principles
7
17
  module Models
8
18
  # The text in an answer that ends as this tool's placeholders end, "Leave as printed ...", "else leave" or "else
9
- # kept", but is none the request's own template printed: another template's placeholder, as an answer filled from
10
- # an older template and repaired field by field keeps it, which no other check refuses in free text (#1084). It
11
- # reads the ending alone, so the agent's own text ending so is refused too, and the repair says to reword it.
19
+ # kept", or is a placeholder some template of this release prints, but is none the request's own template
20
+ # printed: another template's placeholder, as an answer filled from an older template and repaired field by field
21
+ # keeps it, which no other check refuses in free text (#1084), or as a reason copied from a correction's template
22
+ # into an acknowledgement's (#1114). It reads the ending alone for older wordings, so the agent's own text ending
23
+ # so is refused too, and the repair says to reword it.
12
24
  class OtherTemplatesPlaceholders
13
- # How every placeholder of this tool's templates ends, in this release and earlier ones.
14
- ENDING = /(\bLeave (\S+ ){0,2}as printed[^.]*|\belse (leave|kept))\.?\z/ #: Regexp
25
+ include RefusalBeforeShape
15
26
 
16
- # Each string in template, a request's template as printed, that ends as a placeholder does.
17
- #: (untyped) -> OtherTemplatesPlaceholders
18
- def self.besides(template)
19
- new(strings(template).grep(ENDING))
20
- end
27
+ # How every placeholder of this tool's templates ends, in this release and earlier ones, one of which said
28
+ # "; leave as printed otherwise" as a clause, which "to leave as printed" in prose is not (#1085).
29
+ ENDING = /((\bLeave|; leave) (\S+ ){0,2}as printed[^.]*|\belse (leave|kept))\.?\z/ #: Regexp
30
+
31
+ # Every string a JSON value holds, at any depth, by its JSON pointer: the one walk over a template and an
32
+ # answer alike.
33
+ class Strings
34
+ #: (untyped) -> void
35
+ def initialize(value)
36
+ @by_pointer = {} #: Hash[String, String]
37
+ gather(value, "")
38
+ @by_pointer.freeze
39
+ freeze
40
+ end
21
41
 
22
- # Every string in value, at any depth.
23
- #: (untyped) -> Array[String]
24
- def self.strings(value)
25
- case value
26
- when String then [value]
27
- when Hash then value.values.flat_map { strings(it) }
28
- when Array then value.flat_map { strings(it) }
29
- else []
42
+ #: Hash[String, String]
43
+ attr_reader :by_pointer
44
+
45
+ private
46
+
47
+ #: (untyped, String) -> void
48
+ def gather(value, pointer)
49
+ case value
50
+ when String then @by_pointer[pointer] = value
51
+ when Hash then value.each { |key, each| gather(each, "#{pointer}/#{escaped(key)}") }
52
+ when Array then value.each_with_index { |each, index| gather(each, "#{pointer}/#{index}") }
53
+ end
30
54
  end
55
+
56
+ # key as a JSON pointer writes it.
57
+ #: (String) -> String
58
+ def escaped(key) = key.gsub("~", "~0").gsub("/", "~1")
59
+ end
60
+
61
+ # Every placeholder a template of this release prints, from the model that owns each: the full audit's member
62
+ # assessment, collective assessment, recent decision, check result, loading decision and prior finding
63
+ # decision, the correction's disposition, and the one-member audit's acknowledgement. Its spec fails on a
64
+ # placeholder constant in models/ missing here.
65
+ KNOWN = [
66
+ MemberAssessments::PLACEHOLDER, AssessmentAnswer::COLLECTIVE_PLACEHOLDER, RecentDecision::PLACEHOLDERS.to_h,
67
+ ReportedCheck::PLACEHOLDERS.to_h, ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h,
68
+ LoadingDecision::PLACEHOLDERS.to_h, PriorDecisionFields::TEMPLATE_PLACEHOLDERS,
69
+ Disposition::TEMPLATE_PLACEHOLDERS, Acknowledgement::PLACEHOLDERS.to_h, Acknowledgement::EXIT_STATUS_PLACEHOLDER
70
+ ].then { Strings.new(it).by_pointer.values.to_set }.freeze #: Set[String]
71
+
72
+ # Each string in template, a request's template as printed, which its answer may send back.
73
+ #: (untyped) -> OtherTemplatesPlaceholders
74
+ def self.besides(template)
75
+ new(Strings.new(template).by_pointer.values)
31
76
  end
32
77
 
33
78
  # printed is the placeholders the request's own template printed, which an answer may leave as printed.
@@ -36,39 +81,33 @@ module Principles
36
81
  @printed = printed
37
82
  end
38
83
 
39
- # Refuses answer, read from source, in one refusal naming every field holding another template's placeholder.
40
- #: (untyped, String) -> void
41
- def refuse_in(answer, source)
42
- found = pointers(answer, "")
84
+ # Refuses answer in one refusal naming every field holding another template's placeholder, as "The answer": the
85
+ # agent holds its file's path, which cost context in every repair (#1112). It names each of shape_problems at
86
+ # another field too, so both slips take one repair (#1109).
87
+ # @override
88
+ #: (untyped, String, Array[Hash[String, String]]) -> void
89
+ def refuse_in(answer, _source, shape_problems)
90
+ found = Strings.new(answer).by_pointer.select { |_, text| other?(text) }.keys
43
91
  return if found.empty?
44
92
 
45
- raise Error.new("invalid_answer", "#{source} holds text another template printed as a placeholder",
46
- "Start from this request's response_template, or replace each field named with your own " \
47
- "text; if one is your own text, reword its ending.",
48
- source, fields: found.map { { "pointer" => it, "problem" => PROBLEM } })
93
+ elsewhere = ShapeProblemsBeside.new(shape_problems, named: found)
94
+ raise Error.new("invalid_answer", elsewhere.message(MESSAGE),
95
+ "#{elsewhere.repair(REPAIR, "; repair each other field listed")}.",
96
+ fields: found.map { { "pointer" => it, "problem" => PROBLEM } } + elsewhere.fields)
49
97
  end
50
98
 
99
+ MESSAGE = "The answer holds text another template printed as a placeholder" #: String
100
+
101
+ REPAIR = "Start from this request's response_template, or replace each field named with your own text; if one " \
102
+ "is your own text, reword its ending" #: String
103
+
51
104
  PROBLEM = "ends as a placeholder does, but is none this request's template printed" #: String
52
105
 
53
106
  private
54
107
 
55
- # The pointer to each string in value, at pointer, that ends as a placeholder does and is not one printed.
56
- #: (untyped, String) -> Array[String]
57
- def pointers(value, pointer)
58
- case value
59
- when String then other?(value) ? [pointer] : []
60
- when Hash then value.flat_map { |key, each| pointers(each, "#{pointer}/#{escaped(key)}") }
61
- when Array then value.each_with_index.flat_map { |each, index| pointers(each, "#{pointer}/#{index}") }
62
- else []
63
- end
64
- end
65
-
108
+ # Whether text ends as a placeholder does, or is one another template prints, but is none printed.
66
109
  #: (String) -> bool
67
- def other?(text) = text.match?(ENDING) && !@printed.include?(text)
68
-
69
- # key as a JSON pointer writes it.
70
- #: (String) -> String
71
- def escaped(key) = key.gsub("~", "~0").gsub("/", "~1")
110
+ def other?(text) = (text.match?(ENDING) || KNOWN.include?(text)) && !@printed.include?(text)
72
111
  end
73
112
  end
74
113
  end