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
@@ -1,9 +1,12 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "json"
5
+
4
6
  require_relative "../error"
5
7
  require_relative "../data/audit_files"
6
8
  require_relative "audit_record"
9
+ require_relative "audit_entry_protecting_map"
7
10
  require_relative "member_hashes_as_written"
8
11
  require_relative "recorded_hashes"
9
12
  require_relative "project_history"
@@ -39,6 +42,27 @@ module Principles
39
42
  fields && AuditRecord.new(fields)
40
43
  end
41
44
 
45
+ # One exact historical selection, without a routed lookup or a format stamp.
46
+ #: (String, String) -> AuditRecord
47
+ def parsed_history(id, text)
48
+ fields = @files.parse(id, text) { refuse_unreadable(it, file(id)) }
49
+ refuse_unreadable(fields, file(id))
50
+ record = AuditRecord.new(JSON.parse(JSON.generate(fields), freeze: true))
51
+ return record if record.principle_id == id && record.completed?
52
+
53
+ raise Error.new("invalid_audit_record", "#{file(id)} is not a completed record of #{id}",
54
+ "Preserve this record and inspect its identity and status before changing an ID.", file(id))
55
+ end
56
+
57
+ # Optional mapping feedback: a missing record is known absence; unreadable records leave this unknown.
58
+ #: (String) -> bool
59
+ def known_no_completed_audit?(id)
60
+ audit = find(id) or return true
61
+ audit.known_no_completed_audit?
62
+ rescue Error
63
+ false
64
+ end
65
+
42
66
  # The findings id's record leaves open: none when it has no record, and none when its record cannot be read,
43
67
  # which list-member-problems reports, so a command reading other principles' findings beside its own is not
44
68
  # refused for theirs (#772).
@@ -61,23 +85,30 @@ module Principles
61
85
  # when it has none, is not newer, or is refused for another reason, which reading it reports (D85).
62
86
  #: (String) -> RecordFormat?
63
87
  def newer_format(id)
64
- fields = @files.read(id) { |raw| return newer_of(raw) }
65
- fields && newer_of(fields)
88
+ fields = @files.read(id) { |raw| return RecordFormat.newer_of(raw) }
89
+ fields && RecordFormat.newer_of(fields)
66
90
  rescue Error
67
91
  nil
68
92
  end
69
93
 
70
- # Id's record, if this copy can read it, and the member hashes it holds, which its members are compared with:
71
- # the record's own when this copy can read it, and as written when its schema refuses one a later copy wrote,
72
- # marked waiting when a later copy wrote it, so the comparison is read-only (D85 V8, #1066, #1067).
73
- #: (String) -> [AuditRecord?, RecordedHashes]
74
- def for_comparison(id)
75
- audit = find(id) or return [nil, RecordedHashes::NONE]
76
- [audit, RecordedHashes.new(audit.members.hashes_by_key, waiting: RecordFormat.new(audit.to_h).newer?)]
77
- rescue Error => e
78
- raise unless e.payload.fetch("code") == "newer_audit_record"
94
+ # The member hashes id's record holds, which its members are compared with: the record's own when this copy can
95
+ # read it, and as written when its schema refuses one a later copy wrote, marked waiting when a later copy wrote
96
+ # it, so the comparison is read-only (D85 V8, #1066, #1067); none when it has no record.
97
+ #: (String) -> RecordedHashes
98
+ def hashes_to_compare(id)
99
+ audit = find(id) or return RecordedHashes::NONE
100
+ RecordedHashes.new(audit.members.hashes_by_key, waiting: RecordFormat.new(audit.to_h).newer?)
101
+ rescue RecordFormat::NewerFormatError
102
+ RecordedHashes.new(member_hashes_as_written(id).by_key, waiting: true)
103
+ end
79
104
 
80
- [nil, RecordedHashes.new(member_hashes_as_written(id).by_key, waiting: true)]
105
+ # id's record if this copy can read it; nil when it has none, or a later copy wrote it in a form this copy
106
+ # cannot read, whose audits wait on an upgrade (D85, V8).
107
+ #: (String) -> AuditRecord?
108
+ def readable(id)
109
+ find(id)
110
+ rescue RecordFormat::NewerFormatError
111
+ nil
81
112
  end
82
113
 
83
114
  # The record of each of ids that has one.
@@ -88,11 +119,7 @@ module Principles
88
119
  # read across principles is not refused for that one, whose audits wait on an upgrade (D85, V8).
89
120
  #: (Array[String]) -> Array[AuditRecord]
90
121
  def readable_of(ids)
91
- ids.filter_map do |id|
92
- find(id)
93
- rescue Error => e
94
- raise unless e.payload.fetch("code") == "newer_audit_record"
95
- end
122
+ ids.filter_map { readable(it) }
96
123
  end
97
124
 
98
125
  # id's record, refused when it has none.
@@ -107,6 +134,14 @@ module Principles
107
134
  @files.exist?(id)
108
135
  end
109
136
 
137
+ #: (String, ?confirmed: bool) -> void
138
+ def refuse_map_removal(id, confirmed: false)
139
+ return unless @files.entry?(id)
140
+ return if confirmed
141
+
142
+ raise AuditEntryProtectingMap.new(id, file(id)).refusal
143
+ end
144
+
110
145
  # The record as a change to write, unless it says what the record on disk says, apart from when.
111
146
  #: (AuditRecord) -> Array[AuditRecord]
112
147
  def changes(record)
@@ -156,12 +191,6 @@ module Principles
156
191
  MemberHashesAsWritten.new(nil)
157
192
  end
158
193
 
159
- #: (untyped) -> RecordFormat?
160
- def newer_of(fields)
161
- format = RecordFormat.new(fields) if fields.is_a?(Hash)
162
- format if format&.newer?
163
- end
164
-
165
194
  # Refuses fields, a record at file the schema refused, as one a later copy wrote when its format says so, so
166
195
  # its repair is never to repair or restore a record that is not broken (D85, V3).
167
196
  #: (untyped, String) -> void
@@ -1,6 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "candidate_outline"
5
+
4
6
  module Principles
5
7
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
6
8
  module Models
@@ -8,7 +10,8 @@ module Principles
8
10
  # skill's templates, references and examples once filled most of a 10KB inventory (alpha 011
9
11
  # friction 2). So Markdown files and harness settings are listed one by one, except inside a skill,
10
12
  # where only SKILL.md, the file the harness loads, is listed. Every other file is counted under its
11
- # directory. The agent still sees where every file is, and decides what to read.
13
+ # directory. Explicit selections are always named, including skill references and non-Markdown text files.
14
+ # The agent still sees where every file is, and decides what to read.
12
15
  class CandidateFiles
13
16
  # A file a harness reads as settings, listed by name like guidance.
14
17
  SETTINGS = %r{(?:\A|/)\.claude/settings[^/]*\.json\z}
@@ -17,19 +20,35 @@ module Principles
17
20
  IN_SKILL = %r{(?:\A|/)\.claude/skills/[^/]+/}
18
21
  SKILL_ENTRY = %r{(?:\A|/)\.claude/skills/[^/]+/SKILL\.md\z}
19
22
 
20
- #: (Array[Hash[String, untyped]]) -> void
21
- def initialize(files)
23
+ #: (Array[Hash[String, untyped]], text_of: ^(String) -> String, ?selected: Array[String]) -> void
24
+ def initialize(files, text_of:, selected: [])
22
25
  @files = files #: Array[Hash[String, untyped]]
26
+ @text_of = text_of
27
+ @selected = selected
23
28
  freeze
24
29
  end
25
30
 
26
- # The inventory's files, the other files counted by directory, and those test-data hints that name a
27
- # listed file.
28
- #: (Array[Hash[String, untyped]]) -> Hash[String, untyped]
29
- def listing(test_data_hints)
30
- paths = listed.map { |file| file.fetch("path") }
31
- { "files" => listed, "other_files_by_directory" => other_files_by_directory,
32
- "possibly_test_data" => test_data_hints.select { |hint| paths.include?(hint.fetch("path")) } }
31
+ # The inventory's files, each Markdown one the survey reads with its outline, the other files counted by
32
+ # directory, and those test-data hints that name a listed file, whose files the survey leaves out unread (#1153).
33
+ # The files changed names, which a range of commits changed, list first, each marked changed_in_range (#1171).
34
+ #: (Array[Hash[String, untyped]], ?changed: Array[String]) -> Hash[String, untyped]
35
+ def listing(test_data_hints, changed: [])
36
+ outlines = outlines(test_data_hints)
37
+ files = listed.map do |file|
38
+ outline = outlines[file.fetch("path")]
39
+ outline ? file.merge(outline.to_h) : file
40
+ end
41
+ { "files" => changed_first(files, changed),
42
+ "other_files_by_directory" => other_files_by_directory, "possibly_test_data" => hints(test_data_hints) }
43
+ end
44
+
45
+ # The outline of each listed Markdown file the survey reads, by path: every one but those the test-data hints
46
+ # name (#1153), which the budget cuts by (#1155).
47
+ #: (Array[Hash[String, untyped]]) -> Hash[String, CandidateOutline]
48
+ def outlines(test_data_hints)
49
+ test_data = hints(test_data_hints).map { |hint| hint.fetch("path") }
50
+ paths = listed.map { |file| file.fetch("path") }.grep(MARKDOWN)
51
+ (paths - test_data).to_h { |path| [path, CandidateOutline.new(@text_of.call(path))] }
33
52
  end
34
53
 
35
54
  # Each Markdown or settings file, with its size.
@@ -49,6 +68,20 @@ module Principles
49
68
 
50
69
  private
51
70
 
71
+ # files with those changed names first, each marked changed_in_range, and the rest after, each in its order.
72
+ #: (Array[Hash[String, untyped]], Array[String]) -> Array[Hash[String, untyped]]
73
+ def changed_first(files, changed)
74
+ in_range, rest = files.partition { |file| changed.include?(file.fetch("path")) }
75
+ in_range.map { |file| file.merge("changed_in_range" => true) } + rest
76
+ end
77
+
78
+ # The test-data hints that name a listed file.
79
+ #: (Array[Hash[String, untyped]]) -> Array[Hash[String, untyped]]
80
+ def hints(test_data_hints)
81
+ paths = listed.map { |file| file.fetch("path") }
82
+ test_data_hints.select { |hint| paths.include?(hint.fetch("path")) }
83
+ end
84
+
52
85
  #: (String) -> String
53
86
  def directory(path)
54
87
  parent = path.rpartition("/").first
@@ -57,6 +90,7 @@ module Principles
57
90
 
58
91
  #: (String) -> bool
59
92
  def named?(path)
93
+ return true if @selected.include?(path)
60
94
  return path.match?(SKILL_ENTRY) if path.match?(IN_SKILL)
61
95
 
62
96
  path.match?(MARKDOWN) || path.match?(SETTINGS)
@@ -1,13 +1,17 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "candidate_listing"
4
+ require_relative "../data/project_files"
5
+ require_relative "candidate_files"
6
+ require_relative "ignored_candidates"
7
+ require_relative "outline_budget"
5
8
  require_relative "project_history"
9
+ require_relative "survey_search_paths"
6
10
 
7
11
  module Principles
8
12
  # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
13
  module Models
10
- # What list-candidate-files found: the inventory of candidate files as CandidateListing lists them, and in git
14
+ # What list-candidate-files found: the inventory of candidate files as it lists them, and in git
11
15
  # which of them, or of the files their links lead to, git does not track. Each list that names a file is
12
16
  # something the agent asks the project's owner about before mapping, and only those are asked, since asks for
13
17
  # empty lists hid the one that applied (#405).
@@ -19,14 +23,59 @@ module Principles
19
23
  # longer one would bury the ask, so the agent reads it from its list instead (#412).
20
24
  NAMED_INLINE_AT_MOST = 3
21
25
 
26
+ # What list-candidate-files finds in the project's files, each listed file's text read from them. After a commit,
27
+ # a full sha, the files its range changed come first, the Markdown ones outside the places hosts load listed too
28
+ # (#1171). The Markdown files not yet committed are named apart then, under uncommitted, since no commit in the
29
+ # range holds them.
30
+ #: (Data::ProjectFiles, ProjectHistory, search_paths: SurveySearchPaths, ?after: String?,
31
+ #| ?mapped: Array[String]) -> CandidateInventory
32
+ def self.read(files, history, search_paths:, after: nil, mapped: [])
33
+ changed = after ? history.changed_after(after) : []
34
+ inventory = files.inventory(also: changed.grep(CandidateFiles::MARKDOWN) | (changed & mapped),
35
+ matching: search_paths.globs).merge(search_paths.recorded_listing)
36
+ inventory = inventory.merge("uncommitted" => uncommitted_markdown(history)) if after
37
+ found(inventory, history, changed:) { |path| files.read_text(path) }
38
+ end
39
+
40
+ # An explicit file request uses the survey's entries and budget without its broad search.
41
+ #: (Data::ProjectFiles, ProjectHistory, paths: Array[String]) -> CandidateInventory
42
+ def self.requested(files, history, paths:)
43
+ found(files.requested_inventory(paths), history) { |path| files.read_text(path) }
44
+ end
45
+
46
+ # The Markdown files that differ from HEAD or are untracked, ignored ones aside.
47
+ #: (ProjectHistory) -> Array[String]
48
+ def self.uncommitted_markdown(history) = (history.uncommitted_outside([]) || []).grep(CandidateFiles::MARKDOWN)
49
+ private_class_method :uncommitted_markdown
50
+
22
51
  # What the project's inventory lists, and which listed files, or files their links lead to, history says
23
52
  # git does not track.
24
- #: (Hash[String, untyped], ProjectHistory) -> CandidateInventory
25
- def self.found(inventory, history)
26
- listed = CandidateListing.new(inventory).to_h
27
- new(listed, untracked: history.untracked(listed.fetch("files").map { it.fetch("path") }))
53
+ # Each listed file's text, which its outline is read from, is what the block gives for its path.
54
+ # changed names the files a range of commits changed, which list first, marked (#1171).
55
+ #: (Hash[String, untyped], ProjectHistory, ?changed: Array[String]) { (String) -> String } -> CandidateInventory
56
+ def self.found(inventory, history, changed: [], &text_of)
57
+ texts = {} #: Hash[String, String]
58
+ files = CandidateFiles.new(inventory.fetch("files"), selected: inventory.fetch("selected_files", []),
59
+ text_of: ->(path) { texts[path] ||= text_of.call(path) })
60
+ hints = inventory.fetch("possibly_test_data")
61
+ listed = listed(inventory, files.listing(hints, changed:))
62
+ new(listed, untracked: history.untracked(listed.fetch("files").map { it.fetch("path") }),
63
+ outlines: files.outlines(hints))
28
64
  end
29
65
 
66
+ # The inventory as list-candidate-files lists it: the instruction files agent hosts load by convention, the other
67
+ # files counted by directory, the listed files that look like test data, and in git the ignored ones, unread, each
68
+ # folder git ignores counted once.
69
+ #: (Hash[String, untyped], Hash[String, untyped]) -> Hash[String, untyped]
70
+ def self.listed(inventory, files_listing)
71
+ listed = inventory.except("ignored", "ignored_ancestor_folders", "selected_files").merge(files_listing)
72
+ return listed unless inventory.key?("ignored")
73
+
74
+ listed.merge(IgnoredCandidates.new(paths: inventory.fetch("ignored"),
75
+ folders: inventory.fetch("ignored_ancestor_folders")).listing)
76
+ end
77
+ private_class_method :listed
78
+
30
79
  # The listing, as list-candidate-files prints it.
31
80
  #: Hash[String, untyped]
32
81
  attr_reader :listing
@@ -36,10 +85,12 @@ module Principles
36
85
  #: Array[String]?
37
86
  attr_reader :untracked
38
87
 
39
- #: (Hash[String, untyped], untracked: Array[String]?) -> void
40
- def initialize(listing, untracked:)
88
+ # outlines holds each outlined file's outline, by path, which within_budget cuts by.
89
+ #: (Hash[String, untyped], untracked: Array[String]?, ?outlines: Hash[String, CandidateOutline]) -> void
90
+ def initialize(listing, untracked:, outlines: {})
41
91
  @listing = listing
42
92
  @untracked = untracked
93
+ @outlines = outlines
43
94
  @lists = listing.merge("untracked" => untracked) #: Hash[String, untyped]
44
95
  freeze
45
96
  end
@@ -47,6 +98,13 @@ module Principles
47
98
  #: () -> Hash[String, untyped]
48
99
  def to_h = @listing
49
100
 
101
+ # This inventory with its files' list items cut to OutlineBudget, the block giving the bytes each inventory tried
102
+ # prints as (#1155).
103
+ #: () { (CandidateInventory) -> Integer } -> CandidateInventory
104
+ def within_budget(&printed_bytes)
105
+ with(OutlineBudget.new(@outlines).cut(@listing) { |listing| printed_bytes.call(with(listing)) })
106
+ end
107
+
50
108
  # Each list that names a file, in OWNER_ASK_KEYS' order, with the paths its ask names inline: all of
51
109
  # them when there are at most NAMED_INLINE_AT_MOST, and none beyond.
52
110
  #: () -> Hash[String, Array[String]]
@@ -59,6 +117,9 @@ module Principles
59
117
 
60
118
  private
61
119
 
120
+ #: (Hash[String, untyped]) -> CandidateInventory
121
+ def with(listing) = CandidateInventory.new(listing, untracked: @untracked, outlines: @outlines)
122
+
62
123
  # The path one list entry names: a file's path, a folder, or the path itself.
63
124
  #: (untyped) -> String
64
125
  def named(entry) = entry.is_a?(Hash) ? entry.fetch("path") { entry.fetch("folder") } : entry
@@ -0,0 +1,195 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "frontmatter_fields"
6
+ require_relative "outline_group"
7
+ require_relative "outline_section"
8
+ require_relative "text_within"
9
+
10
+ module Principles
11
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
12
+ module Models
13
+ # One candidate file's outline, as the survey reads it in place of the file: its Markdown headings in order, and
14
+ # under each its top-level list items. The second alpha user scripted a heading grep over 45 files to survey them,
15
+ # and missed a principles section written as one numbered list, so this tool prints both (#1153).
16
+ class CandidateOutline
17
+ HEADING = /\A#+\s/
18
+ FENCE = /\A\s*(?:```|~~~)/
19
+ # A top-level list item, its marker and its text; an indented one is nested, and left out.
20
+ ITEM = /\A(\d+\.|[-*])\s+(.*)/
21
+ # A horizontal rule, such as `* * *` or `- - -`, which is no item.
22
+ RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
23
+ LINK = /\[([^\]]*)\]\([^)]*\)/
24
+ BOLD_LEAD = /\A\*\*[^*]+\*\*/
25
+ # The most characters of an item printed, cut back to a whole word.
26
+ ITEM_CHARACTERS = 60
27
+ # The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
28
+ # mid-clause left 30 of the second alpha user's 45 opening lines a fragment (#1155). The line is short only when
29
+ # its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
30
+ # accepted, since the file's path and outline still say what it holds.
31
+ OPENING_CHARACTERS = 160
32
+ # The cuts that shorten an outline to fit a budget, in the order they are made, each keeping those before it.
33
+ # The last leaves the whole outline out, which a big enough project needs once every other cut is made (#1155).
34
+ CUTS = %w[description items headings opening_line outline].freeze
35
+ # The cuts made on a root entry file, every one but the last, since a host loads it in every session.
36
+ ENTRY_FILE_CUTS = CUTS.length - 1 #: Integer
37
+ # The deepest heading level a cut outline keeps once its headings are folded.
38
+ FOLDED_BELOW = 2
39
+ # The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
40
+ # second alpha user's descriptions printed 12,537 B uncut, and suggested about 300 (22645b61, #1155).
41
+ DESCRIPTION_CHARACTERS = 300
42
+
43
+ # A description's key and any block scalar indicator, which its text starts after.
44
+ DESCRIPTION_KEY = /\Adescription:\s*(?:[>|][-+]?\s)?/
45
+ # A value inside a matching pair of quotes, printed without them; its escapes are left as written.
46
+ QUOTED = /\A(["'])(.*)\1\z/
47
+
48
+ #: (String) -> void
49
+ def initialize(text)
50
+ @lines = text.lines #: Array[String]
51
+ @frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
52
+ freeze
53
+ end
54
+
55
+ # The outline as the survey reads it: the whole frontmatter description and the opening line, each when the file
56
+ # has one, and the lines, with the first `cuts` of CUTS made.
57
+ #: (?cuts: Integer) -> Hash[String, untyped]
58
+ def to_h(cuts: 0)
59
+ return {} if left_out?(cuts)
60
+
61
+ { "description" => made?("description", cuts) ? cut_description : description,
62
+ "opening_line" => (opening_line unless made?("opening_line", cuts) && description),
63
+ "outline" => outline_lines(cuts) }.compact
64
+ end
65
+
66
+ # Whether the first `cuts` of CUTS cut the outline's lines, rather than only its description.
67
+ #: (Integer) -> bool
68
+ def outline_cut?(cuts) = made?("items", cuts)
69
+
70
+ # Whether the first `cuts` of CUTS leave the whole outline out, the file printing its path and size alone.
71
+ #: (Integer) -> bool
72
+ def left_out?(cuts) = made?("outline", cuts)
73
+
74
+ # Each line of the outline, as Markdown, leaving out what a code fence holds.
75
+ #: () -> Array[String]
76
+ def lines = sections.flat_map(&:lines)
77
+
78
+ # The outline with its list items cut, each heading that held some followed by how many (#1155).
79
+ #: () -> Array[String]
80
+ def cut_lines = sections.flat_map(&:cut_lines)
81
+
82
+ # Each heading with the items under it, and the items before the first heading when there are any, each with
83
+ # the lines of the file it spans.
84
+ #: () -> Array[OutlineSection]
85
+ def sections
86
+ body = unfenced
87
+ starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
88
+ starts.zip(starts.drop(1)).filter_map do |first, after|
89
+ section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ # The outline's lines with the first `cuts` of CUTS made: whole, with items cut, or with third-level and deeper
96
+ # headings folded into the heading above, whose 11,112 B kept the second alpha user's result over budget.
97
+ #: (Integer) -> Array[String]
98
+ def outline_lines(cuts)
99
+ return lines unless outline_cut?(cuts)
100
+ return cut_lines unless made?("headings", cuts)
101
+
102
+ groups.flat_map(&:folded_lines)
103
+ end
104
+
105
+ # Each section at FOLDED_BELOW or above, with the deeper sections after it; a file's first sections stand as a
106
+ # group of their own whatever their level.
107
+ #: () -> Array[OutlineGroup]
108
+ def groups
109
+ sections.slice_before { |section| section.level <= FOLDED_BELOW }
110
+ .map { |(section, *deeper)| OutlineGroup.new(section, deeper) }
111
+ end
112
+
113
+ # Whether the first `cuts` of CUTS include the one named.
114
+ #: (String, Integer) -> bool
115
+ def made?(cut, cuts) = CUTS.take(cuts).include?(cut)
116
+
117
+ # The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
118
+ # heading nor an item.
119
+ #: (Array[String], first_line: Integer) -> OutlineSection?
120
+ def section(lines, first_line:)
121
+ heading = lines.first if lines.first&.match?(HEADING)
122
+ items = lines.select { |line| item?(line) }.map { |line| item(line) }
123
+ return nil unless heading || items.any?
124
+
125
+ OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
126
+ end
127
+
128
+ # A top-level list item, not a horizontal rule written with the same marks.
129
+ #: (String) -> bool
130
+ def item?(line) = line.match?(ITEM) && !line.match?(RULE)
131
+
132
+ # The index in the file of the body's first line, after any frontmatter.
133
+ #: () -> Integer
134
+ def body_start = (@frontmatter.closing_line || -1) + 1
135
+
136
+ # The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
137
+ #: () -> String?
138
+ def description
139
+ written = @frontmatter.field_lines("$.description") or return nil
140
+ text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
141
+ text[QUOTED, 2] || text
142
+ rescue Error
143
+ nil
144
+ end
145
+
146
+ # The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
147
+ # characters it holds and the lines of the file that hold it, so the agent reads just those back (#1155).
148
+ #: () -> String?
149
+ def cut_description
150
+ text = description or return nil
151
+ within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
152
+ return text unless within.cut?
153
+
154
+ kept = within.kept
155
+ first, last = @frontmatter.field("$.description")
156
+ "#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
157
+ end
158
+
159
+ # The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
160
+ # joined, with links as their text. The first physical line was a fragment in a hard-wrapped file (#1155).
161
+ #: () -> String?
162
+ def opening_line
163
+ body = unfenced
164
+ first = body.index { |line| prose?(line) } or return nil
165
+ paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
166
+ TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
167
+ end
168
+
169
+ #: (String) -> bool
170
+ def prose?(line)
171
+ text = line.strip
172
+ !text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
173
+ end
174
+
175
+ # The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
176
+ #: () -> Array[String]
177
+ def unfenced
178
+ fenced = false #: bool
179
+ body = @lines.drop(body_start).map(&:chomp)
180
+ body.map do |line|
181
+ fenced = !fenced if line.match?(FENCE)
182
+ fenced || line.match?(FENCE) ? "" : line
183
+ end
184
+ end
185
+
186
+ # An item by its marker and its bold lead, or its opening words, with links as their text.
187
+ #: (String) -> String
188
+ def item(line)
189
+ marker, text = line.match(ITEM)&.captures
190
+ text = text.to_s.gsub(LINK, '\1')
191
+ "#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: ITEM_CHARACTERS).by_words}"
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,72 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../data/repository"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The commit first read by one command, including a captured absence. Later history reads share this baseline.
10
+ class CapturedHead
11
+ #: (Data::Repository) -> void
12
+ def initialize(repository)
13
+ @repository = repository
14
+ @commit = nil #: String?
15
+ @read = false #: bool
16
+ @verified = nil #: Data::VerifiedHead?
17
+ @ranges = {} #: Hash[[String?, String], Data::FirstParentRange]
18
+ end
19
+
20
+ #: () -> String?
21
+ def commit
22
+ return @commit if @read
23
+
24
+ @read = true
25
+ @commit = (@repository.head if @repository.inside?)
26
+ end
27
+
28
+ # Permission checks share the command's baseline, refusing disagreement with a prior best-effort read.
29
+ #: (String) -> bool
30
+ def entry?(path) = verified.entry?(path)
31
+
32
+ #: (String, String) -> bool
33
+ def entry_at?(revision, path) = verified.entry_at?(revision, path)
34
+
35
+ #: (String, String) -> Hash[String, String]?
36
+ def raw_entry_at(revision, path) = verified.raw_entry_at(revision, path)
37
+
38
+ # Cache constructed values by owned coordinates; each value certifies its span lazily when queried.
39
+ #: (String?, through: String) -> Data::FirstParentRange
40
+ def first_parent_range(base, through:)
41
+ captured = verified
42
+ lower = base&.dup&.freeze
43
+ upper = through.dup.freeze
44
+ key = [lower, upper].freeze
45
+ @ranges[key] ||= captured.first_parent_range(lower, through: upper)
46
+ end
47
+
48
+ #: (String) -> String?
49
+ def first_parent_of(revision) = verified.first_parent_of(revision)
50
+
51
+ #: (String, Array[String]) -> Array[String]
52
+ def commits_touching_since(base, paths) = verified.commits_touching_since(base, paths)
53
+
54
+ private
55
+
56
+ #: () -> Data::VerifiedHead
57
+ def verified
58
+ return @verified if @verified
59
+
60
+ captured = @repository.verified_head
61
+ revision = captured.commit
62
+ if @read && @commit != revision
63
+ raise Error.new("git_history_unavailable", "HEAD changed after this command captured its history",
64
+ "Stop concurrent Git writers and retry this command. No map was created or removed.")
65
+ end
66
+ @commit = revision
67
+ @read = true
68
+ @verified = captured
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,42 @@
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
+ # A carried member's kept assessment with the facts beside it that may mean the agent should judge it again
8
+ # (D49), and whether any fires, which decides whether a full audit's request prints the member whole or
9
+ # compactly (D93). Whether to judge it again stays the agent's.
10
+ class CarriedMember
11
+ # kept is the assessment carried forward as the request shows it, with evidence_changed;
12
+ # file_changed_outside_member says, in git, whether its file changed since the last full audit outside it, nil
13
+ # outside git; open_elsewhere, whether another principle leaves a finding open on a member sharing its lines
14
+ # (D62); open_here, the ids of the findings this principle leaves open on it.
15
+ #: (Hash[String, untyped], file_changed_outside_member: bool?, open_elsewhere: bool, open_here: Array[String])
16
+ #| -> void
17
+ def initialize(kept, file_changed_outside_member:, open_elsewhere:, open_here:)
18
+ @kept = kept
19
+ @file_changed_outside_member = file_changed_outside_member
20
+ @open_elsewhere = open_elsewhere
21
+ @open_here = open_here
22
+ freeze
23
+ end
24
+
25
+ # What the request lists of the member: its carried assessment with the git fact beside it, the findings this
26
+ # principle leaves open on it, if any, and whether a flag fires.
27
+ #: () -> Hash[String, untyped]
28
+ def shown
29
+ { "carried_forward" => @kept.merge({ "file_changed_outside_member" => @file_changed_outside_member }.compact),
30
+ **(@open_here.empty? ? {} : { "open_finding_ids" => @open_here }), "flagged" => fired? }
31
+ end
32
+
33
+ # Whether any flag fires: evidence the assessment cited changed, its file changed outside it, or a finding is
34
+ # open on its lines elsewhere (review F1) or here.
35
+ #: () -> bool
36
+ def fired?
37
+ @kept.fetch("evidence_changed") == true || @file_changed_outside_member == true || @open_elsewhere ||
38
+ @open_here.any?
39
+ end
40
+ end
41
+ end
42
+ end