principles 0.0.1 → 0.0.5

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 (197) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +10 -2
  3. data/lib/principles/command_line.rb +46 -35
  4. data/lib/principles/command_routes.rb +4 -3
  5. data/lib/principles/controllers/acknowledgement.rb +84 -18
  6. data/lib/principles/controllers/answer.rb +56 -125
  7. data/lib/principles/controllers/answer_phase.rb +54 -0
  8. data/lib/principles/controllers/assessment.rb +132 -0
  9. data/lib/principles/controllers/audit.rb +45 -140
  10. data/lib/principles/controllers/audit_completion.rb +8 -8
  11. data/lib/principles/controllers/command.rb +29 -14
  12. data/lib/principles/controllers/correction.rb +23 -13
  13. data/lib/principles/controllers/full_audit_request.rb +190 -0
  14. data/lib/principles/controllers/inventory.rb +46 -79
  15. data/lib/principles/controllers/mapping.rb +3 -3
  16. data/lib/principles/controllers/member_entries.rb +24 -12
  17. data/lib/principles/controllers/member_problems_report.rb +79 -0
  18. data/lib/principles/controllers/members_a_commit_changed.rb +12 -3
  19. data/lib/principles/controllers/members_to_assess.rb +35 -20
  20. data/lib/principles/controllers/meta_principle_setup.rb +5 -5
  21. data/lib/principles/controllers/repoint.rb +19 -23
  22. data/lib/principles/controllers/running_tool.rb +1 -1
  23. data/lib/principles/data/audit_files.rb +11 -7
  24. data/lib/principles/data/bounded_file.rb +20 -4
  25. data/lib/principles/data/command-steps.json +14 -13
  26. data/lib/principles/data/map_files.rb +2 -2
  27. data/lib/principles/data/principles_subfolder.rb +8 -1
  28. data/lib/principles/data/project_files.rb +12 -15
  29. data/lib/principles/data/project_root.rb +48 -0
  30. data/lib/principles/data/schema_check.rb +39 -11
  31. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
  32. data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
  33. data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
  34. data/lib/principles/data/schemas/audit-record.schema.json +13 -1
  35. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  36. data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
  37. data/lib/principles/invocation_options.rb +1 -1
  38. data/lib/principles/models/acknowledgement.rb +73 -84
  39. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  40. data/lib/principles/models/answer_place.rb +4 -0
  41. data/lib/principles/models/assessment_answer.rb +19 -17
  42. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  43. data/lib/principles/models/audit.rb +24 -15
  44. data/lib/principles/models/audit_record.rb +19 -20
  45. data/lib/principles/models/audit_records.rb +77 -4
  46. data/lib/principles/models/audit_start.rb +3 -3
  47. data/lib/principles/models/candidate_files.rb +30 -7
  48. data/lib/principles/models/candidate_inventory.rb +23 -6
  49. data/lib/principles/models/candidate_listing.rb +12 -3
  50. data/lib/principles/models/candidate_outline.rb +195 -0
  51. data/lib/principles/models/carried_assessments.rb +1 -1
  52. data/lib/principles/models/carried_member.rb +42 -0
  53. data/lib/principles/models/check_since_last_audit.rb +22 -9
  54. data/lib/principles/models/command_steps.rb +17 -1
  55. data/lib/principles/models/correction_basis.rb +1 -1
  56. data/lib/principles/models/decided_prior_findings.rb +9 -19
  57. data/lib/principles/models/declared_map_changes.rb +13 -12
  58. data/lib/principles/models/disposition.rb +28 -24
  59. data/lib/principles/models/evidence_replacements.rb +8 -1
  60. data/lib/principles/models/fix_only_fields.rb +67 -0
  61. data/lib/principles/models/frontmatter_fields.rb +9 -8
  62. data/lib/principles/models/instruction_named.rb +35 -0
  63. data/lib/principles/models/kept_prior_finding.rb +12 -7
  64. data/lib/principles/models/left_as_printed.rb +39 -0
  65. data/lib/principles/models/loaded_files.rb +5 -3
  66. data/lib/principles/models/loading_decision.rb +9 -2
  67. data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
  68. data/lib/principles/models/member.rb +1 -1
  69. data/lib/principles/models/member_assessments.rb +32 -9
  70. data/lib/principles/models/member_file.rb +35 -11
  71. data/lib/principles/models/member_grounds.rb +2 -2
  72. data/lib/principles/models/member_hashes_as_written.rb +44 -0
  73. data/lib/principles/models/member_lines.rb +63 -15
  74. data/lib/principles/models/member_moves.rb +3 -3
  75. data/lib/principles/models/member_problems.rb +50 -24
  76. data/lib/principles/models/member_repair_moves.rb +54 -0
  77. data/lib/principles/models/members_sharing_lines.rb +3 -3
  78. data/lib/principles/models/missing_files.rb +2 -2
  79. data/lib/principles/models/new_findings.rb +55 -0
  80. data/lib/principles/models/open_finding.rb +23 -13
  81. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  82. data/lib/principles/models/other_principles.rb +1 -1
  83. data/lib/principles/models/other_templates_placeholders.rb +113 -0
  84. data/lib/principles/models/outline_budget.rb +127 -0
  85. data/lib/principles/models/outline_group.rb +31 -0
  86. data/lib/principles/models/outline_section.rb +56 -0
  87. data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
  88. data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
  89. data/lib/principles/models/{map_members.rb → principle_members.rb} +15 -4
  90. data/lib/principles/models/prior_decision_fields.rb +47 -0
  91. data/lib/principles/models/prior_finding_decision.rb +38 -7
  92. data/lib/principles/models/prior_finding_outcomes.rb +10 -3
  93. data/lib/principles/models/prior_findings.rb +1 -1
  94. data/lib/principles/models/problem_report.rb +7 -3
  95. data/lib/principles/models/project.rb +22 -17
  96. data/lib/principles/models/project_history.rb +2 -2
  97. data/lib/principles/models/quoted_change.rb +137 -0
  98. data/lib/principles/models/recent_decision.rb +90 -0
  99. data/lib/principles/models/record_format.rb +109 -0
  100. data/lib/principles/models/recorded_entry.rb +6 -0
  101. data/lib/principles/models/recorded_finding.rb +4 -0
  102. data/lib/principles/models/recorded_hashes.rb +43 -0
  103. data/lib/principles/models/recorded_members.rb +33 -16
  104. data/lib/principles/models/refusal_before_shape.rb +21 -0
  105. data/lib/principles/models/repoint.rb +13 -0
  106. data/lib/principles/models/reported_check.rb +66 -24
  107. data/lib/principles/models/request_id.rb +24 -4
  108. data/lib/principles/models/sent_answer.rb +51 -0
  109. data/lib/principles/models/sent_prior_decisions.rb +31 -0
  110. data/lib/principles/models/shape_problems_beside.rb +40 -0
  111. data/lib/principles/models/still_holds_restatement.rb +7 -10
  112. data/lib/principles/models/submitted_answer.rb +34 -0
  113. data/lib/principles/models/template_placeholders.rb +71 -0
  114. data/lib/principles/models/text_within.rb +55 -0
  115. data/lib/principles/models/unchecked_members.rb +76 -0
  116. data/lib/principles/models/write_up_opening.rb +21 -4
  117. data/lib/principles/session_start_options.rb +29 -0
  118. data/lib/principles/start_audit_options.rb +52 -0
  119. data/lib/principles/version.rb +2 -2
  120. data/lib/principles/views/acknowledgement_result.rb +15 -7
  121. data/lib/principles/views/answer_head.rb +29 -0
  122. data/lib/principles/views/assessed_members.rb +129 -0
  123. data/lib/principles/views/assessment_request.rb +139 -78
  124. data/lib/principles/views/audit_result.rb +55 -42
  125. data/lib/principles/views/candidate_files_result.rb +41 -19
  126. data/lib/principles/views/check_notes.rb +44 -0
  127. data/lib/principles/views/check_result_template.rb +42 -30
  128. data/lib/principles/views/correction_request.rb +64 -0
  129. data/lib/principles/views/first_audit.rb +71 -0
  130. data/lib/principles/views/help.rb +3 -2
  131. data/lib/principles/views/instruction.rb +74 -0
  132. data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
  133. data/lib/principles/views/loads_to_check_result.rb +13 -6
  134. data/lib/principles/views/map_added_to.rb +31 -0
  135. data/lib/principles/views/map_result.rb +38 -23
  136. data/lib/principles/views/member_change_since_baseline.rb +22 -5
  137. data/lib/principles/views/member_repairs.rb +21 -52
  138. data/lib/principles/views/members_a_commit_changed.rb +40 -10
  139. data/lib/principles/views/meta_principle_result.rb +3 -14
  140. data/lib/principles/views/one_member_check_result_template.rb +43 -0
  141. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  142. data/lib/principles/views/open_findings_line.rb +77 -23
  143. data/lib/principles/views/principle_read_result.rb +37 -28
  144. data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
  145. data/lib/principles/views/prior_findings_result.rb +30 -18
  146. data/lib/principles/views/problem_lines.rb +14 -11
  147. data/lib/principles/views/problem_result.rb +30 -16
  148. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  149. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  150. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
  151. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  152. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  153. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +6 -17
  154. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
  155. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  156. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  157. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  158. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  159. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  160. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  161. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  162. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
  163. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  164. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +5 -4
  165. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  166. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  167. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
  168. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  169. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  170. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  171. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
  172. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
  173. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +21 -6
  174. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +25 -23
  175. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +18 -16
  176. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +4 -2
  177. data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
  178. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +7 -1
  179. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
  180. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +7 -6
  181. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
  182. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +30 -30
  183. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +39 -39
  184. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
  185. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  186. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
  187. data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
  188. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  189. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  190. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +11 -7
  191. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  192. data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
  193. data/lib/principles/views/request_part.rb +26 -6
  194. data/lib/principles/views/request_parts.rb +8 -0
  195. metadata +69 -9
  196. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  197. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -11,15 +11,15 @@ module Principles
11
11
  # by convention, the other files counted by directory, the listed files that look like test data, and in git
12
12
  # the ignored ones, unread, each folder git ignores counted once.
13
13
  class CandidateListing
14
- #: (Hash[String, untyped]) -> void
15
- def initialize(inventory)
14
+ #: (Hash[String, untyped], text_of: ^(String) -> String) -> void
15
+ def initialize(inventory, text_of:)
16
16
  @inventory = inventory
17
+ @text_of = text_of
17
18
  freeze
18
19
  end
19
20
 
20
21
  #: () -> Hash[String, untyped]
21
22
  def to_h
22
- files = CandidateFiles.new(@inventory.fetch("files"))
23
23
  listed = @inventory.except("ignored", "ignored_ancestor_folders")
24
24
  .merge(files.listing(@inventory.fetch("possibly_test_data")))
25
25
  return listed unless @inventory.key?("ignored")
@@ -27,6 +27,15 @@ module Principles
27
27
  listed.merge(IgnoredCandidates.new(paths: @inventory.fetch("ignored"),
28
28
  folders: @inventory.fetch("ignored_ancestor_folders")).listing)
29
29
  end
30
+
31
+ # The outline of each listed file the survey reads, by path.
32
+ #: () -> Hash[String, CandidateOutline]
33
+ def outlines = files.outlines(@inventory.fetch("possibly_test_data"))
34
+
35
+ private
36
+
37
+ #: () -> CandidateFiles
38
+ def files = CandidateFiles.new(@inventory.fetch("files"), text_of: @text_of)
30
39
  end
31
40
  end
32
41
  end
@@ -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
@@ -16,7 +16,7 @@ module Principles
16
16
  class CarriedAssessments
17
17
  # record is the principle's audit record now, if any; members are the map's members now, with their hashes in
18
18
  # now and their grounds; judged_against digests the description and question this audit asks.
19
- #: (AuditRecord?, members: MapMembers, judged_against: String, now: Hash[String, String],
19
+ #: (AuditRecord?, members: PrincipleMembers, judged_against: String, now: Hash[String, String],
20
20
  #| grounds: MemberGrounds) -> void
21
21
  def initialize(record, members:, judged_against:, now:, grounds:)
22
22
  @last = record&.last_completed #: AuditRecord?
@@ -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
@@ -4,8 +4,8 @@
4
4
  require_relative "../error"
5
5
  require_relative "audit_record"
6
6
  require_relative "member"
7
- require_relative "member_map_history"
8
- require_relative "member_maps"
7
+ require_relative "principle_history"
8
+ require_relative "mapped_principles"
9
9
  require_relative "project_history"
10
10
 
11
11
  module Principles
@@ -16,11 +16,11 @@ module Principles
16
16
  # committed map, and the audit asks the agent to run it, so a check no audit has seen needs a review
17
17
  # first (#227). This tool states the fact; the review is the agent's step.
18
18
  class CheckSinceLastAudit
19
- #: (id: String, history: ProjectHistory, member_maps: MemberMaps, record: AuditRecord?) -> void
20
- def initialize(id:, history:, member_maps:, record:)
19
+ #: (id: String, history: ProjectHistory, principles: MappedPrinciples, record: AuditRecord?) -> void
20
+ def initialize(id:, history:, principles:, record:)
21
21
  @id = id
22
22
  @history = history
23
- @member_maps = member_maps
23
+ @principles = principles
24
24
  @record = record
25
25
  freeze
26
26
  end
@@ -34,26 +34,39 @@ module Principles
34
34
  # changed_in may then name a later commit than the one that set the check: the review is still asked for.
35
35
  #: (Member, String) -> Hash[String, untyped]
36
36
  def of(member, check)
37
- ran = @record&.check_run_for(member.key)
37
+ status = status_of(member.key, check)
38
38
  review = review_of(member.key)
39
- return { "status" => "unchanged", **review } if ran == check
39
+ return { "status" => "unchanged", **review } if status == :unchanged
40
40
 
41
41
  changed_in = commit_that_set(member.key, check)
42
- return { "status" => "new", "changed_in" => changed_in } unless ran
42
+ return { "status" => "new", "changed_in" => changed_in } if %i[new not_run].include?(status)
43
43
 
44
+ ran = @record&.check_run_for(member.key)
44
45
  last_run_review = review.slice("review_basis").transform_keys { "last_run_review_basis" }
45
46
  { "status" => "changed", "last_run" => ran, **last_run_review, "changed_in" => changed_in }
46
47
  end
47
48
 
49
+ # The member's check and how it stands to the last audit's, as a request lists them beside the member; nothing
50
+ # for a member without a check.
51
+ #: (Member) -> Hash[String, untyped]
52
+ def entry(member)
53
+ check = member.check or return {}
54
+ { "check" => check, "check_since_last_audit" => of(member, check) }
55
+ end
56
+
48
57
  private
49
58
 
59
+ # How check stands to the one the last audit ran, as its record says; new when there is no record.
60
+ #: (String, String) -> Symbol
61
+ def status_of(key, check) = @record ? @record.members.check_since(key, check) : :new
62
+
50
63
  # The line the last audit's record keeps for what the review of its run rested on, and since when (D63).
51
64
  #: (String) -> Hash[String, untyped]
52
65
  def review_of(key) = @record&.check_review_for(key) || {}
53
66
 
54
67
  #: (String, String) -> String?
55
68
  def commit_that_set(key, check)
56
- run = MemberMapHistory.new(id: @id, history: @history, member_maps: @member_maps).runs([key]).fetch(key)
69
+ run = PrincipleHistory.new(id: @id, history: @history, principles: @principles).runs([key]).fetch(key)
57
70
  run.take_while { |_sha, fields| Member.new(fields).check == check }.last&.first
58
71
  end
59
72
  end
@@ -133,6 +133,9 @@ module Principles
133
133
  # The named options it takes, without their dashes, besides --project and --help.
134
134
  #: Array[String]
135
135
  attr_reader :options
136
+ # The named options it cannot run without, which the command line refuses together with any missing argument.
137
+ #: Array[String]
138
+ attr_reader :requires
136
139
  #: String
137
140
  attr_reader :summary
138
141
  #: String
@@ -146,6 +149,7 @@ module Principles
146
149
  @usage = data.fetch("usage") #: String
147
150
  @group = data.fetch("group") #: String
148
151
  @options = data.fetch("options").freeze #: Array[String]
152
+ @requires = data.fetch("requires", []).freeze #: Array[String]
149
153
  @summary = data.fetch("summary") #: String
150
154
  @help = data.fetch("help") #: String
151
155
  @steps = steps.freeze #: Array[Step]
@@ -162,6 +166,17 @@ module Principles
162
166
  following ? [following] : []
163
167
  end
164
168
 
169
+ # The first rule of its own entry the command breaks, or nil when it keeps them all.
170
+ #: () -> String?
171
+ def fault
172
+ ids = @steps.map(&:id)
173
+ return "#{@name} repeats a step id" unless ids.uniq == ids
174
+
175
+ # The command line refuses an option a command does not take, so it could never be given.
176
+ untaken = @requires - @options
177
+ "#{@name} requires #{untaken.join(", ")}, which it does not take" if untaken.any?
178
+ end
179
+
165
180
  #: (String) -> Step
166
181
  def find(id)
167
182
  @steps.find { |step| step.id == id } || raise(KeyError, "#{@name} has no step #{id}")
@@ -244,8 +259,9 @@ module Principles
244
259
  #: (Command, Array[String]) -> void
245
260
  def check_command(command, names)
246
261
  writes(command)
262
+ fault = command.fault
263
+ refuse(fault) if fault
247
264
  ids = command.steps.map(&:id)
248
- refuse("#{command.name} repeats a step id") unless ids.uniq == ids
249
265
  command.steps.each { |step| check_step("#{command.name}/#{step.id}", step, names, ids) }
250
266
  end
251
267
 
@@ -58,7 +58,7 @@ module Principles
58
58
  # The id of the correction request of principle_id for this basis, with each member's hash when the audit began.
59
59
  #: (String, Hash[String, String]) -> RequestId
60
60
  def request_id(principle_id, before)
61
- RequestId.for(principle_id: principle_id, phase: "correction", parts: [@fields, before])
61
+ RequestId.handing_back(principle_id: principle_id, phase: "correction", handed: @fields, parts: [before])
62
62
  end
63
63
 
64
64
  # The last completed record's revision when the request was printed, which refuses a correction once that
@@ -54,25 +54,15 @@ module Principles
54
54
  #: () -> Array[String]
55
55
  def resolved_ids = closed.select { |each| each["decision"] == "resolved" }.map { |each| each.fetch("finding_id") }
56
56
 
57
- # Each kept finding whose pointer its decision dropped with null, with the pointer it had (#374). A
58
- # correction basis printed before this was built carries none.
59
- #: () -> Array[Hash[String, untyped]]
60
- def dropped
61
- @fields.fetch("dropped", [])
62
- end
63
-
64
- # Each kept finding whose waits_on its decision dropped, with null or by accepting it, with the line and since
65
- # it had (D52). A correction basis printed before this was built carries none.
66
- #: () -> Array[Hash[String, untyped]]
67
- def waits_on_dropped
68
- @fields.fetch("waits_on_dropped", [])
69
- end
70
-
71
- # Each kept evidence item a still_holds decision gave a new place, as it was and is now (D70). A correction
72
- # basis printed before this was built carries none.
73
- #: () -> Array[Hash[String, untyped]]
74
- def evidence_replaced
75
- @fields.fetch("evidence_replaced", [])
57
+ # What the decisions changed of the findings kept, each list by the name the completed result gives it after
58
+ # prior_findings_: each pointer a decision dropped with null, with the pointer it had (#374); each waits_on it
59
+ # dropped, with null or by accepting it, with the line and since it had (D52); each kept evidence item it gave a
60
+ # new place (D70); and each problem it restated (D82), each as it was and is now. A correction basis printed
61
+ # before a list was built carries none of it.
62
+ #: () -> Hash[String, Array[Hash[String, untyped]]]
63
+ def changed
64
+ { "pointers_dropped" => @fields.fetch("dropped", []),
65
+ **%w[waits_on_dropped evidence_replaced problems_restated].to_h { |name| [name, @fields.fetch(name, [])] } }
76
66
  end
77
67
 
78
68
  # When the prior finding that the new finding id raises again was first raised, or nothing.
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
- require_relative "member_map"
5
+ require_relative "principle"
6
6
  require_relative "member_moves"
7
7
 
8
8
  module Principles
@@ -36,7 +36,7 @@ module Principles
36
36
  # The base commit, to read there the map the audit began from, or nil when nothing is declared and current is
37
37
  # still at map_version, the version the audit began from. Outside git, a map that changed is refused, as are
38
38
  # declared changes, since there is no base map to check them against.
39
- #: (String?, MemberMap, map_version: String, map_file: String) -> String?
39
+ #: (String?, Principle, map_version: String, map_file: String) -> String?
40
40
  def base_to_read(base, current, map_version:, map_file:)
41
41
  return check_in_git(base, principle_id: current.id) unless empty?
42
42
  return if current.version == map_version
@@ -59,7 +59,7 @@ module Principles
59
59
 
60
60
  # Refuses unless base is the map the audit began from and current is base with exactly the declared
61
61
  # members moved, the claimed members' role and check changed, and any members added (T69).
62
- #: (MemberMap, MemberMap, map_version: String, map_file: String) -> void
62
+ #: (Principle, Principle, map_version: String, map_file: String) -> void
63
63
  def check(base, current, map_version:, map_file:)
64
64
  raise unexplained(current.id, map_file) unless base.version == map_version
65
65
 
@@ -70,7 +70,7 @@ module Principles
70
70
  # Each claimed member's role and check, as was and now, where they differ between the base map with the
71
71
  # declared moves applied, which check compares, and current. The block gives [base, current], and is
72
72
  # called only when a fix claims an entry, so nothing else reads the base map (#462).
73
- #: () { () -> [MemberMap, MemberMap] } -> Array[Hash[String, untyped]]
73
+ #: () { () -> [Principle, Principle] } -> Array[Hash[String, untyped]]
74
74
  def entry_changes(&)
75
75
  return [] if @entries.empty?
76
76
 
@@ -79,17 +79,17 @@ module Principles
79
79
  @entries.map { |id| changed_fields(id, moved.member(id), current.member(id)) }
80
80
  end
81
81
 
82
- # The map file, when a fix changed a member's role or check in it or the correction added members to it, so the
83
- # agent commits it too (T69).
82
+ # The map file, when the correction moved a member in it, even under its own id (#1100), a fix changed a
83
+ # member's role or check in it, or the correction added members to it, so the agent commits it too (T69).
84
84
  #: (String, ?added: Array[String]) -> Array[String]
85
85
  def files_to_commit(map_file, added: [])
86
- @entries.empty? && added.empty? ? [] : [map_file]
86
+ empty? && added.empty? ? [] : [map_file]
87
87
  end
88
88
 
89
89
  private
90
90
 
91
91
  # expected with each member of current whose id it lacks added, as add-member adds it.
92
- #: (MemberMap, MemberMap) -> MemberMap
92
+ #: (Principle, Principle) -> Principle
93
93
  def with_added(expected, current)
94
94
  added = current.members.ids - expected.members.ids
95
95
  added.reduce(expected) { |map, id| map.adding(current.member(id)) }
@@ -102,7 +102,7 @@ module Principles
102
102
 
103
103
  # The map with the claimed member's role and check as current holds them, refused when they are as
104
104
  # they were at the base commit.
105
- #: (MemberMap, MemberMap, String) -> MemberMap
105
+ #: (Principle, Principle, String) -> Principle
106
106
  def claimed_entry(map, current, id)
107
107
  unless current.members.taken?(id)
108
108
  raise Error.new("unknown_member", "#{id} is not a member of #{current.id}",
@@ -118,7 +118,7 @@ module Principles
118
118
 
119
119
  # The map with the member's role and check changed to now's, as change-member-role, change-member-check
120
120
  # and remove-member-check changed them.
121
- #: (MemberMap, String, Hash[String, untyped]) -> MemberMap
121
+ #: (Principle, String, Hash[String, untyped]) -> Principle
122
122
  def replayed(map, id, now)
123
123
  roled = map.changing_role(id, now.fetch("role"))
124
124
  return roled.changing_check(id, now.fetch("check")) if now.key?("check")
@@ -132,7 +132,7 @@ module Principles
132
132
  { "member_id" => id, **changed.to_h { |field| [field, { "was" => was[field], "now" => now[field] }] } }
133
133
  end
134
134
 
135
- #: (MemberMap, MemberMap, String) -> bool
135
+ #: (Principle, Principle, String) -> bool
136
136
  def as_at_base?(map, current, id)
137
137
  map.member(id).slice("role", "check") == current.member(id).slice("role", "check")
138
138
  end
@@ -146,7 +146,8 @@ module Principles
146
146
  def stale_map(principle_id, map_file)
147
147
  Error.new("stale_map", "The map of #{principle_id} changed during this audit",
148
148
  "If you moved a member to fix a finding, declare it in the answer's moved_members as " \
149
- "{\"from\": OLD_ID, \"to\": NEW_ID}; if a fix changed a member's role or check, list the " \
149
+ "{\"from\": OLD_ID, \"to\": NEW_ID}, and a move that kept its id, as narrowing or widening a " \
150
+ "passage, as {\"from\": ID, \"to\": ID}; if a fix changed a member's role or check, list the " \
150
151
  "member's id in that fixed disposition's changed_map_entries. In git, a member you added with " \
151
152
  "add-member needs no declaration, as long as nothing else changed.\n" \
152
153
  "Otherwise, start a fresh audit: #{Error::EXECUTABLE} start-audit #{principle_id}", map_file)