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
@@ -0,0 +1,51 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../data/schema_check"
5
+ require_relative "../error"
6
+ require_relative "refusal_before_shape"
7
+
8
+ module Principles
9
+ module Models
10
+ # An answer an agent sent for a phase's request, read from its source, whose head, the fields every answer hands
11
+ # back as its request printed them, is checked on arrival: they say whether it still answers that request
12
+ # (#990). The rest is checked only once that request is known, against the placeholders its template printed and
13
+ # the phase's schema (D29, #1052, #1084).
14
+ class SentAnswer
15
+ HEAD = %w[request_id basis].freeze #: Array[String]
16
+
17
+ # What a refusal's message calls the answer: the agent holds its file's path, which cost context in every
18
+ # repair (#1112, #1118).
19
+ NAMED = "The answer" #: String
20
+ # What a refusal to read its file calls that file (#1131).
21
+ FILE_NAMED = "The answer file" #: String
22
+
23
+ REPAIR = "Repair each field listed, starting from the request's response_template." #: String
24
+
25
+ # parsed is the answer as its source, a file or - for stdin, holds it; check is its phase's answer schema.
26
+ #: (untyped, String, Data::SchemaCheck) -> void
27
+ def initialize(parsed, source, check)
28
+ @parsed = parsed
29
+ @source = source
30
+ @check = check
31
+ check.only(HEAD).checked(parsed, code: "invalid_answer", source: source, repair: REPAIR, named: NAMED)
32
+ freeze
33
+ end
34
+
35
+ # The answer's head, checked.
36
+ #: () -> Hash[String, untyped]
37
+ def head = @parsed.slice(*HEAD)
38
+
39
+ # The whole answer, once each refusal its request's rules make before its shape, in order, then its shape, is
40
+ # checked: such as a stray check_result on a member with no check, a field holding a placeholder its
41
+ # request's template did not print, and a one-member audit's field left as its template printed it, each handed
42
+ # the shape's problems to name beside its own (#1106).
43
+ #: (Array[RefusalBeforeShape]) -> untyped
44
+ def checked(before_shape)
45
+ shape_problems = @check.problems(@parsed)
46
+ before_shape.each { |refusal| refusal.refuse_in(@parsed, @source, shape_problems) }
47
+ @check.checked(@parsed, code: "invalid_answer", source: @source, repair: REPAIR, named: NAMED)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "prior_decision_fields"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # An assessment answer's prior_finding_decisions as sent, before each is checked against the finding it decides:
10
+ # a decision still the placeholder start-audit --as template printed is no decision, so the answer's one refusal
11
+ # names it with every other judgement left so (#1040).
12
+ class SentPriorDecisions
13
+ # decisions is the answer's prior_finding_decisions as sent, a list.
14
+ #: (Array[untyped]) -> void
15
+ def initialize(decisions)
16
+ @decisions = decisions
17
+ freeze
18
+ end
19
+
20
+ # Each decision left as printed, named by the finding it decides, with its pointer.
21
+ #: () -> Hash[String, String]
22
+ def left_as_printed
23
+ @decisions.each_with_index.filter_map do |decision, index|
24
+ next unless decision.is_a?(Hash) && decision["decision"] == PriorDecisionFields::DECISION
25
+
26
+ ["Prior finding #{decision["finding_id"]} decision", "/prior_finding_decisions/#{index}/decision"]
27
+ end.to_h
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # The problems an answer's shape has beside those a refusal before the shape names, which that refusal names too,
8
+ # so one refusal lists every repair (#1106, #1109), and says so in its message, which an agent reads first (#1130).
9
+ class ShapeProblemsBeside
10
+ # What the message adds when there are any.
11
+ MESSAGE = ", and fields not in the shape this tool reads" #: String
12
+
13
+ # problems are the shape's, as Data::SchemaCheck#problems gives them; each at or under a pointer in named, which
14
+ # the refusal names, is left out, since its repair repairs that one too.
15
+ #: (Array[Hash[String, String]], named: Array[String]) -> void
16
+ def initialize(problems, named:)
17
+ elsewhere = problems.reject { |problem| under?(problem.fetch("pointer"), named) }
18
+ @fields = elsewhere.freeze #: Array[Hash[String, String]]
19
+ freeze
20
+ end
21
+
22
+ #: Array[Hash[String, String]]
23
+ attr_reader :fields
24
+
25
+ # The refusal's own message, saying when it names these too.
26
+ #: (String) -> String
27
+ def message(own) = "#{own}#{MESSAGE unless @fields.empty?}"
28
+
29
+ # The refusal's own repair, with also, how to repair these, when there are any.
30
+ #: (String, String) -> String
31
+ def repair(own, also) = "#{own}#{also unless @fields.empty?}"
32
+
33
+ private
34
+
35
+ # Whether pointer is one of named, or inside one.
36
+ #: (String, Array[String]) -> bool
37
+ def under?(pointer, named) = named.any? { pointer == it || pointer.start_with?("#{it}/") }
38
+ end
39
+ end
40
+ end
@@ -10,9 +10,9 @@ require_relative "open_finding"
10
10
  module Principles
11
11
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
12
  module Models
13
- # What a decision on a prior finding restates of that finding, which only a still_holds decision may: the
14
- # problem its record lacks, a new pointer to its write-up (D35), the evidence its record lacks (D64) and a new
15
- # place for each kept evidence item no longer found (D70).
13
+ # What a decision on a prior finding restates of that finding, which only a still_holds decision may: its
14
+ # problem, which its record may lack (#706), a new pointer to its write-up (D35), the evidence its record lacks
15
+ # (D64) and a new place for each kept evidence item no longer found (D70).
16
16
  # PriorFindingDecision checks the rest of the decision, and refuses for this through refuse.
17
17
  class StillHoldsRestatement
18
18
  # finding is the prior finding as its record left it open; place is the decision's place in the answer; refuse
@@ -27,9 +27,8 @@ module Principles
27
27
  freeze
28
28
  end
29
29
 
30
- # Refuses a restatement on any decision but still_holds, a problem the finding already states or that is not
31
- # one line, kept evidence it replaces but that is still found or named by no replaces, and a pointer locate
32
- # cannot resolve.
30
+ # Refuses a restatement on any decision but still_holds, a problem that is not one line, kept evidence it
31
+ # replaces but that is still found or named by no replaces, and a pointer locate cannot resolve.
33
32
  #: (^(Locator) -> void) -> void
34
33
  def check(locate)
35
34
  evidence(locate) if @decision.key?("problem_evidence")
@@ -74,12 +73,10 @@ module Principles
74
73
  AnswerFields.new(locate).evidence(given, place)
75
74
  end
76
75
 
76
+ # The problem its record lacks, or a restatement of the one it states when a term in it was renamed or a fact it
77
+ # names moved, which keeps the finding's id and first_raised_at (#706).
77
78
  #: () -> void
78
79
  def problem
79
- if @finding.states_problem?
80
- @refuse.call("it already states its problem",
81
- "Drop problem from #{@id}'s decision, or raise it again as a new finding to restate it.")
82
- end
83
80
  @refuse.call("problem must be one line", nil) unless AnswerText.new(@decision["problem"]).one_line?
84
81
  end
85
82
  end
@@ -0,0 +1,34 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "prior_findings"
5
+ require_relative "request_id"
6
+
7
+ module Principles
8
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # An answer submitted to the request request_id names, its shape checked, with the prior findings a full
11
+ # audit's request listed, which checking its head found (#1052), or nil for any other phase.
12
+ class SubmittedAnswer
13
+ #: RequestId
14
+ attr_reader :request_id
15
+
16
+ #: untyped
17
+ attr_reader :response
18
+
19
+ #: (RequestId, untyped, PriorFindings?) -> void
20
+ def initialize(request_id, response, prior)
21
+ @request_id = request_id
22
+ @response = response
23
+ @prior = prior
24
+ freeze
25
+ end
26
+
27
+ # The prior findings a full audit's assessment request listed, which only that phase's answer has.
28
+ #: () -> PriorFindings
29
+ def prior_findings
30
+ @prior or raise ArgumentError, "an assessment's prior findings come from checking its head"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,71 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "left_as_printed"
5
+ require_relative "refusal_before_shape"
6
+
7
+ module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
+ module Models
10
+ # The text an answer's template prints in each field an agent may leave as printed to give none, so the agent
11
+ # fills the fields that apply and never reshapes the answer (#993, #994). The model that owns a part of the answer
12
+ # holds one, which a controller hands to the view that prints it.
13
+ class TemplatePlaceholders
14
+ include RefusalBeforeShape
15
+
16
+ # placeholders is the text printed in each field, by field name, or for a field that takes pointers, one pointer
17
+ # whose fields hold that text, so the template shows their shape (#1042); empty_lists names the fields a template
18
+ # may instead start as an empty list, which is not given either (#838); also_printed, the other text a template
19
+ # may print in a field, refused alike (#1142).
20
+ #: (Hash[String, untyped], ?empty_lists: Array[String], ?also_printed: Hash[String, String]) -> void
21
+ def initialize(placeholders, empty_lists: [], also_printed: {})
22
+ @placeholders = placeholders.freeze #: Hash[String, untyped]
23
+ @empty_lists = empty_lists.freeze #: Array[String]
24
+ @also_printed = also_printed.freeze #: Hash[String, String]
25
+ freeze
26
+ end
27
+
28
+ # The text printed in each field, with field's other text in place of its own.
29
+ #: (String) -> Hash[String, untyped]
30
+ def with_other_text_in(field) = @placeholders.merge(field => @also_printed.fetch(field))
31
+
32
+ # The text printed in each field, for the view that prints it.
33
+ #: () -> Hash[String, untyped]
34
+ def to_h = @placeholders
35
+
36
+ # The text printed in field.
37
+ #: (String) -> untyped
38
+ def fetch(field) = @placeholders.fetch(field)
39
+
40
+ # fields, without each one left as its placeholder, which is not given.
41
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
42
+ def given(fields) = fields.reject { |field, value| left?(field, value) }
43
+
44
+ # Refuses answer, as sent, when it leaves a field as its placeholder, for a template whose every field must be
45
+ # written, as a one-member audit's (#773); read before the answer's shape, which would refuse a placeholder in a
46
+ # field of another type without naming it, so the refusal names the shape's other problems too (#1106). source
47
+ # is unused, as other refusals before the shape name it.
48
+ # @override
49
+ #: (untyped, String, Array[Hash[String, String]]) -> void
50
+ def refuse_in(answer, _source, shape_problems)
51
+ return unless answer.is_a?(Hash)
52
+
53
+ left = @placeholders.keys.select { |field| printed?(field, answer[field]) }
54
+ LeftAsPrinted.new(left.to_h { [it, "/#{it}"] }).refuse(besides: shape_problems)
55
+ end
56
+
57
+ # Whether value is field's placeholder, or the empty list it may start as, as printed; a field with neither
58
+ # never is.
59
+ #: (String, untyped) -> bool
60
+ def left?(field, value)
61
+ (@placeholders.key?(field) && printed?(field, value)) || (@empty_lists.include?(field) && value == [])
62
+ end
63
+
64
+ private
65
+
66
+ # Whether value is a text the template prints in field.
67
+ #: (String, untyped) -> bool
68
+ def printed?(field, value) = [@placeholders[field], @also_printed[field]].compact.include?(value)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,55 @@
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
+ # A text cut to at most some characters, as a candidate file's outline prints its items, opening line and
8
+ # description: whole when it fits, else back to a sentence end or a whole word (#1155).
9
+ class TextWithin
10
+ # Text up to its last sentence end that a space follows.
11
+ SENTENCES = /\A.*[.!?](?=\s)/
12
+ # Text up to its last whole word.
13
+ WORDS = /\A.*(?=\s)/
14
+
15
+ #: (String, at_most: Integer) -> void
16
+ def initialize(text, at_most:)
17
+ @text = text
18
+ @at_most = at_most
19
+ freeze
20
+ end
21
+
22
+ # Whether the text is longer than at_most characters.
23
+ #: () -> bool
24
+ def cut? = @text.length > @at_most
25
+
26
+ # The text whole, else up to its last sentence end within at_most characters, else up to its last whole word.
27
+ #: () -> String
28
+ def kept
29
+ return @text unless cut?
30
+
31
+ sentences_kept || words_kept
32
+ end
33
+
34
+ # The text whole, else up to its last sentence end, else cut on a word ending in an ellipsis.
35
+ #: () -> String
36
+ def by_sentences = cut? && !sentences_kept ? "#{words_kept}…" : kept
37
+
38
+ # The text whole, else cut on a word ending in an ellipsis.
39
+ #: () -> String
40
+ def by_words = cut? ? "#{words_kept}…" : @text
41
+
42
+ private
43
+
44
+ #: () -> String?
45
+ def sentences_kept = window[SENTENCES]
46
+
47
+ #: () -> String
48
+ def words_kept = window[WORDS] || @text[0, @at_most].to_s
49
+
50
+ # The text's first at_most characters and the one after, so a sentence or word ending at the cap is kept.
51
+ #: () -> String
52
+ def window = @text[0, @at_most + 1].to_s
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,76 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "../prose_list"
6
+ require_relative "answer_place"
7
+ require_relative "principle_members"
8
+ require_relative "refusal_before_shape"
9
+
10
+ module Principles
11
+ module Models
12
+ # The members of a principle that name no check, whose assessments take no check_result. An answer is read for
13
+ # one before its shape is checked, since the shape would ask for the command such a check_result lacks, sending
14
+ # the agent to fill in what it should remove (#1088).
15
+ class UncheckedMembers
16
+ include RefusalBeforeShape
17
+
18
+ #: (PrincipleMembers) -> void
19
+ def initialize(members)
20
+ @members = members
21
+ freeze
22
+ end
23
+
24
+ # Refuses answer when it gives check_result on the assessment of a member with no check. It reads the answer as
25
+ # sent, so it leaves anything malformed to the shape's refusal or the coverage refusal; source is unused, as
26
+ # other refusals before the shape name it.
27
+ # @override
28
+ #: (untyped, String, Array[Hash[String, String]]) -> void
29
+ def refuse_in(answer, _source, _shape_problems)
30
+ assessments = answer["member_assessments"] if answer.is_a?(Hash)
31
+ return unless assessments.is_a?(Array)
32
+
33
+ assessments.each_with_index do |assessment, index|
34
+ next unless stray?(assessment)
35
+
36
+ refuse_at(AnswerPlace.member_assessment(index, assessment["member_id"]), assessment["check_result"])
37
+ end
38
+ end
39
+
40
+ # Refuses reported, the check_result given on the assessment at place of a member with no check, naming the
41
+ # members that hold the principle's checks, since an agent may have taken this one for one of them (#1090); nil
42
+ # when none is given, as such an assessment should.
43
+ #: (AnswerPlace, untyped) -> nil
44
+ def refuse_at(place, reported)
45
+ return unless reported
46
+
47
+ raise place.child("check_result").refusal(
48
+ Error.new("invalid_check_result", "the member has no check, so its assessment takes no check_result",
49
+ ["Remove check_result from this member's assessment.", checked_on].compact.join(" "))
50
+ )
51
+ end
52
+
53
+ private
54
+
55
+ # The sentence naming the members that hold the principle's checks, or nil when none does.
56
+ #: () -> String?
57
+ def checked_on
58
+ checked = @members.checked_ids
59
+ return if checked.empty?
60
+
61
+ "This principle's #{checked.one? ? "check is" : "checks are"} on #{ProseList.new(checked)}."
62
+ end
63
+
64
+ # Whether assessment gives a check_result for a mapped member that names no check.
65
+ #: (untyped) -> bool
66
+ def stray?(assessment)
67
+ return false unless assessment.is_a?(Hash) && assessment["check_result"]
68
+
69
+ id = assessment["member_id"]
70
+ return false unless id.is_a?(String)
71
+
72
+ @members.unchecked?(id)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -55,11 +55,22 @@ module Principles
55
55
  def to_h
56
56
  index = (@first...@last).find { |each| !line(each).blank? } or return nil
57
57
  text = opening_text(index)
58
- { "text" => text[0, LIMIT], "line" => index + 1 }.merge(text.length > LIMIT ? { "truncated" => true } : {})
58
+ { "text" => cut(text), "line" => index + 1 }.merge(text.length > LIMIT ? { "truncated" => true } : {})
59
59
  end
60
60
 
61
61
  private
62
62
 
63
+ # text whole within the limit, or else up to the last whole word that fits, since a cut mid-word reads as a
64
+ # different phrase (#1078); one word longer than the limit is cut where the limit falls.
65
+ #: (String) -> String
66
+ def cut(text)
67
+ return text if text.length <= LIMIT
68
+
69
+ fits = text[0, LIMIT + 1].to_s
70
+ boundary = fits.rindex(" ") or return fits[0, LIMIT].to_s
71
+ fits[0, boundary].to_s
72
+ end
73
+
63
74
  # A heading line whole, since a heading is not a sentence and "F4." may number it (#739). Otherwise the
64
75
  # first sentence: hard-wrapped lines joined with single spaces up to the sentence's end, or else to its
65
76
  # paragraph's end, a blank line, the next list item or heading, or the file's end. It runs past the region's
@@ -78,13 +89,19 @@ module Principles
78
89
  [line(index), *rest].map(&:text)
79
90
  end
80
91
 
81
- # text up to the end of its first sentence, or all of it when none ends.
92
+ # text up to the end of its first sentence, or all of it when none ends. A mark inside a parenthesis, as in
93
+ # "(e.g. this)", ends no sentence, since cutting there leaves a fragment (#1078).
82
94
  #: (String) -> String
83
95
  def sentence(text)
84
- found = SENTENCE_END.match(text) or return text
85
- text[0, found.end(0)].to_s
96
+ ends = text.to_enum(:scan, SENTENCE_END).map { Regexp.last_match&.end(0) }
97
+ found = ends.compact.find { |at| closed?(text[0, at].to_s) } or return text
98
+ text[0, found].to_s
86
99
  end
87
100
 
101
+ # Whether every parenthesis opened in text is closed by its end.
102
+ #: (String) -> bool
103
+ def closed?(text) = text.count("(") <= text.count(")")
104
+
88
105
  # The line at index, or a blank one past the file's end.
89
106
  #: (Integer) -> Line
90
107
  def line(index) = @lines[index] || Line.new("")
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The option list-open-findings --short takes from Claude Code's SessionStart hook, --session-start (#717), and what
8
+ # is wrong with it as given, which CommandLine refuses as a usage error.
9
+ class SessionStartOptions
10
+ # The sources Claude Code's SessionStart hook names.
11
+ SOURCES = %w[startup resume clear compact].freeze #: Array[String]
12
+
13
+ #: (InvocationOptions) -> void
14
+ def initialize(options)
15
+ @start = options.value("session_start") #: String?
16
+ @short = !options.value("short").nil? #: bool
17
+ freeze
18
+ end
19
+
20
+ # What is wrong with the option as given, or nil when it fits or is not given; it words only the --short line.
21
+ #: () -> String?
22
+ def fault
23
+ start = @start or return
24
+ return "--session-start takes startup, resume, clear or compact, not #{start}" unless SOURCES.include?(start)
25
+
26
+ "--session-start words only the --short line" unless @short
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,52 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The options that choose which audit start-audit begins, --member and --write-ups (#760), and the form --as prints
8
+ # it in (D81), and what is wrong with them as given, which CommandLine refuses as a usage error.
9
+ class StartAuditOptions
10
+ #: (InvocationOptions) -> void
11
+ def initialize(options)
12
+ @member = !options.value("member").nil? #: bool
13
+ @write_ups = !options.value("write_ups").nil? #: bool
14
+ @form = options.value("as") #: String?
15
+ @instruction = !options.value("instruction").nil? #: bool
16
+ freeze
17
+ end
18
+
19
+ # What is wrong with the options as given, or nil when they fit.
20
+ #: () -> String?
21
+ def fault
22
+ return "--member and --write-ups each start a different audit; give one" if @member && @write_ups
23
+
24
+ instruction_fault || form_fault
25
+ end
26
+
27
+ private
28
+
29
+ # --instruction prints one field of a full audit's request whole (D81 step 2); nil when nothing beside it prints
30
+ # another output.
31
+ #: () -> String?
32
+ def instruction_fault
33
+ return unless @instruction
34
+
35
+ other = if @form then "the answer --as template prints"
36
+ elsif @member then "the one-member audit --member starts"
37
+ elsif @write_ups then "the repoint --write-ups starts"
38
+ end
39
+ "--instruction prints one field of a full audit's request, not of #{other}" if other
40
+ end
41
+
42
+ # --as template prints a full audit's answer alone (D81 step 1), or a one-member audit's (#773), the one form
43
+ # built so far; nil when it fits.
44
+ #: () -> String?
45
+ def form_fault
46
+ form = @form or return
47
+ return "--as takes template, the answer alone, not #{form}" unless form == "template"
48
+
49
+ "--as template prints a full or one-member audit's answer, not one --write-ups starts" if @write_ups
50
+ end
51
+ end
52
+ end
@@ -3,9 +3,9 @@
3
3
 
4
4
  module Principles
5
5
  # The next production release, as major.minor.patch. A production build is versioned with this alone.
6
- RELEASE = "0.0.1"
6
+ RELEASE = "0.0.5"
7
7
  # The version a built gem prints. `rake build[production]` stamps RELEASE here, in the copy of lib/ it
8
8
  # packages, and `rake build[development]` stamps RELEASE.g<short sha>. A checkout leaves it nil, and
9
9
  # Data::RunningVersion reads the commit this tool runs from instead.
10
- BUILT_VERSION = "0.0.1" #: String?
10
+ BUILT_VERSION = "0.0.5" #: String?
11
11
  end
@@ -16,20 +16,28 @@ module Principles
16
16
  freeze
17
17
  end
18
18
 
19
- # change is the member's change since its baseline; open_findings, the record's findings on the member. What
20
- # the agent judges is under context, the question last, as in a full audit's request (D60).
19
+ # change is the member's change since its baseline; open_findings, the record's findings on the member;
20
+ # placeholders, the text the template prints in each field the agent writes. What the agent judges is under
21
+ # context, the question last, as in a full audit's request (D60).
21
22
  #: (request_id: String, principle_id: String, change: MemberChangeSinceBaseline,
22
- #| open_findings: Hash[String, Array[String]]) -> Hash[String, untyped]
23
- def request(request_id:, principle_id:, change:, open_findings:)
23
+ #| open_findings: Hash[String, Array[String]], placeholders: Hash[String, untyped]) -> Hash[String, untyped]
24
+ def request(request_id:, principle_id:, change:, open_findings:, placeholders:)
24
25
  { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "acknowledgement",
25
26
  "context" => { "principle_id" => principle_id, **change.to_h, **open_findings,
26
27
  "question" => Prompts.text("acknowledge-a-change/say-whether-the-change-keeps-the-meaning") },
27
- "response_template" => { "request_id" => request_id,
28
- "basis" => { "base_commit" => change.base_commit, "member_id" => change.member_id },
29
- "meaning_kept" => true, "reason" => "", "old_line" => "", "new_line" => "" },
28
+ "response_template" => answer_to_fill(request_id:, change:, placeholders:),
30
29
  "answer_with" => @invocation.submit_answer(request_id) }
31
30
  end
32
31
 
32
+ # The answer to the request request_id names, to fill: the request prints it as response_template, and
33
+ # start-audit --member --as template prints it alone, each field the agent writes holding its placeholder (#773).
34
+ #: (request_id: String, change: MemberChangeSinceBaseline, placeholders: Hash[String, untyped])
35
+ #| -> Hash[String, untyped]
36
+ def answer_to_fill(request_id:, change:, placeholders:)
37
+ { "request_id" => request_id,
38
+ "basis" => { "base_commit" => change.base_commit, "member_id" => change.member_id }, **placeholders }
39
+ end
40
+
33
41
  # The acknowledgement was accepted and file holds it.
34
42
  #: (principle_id: String, member_id: String, file: String) -> Hash[String, untyped]
35
43
  def acknowledged(principle_id:, member_id:, file:)
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # What an answer hands back unchanged, at its head: the id of the request it answers and that request's basis,
8
+ # which the agent never copies by hand.
9
+ class AnswerHead
10
+ #: String
11
+ attr_reader :request_id
12
+
13
+ #: (request_id: String, basis: Hash[String, untyped]) -> void
14
+ def initialize(request_id:, basis:)
15
+ @request_id = request_id
16
+ @basis = basis
17
+ freeze
18
+ end
19
+
20
+ # Whether the basis names a base commit, as in git; outside git it names none.
21
+ #: () -> bool
22
+ def based_on_a_commit? = !@basis["base_commit"].nil?
23
+
24
+ # The answer's fields, after its request id and basis.
25
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
26
+ def leading(fields) = { "request_id" => @request_id, "basis" => @basis }.merge(fields)
27
+ end
28
+ end
29
+ end