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
@@ -28,14 +28,14 @@ module Principles
28
28
  freeze
29
29
  end
30
30
 
31
- # The finding as list-open-findings prints it, with its principle, when its audit was made and when it was
32
- # first raised, so how long it has waited shows (#629), what it says it waits on, since when (D52), and the
33
- # evidence its record keeps, or that it keeps none (D64, #839).
31
+ # The finding as list-open-findings prints it, with its principle, why it was left open (#996), when its audit
32
+ # was made and when it was first raised, so how long it has waited shows (#629), what it says it waits on, since
33
+ # when (D52), and the evidence its record keeps, or that it keeps none (D64, #839).
34
34
  #: () -> Hash[String, untyped]
35
35
  def listed
36
36
  { "principle" => @principle_id, "finding_id" => id, "member_ids" => @finding.member_ids, **problem,
37
- "action" => @finding.action, "recorded_at" => recorded_at&.to_h, "audited_at" => @audited_at,
38
- "first_raised_at" => first_raised_at, **raised_in, **waiting, **kept_evidence }
37
+ "action" => @finding.action, **present("reason", @finding.reason), "recorded_at" => recorded_at&.to_h,
38
+ "audited_at" => @audited_at, "first_raised_at" => first_raised_at, **raised_in, **waiting, **kept_evidence }
39
39
  end
40
40
 
41
41
  # The finding as the next full audit's request lists it, with when it was first raised, and what it waits on,
@@ -52,7 +52,7 @@ module Principles
52
52
  # now, hashes_now: under its members' ids now, with whether each changed since the audit that left it open,
53
53
  # what its record did not keep of it, and the evidence it keeps, so the agent deciding it sees what it rests on
54
54
  # (#839). Given since, each evidence item also carries what since says of it now (#858, #877).
55
- #: (MapMembers, Hash[String, String]) ?{ (EvidenceItem) -> Hash[String, bool] }
55
+ #: (PrincipleMembers, Hash[String, String]) ?{ (EvidenceItem) -> Hash[String, bool] }
56
56
  #| -> Hash[String, untyped]
57
57
  def for_next_audit_against(members_now, hashes_now, &)
58
58
  finding = for_next_audit
@@ -63,11 +63,13 @@ module Principles
63
63
  end
64
64
 
65
65
  # The finding as the next full audit's record keeps it, before that audit's decision on it: under its members'
66
- # ids now, with its write-up, when it was first raised and the commit an earlier first_raised_at cited (D53).
67
- #: (MapMembers) -> Hash[String, untyped]
66
+ # ids now, with why it was left open (#996), its write-up, when it was first raised and the commit an earlier
67
+ # first_raised_at cited (D53).
68
+ #: (PrincipleMembers) -> Hash[String, untyped]
68
69
  def kept_against(members_now)
69
70
  { "id" => id, "member_ids" => ids_now(members_now), **problem, "action" => @finding.action,
70
- **present("recorded_at", recorded_at&.to_h), "first_raised_at" => first_raised_at, **raised_in }
71
+ **present("reason", @finding.reason), **present("recorded_at", recorded_at&.to_h),
72
+ "first_raised_at" => first_raised_at, **raised_in }
71
73
  end
72
74
 
73
75
  # The principle whose record left it open.
@@ -95,13 +97,21 @@ module Principles
95
97
  #: () -> Array[Hash[String, untyped]]?
96
98
  def evidence = @finding.evidence
97
99
 
100
+ # The problem it states, and the one a still_holds decision gives in its place, as the completed result names
101
+ # them, or nil when the decision gives none, its record states none or the two are the same (D82).
102
+ #: (String?) -> Hash[String, String]?
103
+ def restated(problem)
104
+ stated = @finding.problem
105
+ { "finding_id" => id, "replaced" => stated, "with" => problem } if stated && problem && problem != stated
106
+ end
107
+
98
108
  # Whether its record keeps the evidence it was raised with (D64).
99
109
  #: () -> bool
100
110
  def evidence_kept? = @finding.evidence_kept?
101
111
 
102
112
  # The ids now, as the next full audit's request lists them, of its members no longer in the map, which its
103
113
  # members_since calls removed.
104
- #: (MapMembers) -> Array[String]
114
+ #: (PrincipleMembers) -> Array[String]
105
115
  def removed_from(members_now) = ids_now(members_now).reject { |member_id| members_now.with_id(member_id) }
106
116
 
107
117
  # The new places a decision's problem_evidence gives the evidence its record keeps, so the check that an item is
@@ -170,13 +180,13 @@ module Principles
170
180
  private
171
181
 
172
182
  # Its members' ids now, each member found by key so a member renamed since keeps its new id (#772).
173
- #: (MapMembers) -> Array[String]
183
+ #: (PrincipleMembers) -> Array[String]
174
184
  def ids_now(members_now) = @finding.member_ids.map { |id| id_now(members_now, @members.key_of(id)) || id }
175
185
 
176
- #: (MapMembers, String) -> String?
186
+ #: (PrincipleMembers, String) -> String?
177
187
  def id_now(members_now, key) = members_now.with_key(key)&.id
178
188
 
179
- #: (MapMembers, Hash[String, String], String) -> String
189
+ #: (PrincipleMembers, Hash[String, String], String) -> String
180
190
  def since_this_audit(members_now, hashes_now, id)
181
191
  member = members_now.with_id(id) or return "removed"
182
192
  @members.freshness(member.key, hashes_now.fetch(id))
@@ -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.
@@ -15,7 +15,7 @@ module Principles
15
15
  # cannot read is among them, as list-member-problems lists it.
16
16
  #: (Project, but: String) -> OtherPrinciples
17
17
  def self.of(project, but:)
18
- new((project.member_maps.ids - [but]).to_h { [it, MemberProblems.for(project, it, listing_all: true)] })
18
+ new((project.principles.ids - [but]).to_h { [it, MemberProblems.for(project, it, listing_all: true)] })
19
19
  end
20
20
 
21
21
  # problems maps each principle's id to its members' problems.
@@ -0,0 +1,113 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
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"
15
+
16
+ module Principles
17
+ module Models
18
+ # The text in an answer that ends as this tool's placeholders end, "Leave as printed ...", "else leave" or "else
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.
24
+ class OtherTemplatesPlaceholders
25
+ include RefusalBeforeShape
26
+
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
41
+
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
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
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)
76
+ end
77
+
78
+ # printed is the placeholders the request's own template printed, which an answer may leave as printed.
79
+ #: (Array[String]) -> void
80
+ def initialize(printed)
81
+ @printed = printed
82
+ end
83
+
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
91
+ return if found.empty?
92
+
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)
97
+ end
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
+
104
+ PROBLEM = "ends as a placeholder does, but is none this request's template printed" #: String
105
+
106
+ private
107
+
108
+ # Whether text ends as a placeholder does, or is one another template prints, but is none printed.
109
+ #: (String) -> bool
110
+ def other?(text) = (text.match?(ENDING) || KNOWN.include?(text)) && !@printed.include?(text)
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,127 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "candidate_outline"
6
+ require_relative "entry_files"
7
+
8
+ module Principles
9
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # How much list-candidate-files may print: its listed files' outlines, cut a whole file's list items at a time
12
+ # until the result fits. The second alpha user's run printed 66,145 B for 45 files, against a ceiling of about
13
+ # 37 KB, and no cap on items under each heading both fitted and kept a core list of 8 whole (#1155).
14
+ class OutlineBudget
15
+ # The most bytes the result may print, under the host's inline limit for a tool result. Claude Code's tools
16
+ # reference, "Output limits" (code.claude.com/docs/en/tools-reference, checked 2026-11-16), gives a Bash result
17
+ # inline "up to roughly 30,000 characters by default; past that, the path of a file" and a 2,000-character
18
+ # preview. The second alpha user's 40.4 KB result arrived that way, and its agent scripted over the saved file
19
+ # (22645b61, #1155). A character is at least a byte, so 28,000 B stays under 30,000 characters with room.
20
+ BYTES = 28_000
21
+
22
+ # The fields of a file's entry its outline gives, which a cut replaces.
23
+ OUTLINE_FIELDS = %w[description opening_line outline].freeze
24
+
25
+ # The lists naming the files cut: those whose outline's lines were cut, and those whose whole outline was.
26
+ NAMING_LISTS = %w[outlines_cut outlines_left_out].freeze
27
+
28
+ # Each outlined file's outline, by path.
29
+ #: (Hash[String, CandidateOutline]) -> void
30
+ def initialize(outlines)
31
+ @outlines = outlines
32
+ freeze
33
+ end
34
+
35
+ # The listing with its files' outlines cut, one cut of one file at a time in cut order, until what the block says
36
+ # it prints fits BYTES, each file whose items were cut named under outlines_cut. If every cut is made and it
37
+ # still does not fit, every file cut is named.
38
+ #: (Hash[String, untyped]) { (Hash[String, untyped]) -> Integer } -> Hash[String, untyped]
39
+ def cut(listing, &printed_bytes)
40
+ cut_order(listing).reduce(listing) do |shorter, (path, cuts)|
41
+ return shorter if printed_bytes.call(shorter) <= BYTES
42
+
43
+ cut_file(shorter, path, cuts)
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ # Each cut that shortens a file, as its path and how many of CandidateOutline::CUTS it then has made. Every file
50
+ # but the root entry files comes first, since a host loads those in every session, so they keep theirs longest,
51
+ # in EntryFiles' order. Within each group, each cut is made across the files in CUTS' order: those with a
52
+ # description first, since the agent still reads what each is for, then the deepest path, then the most bytes
53
+ # the cut saves (#1155, review F5).
54
+ #: (Hash[String, untyped]) -> Array[[String, Integer]]
55
+ def cut_order(listing)
56
+ outlined = listing.fetch("files").select { |file| @outlines.key?(file.fetch("path")) }
57
+ outlined.group_by { |file| entry_rank(file.fetch("path")) }.sort.flat_map do |rank, files|
58
+ (1..most_cuts(rank)).flat_map { |cuts| cuts_across(files, cuts) }
59
+ end
60
+ end
61
+
62
+ # How many of CUTS are made on a file of this entry rank: on an entry file every one but leaving its outline out.
63
+ #: (Integer) -> Integer
64
+ def most_cuts(rank) = rank.zero? ? CandidateOutline::CUTS.length : CandidateOutline::ENTRY_FILE_CUTS
65
+
66
+ # The files the cuts'th cut shortens, in the order it is made across them.
67
+ #: (Array[Hash[String, untyped]], Integer) -> Array[[String, Integer]]
68
+ def cuts_across(files, cuts)
69
+ files.select { |file| saved(file.fetch("path"), cuts).positive? }
70
+ .sort_by { |file| cut_rank(file, cuts) }.map { |file| [file.fetch("path"), cuts] }
71
+ end
72
+
73
+ # Where a file comes among those one cut shortens: described or not, depth, bytes saved, then path.
74
+ #: (Hash[String, untyped], Integer) -> [Integer, Integer, Integer, String]
75
+ def cut_rank(file, cuts)
76
+ path = file.fetch("path")
77
+ [file.key?("description") ? 0 : 1, -path.count("/"), -saved(path, cuts), path]
78
+ end
79
+
80
+ # 0 for a file that is not a root entry file, then each entry file in EntryFiles::PATHS reversed, so the first,
81
+ # CLAUDE.md, keeps its items longest.
82
+ #: (String) -> Integer
83
+ def entry_rank(path)
84
+ index = EntryFiles::PATHS.index(path) or return 0
85
+
86
+ EntryFiles::PATHS.length - index
87
+ end
88
+
89
+ # The bytes the cuts'th cut of path's outline saves over the cuts made before it.
90
+ #: (String, Integer) -> Integer
91
+ def saved(path, cuts)
92
+ outline = @outlines.fetch(path)
93
+ JSON.generate(outline.to_h(cuts: cuts - 1)).bytesize - JSON.generate(outline.to_h(cuts:)).bytesize
94
+ end
95
+
96
+ # The listing with path's outline cut to its first `cuts` cuts, and the file named as its cuts say.
97
+ #: (Hash[String, untyped], String, Integer) -> Hash[String, untyped]
98
+ def cut_file(listing, path, cuts)
99
+ outline = @outlines.fetch(path)
100
+ files = listing.fetch("files").map do |file|
101
+ file.fetch("path") == path ? file.except(*OUTLINE_FIELDS).merge(outline.to_h(cuts:)) : file
102
+ end
103
+ named(listing.merge("files" => files), path, outline, cuts)
104
+ end
105
+
106
+ # The listing naming path under outlines_cut once its outline's lines are cut, and under outlines_left_out instead
107
+ # once its whole outline is; a cut description says so in its own text. A list that names no path is left out.
108
+ #: (Hash[String, untyped], String, CandidateOutline, Integer) -> Hash[String, untyped]
109
+ def named(listing, path, outline, cuts)
110
+ named_in = naming_list(outline, cuts)
111
+ lists = NAMING_LISTS.to_h do |list|
112
+ [list, listing.fetch(list, []) - [path] + (list == named_in ? [path] : [])]
113
+ end
114
+ listing.except(*NAMING_LISTS).merge(lists.reject { |_, paths| paths.empty? })
115
+ end
116
+
117
+ # The one of NAMING_LISTS a file with these cuts made belongs in, the whole outline left out moving it from the
118
+ # first to the second; nil while only its description is cut.
119
+ #: (CandidateOutline, Integer) -> String?
120
+ def naming_list(outline, cuts)
121
+ return "outlines_left_out" if outline.left_out?(cuts)
122
+
123
+ "outlines_cut" if outline.outline_cut?(cuts)
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,31 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "outline_section"
5
+
6
+ module Principles
7
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # One section of a candidate file's outline and the deeper sections under it, which a cut outline folds into it
10
+ # once its headings are cut too (#1155).
11
+ class OutlineGroup
12
+ #: (OutlineSection, Array[OutlineSection]) -> void
13
+ def initialize(section, deeper)
14
+ @section = section
15
+ @deeper = deeper
16
+ freeze
17
+ end
18
+
19
+ # The group as a cut outline prints it once its deeper headings are folded: the section's heading, then how many
20
+ # items it and they hold under how many headings, and the lines they span.
21
+ #: () -> Array[String]
22
+ def folded_lines
23
+ last = @deeper.last or return @section.cut_lines
24
+
25
+ items = @section.item_count + @deeper.sum(&:item_count)
26
+ headings = "#{@deeper.length} heading#{"s" unless @deeper.one?}"
27
+ [*@section.heading, "(#{items} more under #{headings}, lines #{@section.first_line}-#{last.last_line})"]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,56 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # One heading of a candidate file's outline and the top-level list items under it, with the lines of the file it
8
+ # spans, so an outline whose items are cut can say where to read them back (#1155).
9
+ class OutlineSection
10
+ # The most items printed under one heading; a longer list says how many more it holds.
11
+ MOST_ITEMS = 20
12
+ # A heading's marks, as many as its level.
13
+ MARKS = /\A#+/
14
+
15
+ # The heading as Markdown; nil for the items before a file's first heading.
16
+ #: String?
17
+ attr_reader :heading
18
+
19
+ # The file's lines the section spans, from its heading, counted from 1.
20
+ #: Integer
21
+ attr_reader :first_line
22
+
23
+ #: Integer
24
+ attr_reader :last_line
25
+
26
+ # The heading's level, its number of #s; 0 for the items before a file's first heading.
27
+ #: Integer
28
+ attr_reader :level
29
+
30
+ #: (heading: String?, items: Array[String], first_line: Integer, last_line: Integer) -> void
31
+ def initialize(heading:, items:, first_line:, last_line:)
32
+ @heading = heading
33
+ @level = heading.to_s[MARKS].to_s.length #: Integer
34
+ @items = items
35
+ @first_line = first_line
36
+ @last_line = last_line
37
+ freeze
38
+ end
39
+
40
+ # The section as the outline prints it: its heading, its items up to MOST_ITEMS, then how many more.
41
+ #: () -> Array[String]
42
+ def lines
43
+ more = @items.length - MOST_ITEMS
44
+ [*@heading, *@items.first(MOST_ITEMS), *("(#{more} more)" if more.positive?)]
45
+ end
46
+
47
+ # The section as a cut outline prints it: its heading, then, if it holds items, how many and the lines of the file
48
+ # that hold them, so the agent reads just that section back (#1155, review F2).
49
+ #: () -> Array[String]
50
+ def cut_lines = [*@heading, *("(#{@items.length} more, lines #{@first_line}-#{@last_line})" if @items.any?)]
51
+
52
+ #: () -> Integer
53
+ def item_count = @items.length
54
+ end
55
+ end
56
+ end
@@ -5,7 +5,7 @@ require "json"
5
5
  require_relative "../error"
6
6
  require_relative "../data/schema_check"
7
7
  require_relative "member"
8
- require_relative "map_members"
8
+ require_relative "principle_members"
9
9
  require_relative "activation"
10
10
  require_relative "json_digest"
11
11
  require_relative "meta_principle"
@@ -13,21 +13,21 @@ require_relative "meta_principle"
13
13
  module Principles
14
14
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
15
15
  module Models
16
- # One principle's member map: the principle it names and the members that reinforce it, each a project
17
- # file or a place in one, with the role it plays. Every change returns a new map and leaves this one as
18
- # it was; MemberMaps saves it. Fields the map holds beyond these are kept as they are.
19
- class MemberMap
16
+ # One principle: its id, description and activation, and the members that reinforce it, each a project file
17
+ # or a place in one, with the role it plays. Its map file holds it. Every change returns a new principle and
18
+ # leaves this one as it was; MappedPrinciples saves it. Fields its map holds beyond these are kept as they are.
19
+ class Principle
20
20
  #: String
21
21
  attr_reader :id
22
22
 
23
23
  #: (String, Hash[String, untyped]) -> void
24
24
  def initialize(id, fields)
25
25
  @id = id
26
- # The map owns its data: every field, an unknown one too, is copied and frozen down to each string, so no
26
+ # The principle owns its data: every field, an unknown one too, is copied and frozen down to each string, so no
27
27
  # change made in place to what it was built from or what it hands out changes its file or version (#648,
28
28
  # #654). The copy goes through the JSON its version digests, which a map's file holds anyway.
29
29
  owned = JSON.parse(JSON.generate(fields), freeze: true) #: Hash[String, untyped]
30
- @members = MapMembers.new(id, owned.fetch("members").map { |each| Member.new(each) }) #: MapMembers
30
+ @members = PrincipleMembers.new(id, owned.fetch("members").map { |each| Member.new(each) }) #: PrincipleMembers
31
31
  @fields = owned.merge("members" => @members.map(&:to_h).freeze).freeze #: Hash[String, untyped]
32
32
  freeze
33
33
  end
@@ -38,7 +38,7 @@ module Principles
38
38
  end
39
39
 
40
40
  # Its members as Member values, which say each one's id, key, place and check.
41
- #: MapMembers
41
+ #: PrincipleMembers
42
42
  attr_reader :members
43
43
 
44
44
  # Each member in one of paths, by its id and path, as show-meta-principle-passage reports the members already in
@@ -59,20 +59,25 @@ module Principles
59
59
  #: () -> bool
60
60
  def keeps_others_held? = meta_principle?
61
61
 
62
- # Whether this is the meta-principle's map with no members, as a setup that wrote its map before the first
63
- # member, or removing its last member, leaves it. Only this map's having none is out of the way: setup no longer
64
- # writes it, and its first add-member creates it with that member (T74), while any other principle has none from
65
- # create-principle until its first add-member (#931).
62
+ # Whether this is the meta-principle with no members, as a setup that wrote its map before the first
63
+ # member, or removing its last member, leaves it. Only this principle's having none is out of the way: setup no
64
+ # longer writes it, and its first add-member creates it with that member (T74), while any other principle has
65
+ # none from create-principle until its first add-member (#931).
66
66
  #: () -> bool
67
67
  def unstarted? = meta_principle? && @members.empty?
68
68
 
69
+ # Whether a full audit of this principle can have started, so that a correction may be open while a member is
70
+ # added: start-audit refuses a map with no members (D72, #1023).
71
+ #: () -> bool
72
+ def auditable? = !@members.empty?
73
+
69
74
  # The map's version: the digest of what its JSON says, so any change to it gives a new version, and a hand
70
75
  # edit or a formatter that only reorders its keys does not (#656).
71
76
  #: () -> String
72
77
  def version = JsonDigest.new(@fields).to_s
73
78
 
74
- # Whether other would write the same file as this map, so saving it would change nothing.
75
- #: (MemberMap) -> bool
79
+ # Whether other would write the same file as this principle, so saving it would change nothing.
80
+ #: (Principle) -> bool
76
81
  def same_as?(other) = version == other.version
77
82
 
78
83
  # Each member as this tool prints it: its id beside the fields shown gives it.
@@ -87,26 +92,26 @@ module Principles
87
92
  @fields
88
93
  end
89
94
 
90
- # The member with member_id, refused unless the map has it.
95
+ # The member with member_id, refused unless this principle has it.
91
96
  #: (String) -> Hash[String, untyped]
92
97
  def member(member_id)
93
98
  @members.found(member_id).to_h
94
99
  end
95
100
 
96
- #: (String) -> MemberMap
101
+ #: (String) -> Principle
97
102
  def describing(description)
98
- MemberMap.new(id, @fields.merge("description" => description))
103
+ Principle.new(id, @fields.merge("description" => description))
99
104
  end
100
105
 
101
106
  # When the agent said this principle's work is in hand, as the map stores it, or nil when it has not (D38).
102
107
  #: () -> Hash[String, untyped]?
103
108
  def activation = @fields["activation"]
104
109
 
105
- #: (Activation) -> MemberMap
106
- def activating(activation) = MemberMap.new(id, @fields.merge("activation" => activation.to_h))
110
+ #: (Activation) -> Principle
111
+ def activating(activation) = Principle.new(id, @fields.merge("activation" => activation.to_h))
107
112
 
108
- # This map with member added, refused when the map already has a member with its id.
109
- #: (Hash[String, untyped]) -> MemberMap
113
+ # This principle with member added, refused when it already has a member with its id.
114
+ #: (Hash[String, untyped]) -> Principle
110
115
  def adding(member)
111
116
  added = Member.new(member)
112
117
  new_id = added.id
@@ -118,10 +123,10 @@ module Principles
118
123
  with_members(@members.to_a + [@members.keyed(added)])
119
124
  end
120
125
 
121
- # This map with member_id pointed at the place located names, in the same file. The new place replaces
126
+ # This principle with member_id pointed at the place located names, in the same file. The new place replaces
122
127
  # the old one whole, and every other field is kept: its role, and any a newer version wrote (D29). It is
123
128
  # refused when another member is already there.
124
- #: (String, Hash[String, untyped]) -> MemberMap
129
+ #: (String, Hash[String, untyped]) -> Principle
125
130
  def moving(member_id, located)
126
131
  old = @members.found(member_id)
127
132
  moved = old.moved_to(located)
@@ -133,15 +138,15 @@ module Principles
133
138
  replacing(old, moved)
134
139
  end
135
140
 
136
- #: (String, String) -> MemberMap
141
+ #: (String, String) -> Principle
137
142
  def changing_role(member_id, role) = changing(member_id, "role" => role)
138
143
 
139
144
  # Names the command that enforces a member, which an audit asks the agent to run (D30). This tool
140
145
  # stores it and never runs it.
141
- #: (String, String) -> MemberMap
146
+ #: (String, String) -> Principle
142
147
  def changing_check(member_id, check) = changing(member_id, "check" => check)
143
148
 
144
- #: (String) -> MemberMap
149
+ #: (String) -> Principle
145
150
  def removing_check(member_id)
146
151
  old = @members.found(member_id)
147
152
  unless old.to_h.key?("check")
@@ -152,16 +157,16 @@ module Principles
152
157
  replacing(old, old.without_check)
153
158
  end
154
159
 
155
- #: (String) -> MemberMap
160
+ #: (String) -> Principle
156
161
  def removing(member_id)
157
162
  old = @members.found(member_id)
158
163
  with_members(@members.reject { |each| each.equal?(old) })
159
164
  end
160
165
 
161
- # Member owns the format each member field needs; this name stays while member_map_spec checks it there.
166
+ # Member owns the format each member field needs; this name stays while principle_spec checks it there.
162
167
  FIELD_FORMATS = Member::FIELD_FORMATS #: Hash[String, Integer]
163
168
 
164
- # The oldest format that holds every member of this map: 1 unless a member uses a later field.
169
+ # The oldest format that holds every member of this principle: 1 unless a member uses a later field.
165
170
  #: () -> Integer
166
171
  def format
167
172
  @members.format
@@ -169,38 +174,38 @@ module Principles
169
174
 
170
175
  private
171
176
 
172
- # Whether this is the map of the principle that keeps every other one held (D67).
177
+ # Whether this is the principle that keeps every other one held (D67).
173
178
  #: () -> bool
174
179
  def meta_principle? = @id == MetaPrinciple::ID
175
180
 
176
- # The map with only the fields this tool knows, for printing: a field someone added to the file is kept
181
+ # This principle with only the fields this tool knows, for printing: a field someone added to the file is kept
177
182
  # in it but never shown as if this tool had said it.
178
183
  #: () -> Hash[String, untyped]
179
184
  def shown
180
185
  Data::SchemaCheck.new("member-map").known(@fields)
181
186
  end
182
187
 
183
- # The refusal for a member id another member of this map has, ending with its repairs.
188
+ # The refusal for a member id another member of this principle has, ending with its repairs.
184
189
  #: (String, *Error::RepairCommand) -> Error
185
190
  def taken(new_id, *repairs)
186
191
  Error.new("member_exists", "#{new_id} is already a member of #{id}", "").ending_with(repairs)
187
192
  end
188
193
 
189
- # A repair command acting on a member of this map, with the placeholders the agent fills; the controller prints
190
- # it, quoting the member (D56, #729).
194
+ # A repair command acting on a member of this principle, with the placeholders the agent fills; the controller
195
+ # prints it, quoting the member (D56, #729).
191
196
  #: (String, String, String, ?String?) -> Error::RepairCommand
192
197
  def repair(purpose, command, member, usage = nil)
193
198
  Error::RepairCommand.new(purpose: purpose, command: command, values: [id, member], usage: usage)
194
199
  end
195
200
 
196
- # The map with member_id's entry holding fields in place of its own.
197
- #: (String, Hash[String, untyped]) -> MemberMap
201
+ # This principle with member_id's entry holding fields in place of its own.
202
+ #: (String, Hash[String, untyped]) -> Principle
198
203
  def changing(member_id, fields)
199
204
  old = @members.found(member_id)
200
205
  replacing(old, old.with(fields))
201
206
  end
202
207
 
203
- #: (Member, Member) -> MemberMap
208
+ #: (Member, Member) -> Principle
204
209
  def replacing(old, member)
205
210
  with_members(@members.map { |each| each.equal?(old) ? member : each })
206
211
  end
@@ -208,11 +213,11 @@ module Principles
208
213
  # Members are kept in id order, so a map's file changes only where a member does.
209
214
  # Its format is worked out again, and written only above 1, so a map that uses no later field keeps
210
215
  # the bytes an older version wrote, and its version.
211
- #: (Array[Member]) -> MemberMap
216
+ #: (Array[Member]) -> Principle
212
217
  def with_members(list)
213
- changed = MemberMap.new(id, @fields.merge("members" => list.sort_by(&:id).map(&:to_h)))
218
+ changed = Principle.new(id, @fields.merge("members" => list.sort_by(&:id).map(&:to_h)))
214
219
  fields = changed.to_h.except("format")
215
- MemberMap.new(id, changed.format > 1 ? fields.merge("format" => changed.format) : fields)
220
+ Principle.new(id, changed.format > 1 ? fields.merge("format" => changed.format) : fields)
216
221
  end
217
222
  end
218
223
  end