principles 0.0.10 → 0.1.0

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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +0 -2
  4. data/lib/principles/controllers/acknowledgement.rb +11 -4
  5. data/lib/principles/controllers/acknowledgements.rb +4 -4
  6. data/lib/principles/controllers/answer.rb +2 -2
  7. data/lib/principles/controllers/assessment.rb +20 -4
  8. data/lib/principles/controllers/audit.rb +16 -5
  9. data/lib/principles/controllers/broken_member_repairs.rb +60 -0
  10. data/lib/principles/controllers/command.rb +8 -30
  11. data/lib/principles/controllers/correction.rb +7 -5
  12. data/lib/principles/controllers/full_audit_request.rb +44 -22
  13. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  14. data/lib/principles/controllers/inventory.rb +3 -3
  15. data/lib/principles/controllers/member_acknowledgement.rb +5 -5
  16. data/lib/principles/controllers/member_addition.rb +5 -2
  17. data/lib/principles/controllers/member_entries.rb +1 -1
  18. data/lib/principles/controllers/member_problems_report.rb +11 -7
  19. data/lib/principles/controllers/members_to_assess.rb +1 -1
  20. data/lib/principles/controllers/meta_principle_setup.rb +4 -3
  21. data/lib/principles/controllers/open_correction.rb +3 -3
  22. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  23. data/lib/principles/controllers/running_tool.rb +22 -5
  24. data/lib/principles/controllers/survey.rb +3 -2
  25. data/lib/principles/data/candidate_files_found.rb +6 -4
  26. data/lib/principles/data/command-steps.json +20 -20
  27. data/lib/principles/data/json_text.rb +5 -1
  28. data/lib/principles/data/parser_message.rb +61 -0
  29. data/lib/principles/data/project_files.rb +4 -2
  30. data/lib/principles/data/repository.rb +4 -4
  31. data/lib/principles/data/running_version.rb +1 -1
  32. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  33. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  34. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  35. data/lib/principles/invocation_options.rb +4 -4
  36. data/lib/principles/launch.rb +5 -3
  37. data/lib/principles/models/acknowledgement.rb +1 -27
  38. data/lib/principles/models/acknowledgement_left_as_printed.rb +2 -1
  39. data/lib/principles/models/acknowledgement_placeholders.rb +48 -0
  40. data/lib/principles/models/after_commit_input.rb +1 -0
  41. data/lib/principles/models/assessment_answer.rb +2 -2
  42. data/lib/principles/models/assessment_basis.rb +1 -1
  43. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  44. data/lib/principles/models/audit.rb +24 -4
  45. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  46. data/lib/principles/models/audit_record.rb +5 -14
  47. data/lib/principles/models/audit_records.rb +2 -2
  48. data/lib/principles/models/audited_member_lines.rb +1 -1
  49. data/lib/principles/models/candidate_files.rb +1 -1
  50. data/lib/principles/models/candidate_inventory.rb +20 -10
  51. data/lib/principles/models/candidate_outline.rb +1 -1
  52. data/lib/principles/models/changed_regions.rb +1 -1
  53. data/lib/principles/models/command_steps.rb +1 -2
  54. data/lib/principles/models/correction_basis.rb +1 -1
  55. data/lib/principles/models/declared_map_changes.rb +1 -2
  56. data/lib/principles/models/disposition.rb +12 -76
  57. data/lib/principles/models/disposition_placeholders.rb +48 -0
  58. data/lib/principles/models/disposition_text_field.rb +41 -0
  59. data/lib/principles/models/evidence_item.rb +1 -1
  60. data/lib/principles/models/finding_decision.rb +84 -0
  61. data/lib/principles/models/finding_write_ups.rb +2 -1
  62. data/lib/principles/models/first_full_audit.rb +1 -0
  63. data/lib/principles/models/fix_only_fields.rb +4 -3
  64. data/lib/principles/models/frontmatter_fields.rb +1 -1
  65. data/lib/principles/models/guidance_search_path.rb +1 -1
  66. data/lib/principles/models/guidance_search_paths.rb +5 -1
  67. data/lib/principles/models/head_moves.rb +1 -0
  68. data/lib/principles/models/ignored_candidates.rb +1 -1
  69. data/lib/principles/models/instruction_named.rb +1 -1
  70. data/lib/principles/models/json_path_query.rb +1 -1
  71. data/lib/principles/models/json_path_selectors.rb +1 -1
  72. data/lib/principles/models/json_path_string.rb +1 -1
  73. data/lib/principles/models/last_completed_revision.rb +1 -1
  74. data/lib/principles/models/line_diff.rb +1 -1
  75. data/lib/principles/models/line_span.rb +1 -1
  76. data/lib/principles/models/loading_scope.rb +1 -0
  77. data/lib/principles/models/located_text.rb +20 -12
  78. data/lib/principles/models/map_change.rb +66 -0
  79. data/lib/principles/models/mapped_principles.rb +4 -0
  80. data/lib/principles/models/markdown_file.rb +22 -1
  81. data/lib/principles/models/member.rb +1 -1
  82. data/lib/principles/models/member_assessments.rb +11 -4
  83. data/lib/principles/models/member_elsewhere.rb +1 -1
  84. data/lib/principles/models/member_file.rb +15 -13
  85. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  86. data/lib/principles/models/member_history.rb +1 -1
  87. data/lib/principles/models/member_lines.rb +1 -1
  88. data/lib/principles/models/member_loading_scopes.rb +1 -0
  89. data/lib/principles/models/member_mapping_run.rb +4 -4
  90. data/lib/principles/models/member_moves.rb +1 -2
  91. data/lib/principles/models/member_problems.rb +5 -1
  92. data/lib/principles/models/member_region.rb +1 -1
  93. data/lib/principles/models/member_repair_moves.rb +20 -4
  94. data/lib/principles/models/member_snapshots.rb +10 -10
  95. data/lib/principles/models/members_elsewhere.rb +1 -1
  96. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  97. data/lib/principles/models/members_sharing_lines.rb +2 -2
  98. data/lib/principles/models/misspelt_member_id.rb +10 -4
  99. data/lib/principles/models/named_placeholder.rb +32 -0
  100. data/lib/principles/models/open_finding.rb +4 -3
  101. data/lib/principles/models/open_findings_decision.rb +124 -0
  102. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  103. data/lib/principles/models/other_templates_placeholders.rb +26 -6
  104. data/lib/principles/models/outline_budget.rb +1 -1
  105. data/lib/principles/models/outline_group.rb +1 -1
  106. data/lib/principles/models/outline_section.rb +1 -1
  107. data/lib/principles/models/part_named.rb +1 -1
  108. data/lib/principles/models/plain_text_file.rb +1 -1
  109. data/lib/principles/models/principle_history.rb +5 -4
  110. data/lib/principles/models/principle_members.rb +1 -1
  111. data/lib/principles/models/problem_report.rb +13 -1
  112. data/lib/principles/models/project.rb +15 -16
  113. data/lib/principles/models/project_at_commit.rb +60 -0
  114. data/lib/principles/models/project_history.rb +10 -52
  115. data/lib/principles/models/prose_line.rb +36 -0
  116. data/lib/principles/models/record_format.rb +17 -4
  117. data/lib/principles/models/recorded_finding.rb +47 -7
  118. data/lib/principles/models/recorded_findings.rb +7 -7
  119. data/lib/principles/models/recorded_hashes.rb +1 -1
  120. data/lib/principles/models/recorded_members.rb +6 -8
  121. data/lib/principles/models/report_hooks.rb +1 -0
  122. data/lib/principles/models/request_id.rb +2 -2
  123. data/lib/principles/models/sent_answer.rb +5 -3
  124. data/lib/principles/models/session_start_input.rb +1 -0
  125. data/lib/principles/models/stale_request.rb +22 -8
  126. data/lib/principles/models/submitted_answer.rb +1 -1
  127. data/lib/principles/models/survey_search_paths.rb +13 -5
  128. data/lib/principles/models/template_placeholders.rb +22 -7
  129. data/lib/principles/models/text_size.rb +11 -3
  130. data/lib/principles/models/text_within.rb +1 -1
  131. data/lib/principles/models/unchecked_members.rb +1 -0
  132. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  133. data/lib/principles/models/unfinished_field.rb +34 -0
  134. data/lib/principles/models/unknown_principle.rb +1 -0
  135. data/lib/principles/models/write_up_opening.rb +5 -31
  136. data/lib/principles/models/write_up_pointer.rb +2 -1
  137. data/lib/principles/start_audit_options.rb +35 -20
  138. data/lib/principles/version.rb +2 -2
  139. data/lib/principles/views/acknowledged_result.rb +59 -0
  140. data/lib/principles/views/acknowledgement_result.rb +44 -51
  141. data/lib/principles/views/added_member.rb +10 -1
  142. data/lib/principles/views/answer_in_a_file.rb +65 -0
  143. data/lib/principles/views/assessed_members.rb +4 -2
  144. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  145. data/lib/principles/views/assessment_request.rb +2 -26
  146. data/lib/principles/views/audit_result.rb +18 -7
  147. data/lib/principles/views/candidate_files_result.rb +9 -4
  148. data/lib/principles/views/context_parts.rb +41 -10
  149. data/lib/principles/views/correction_request.rb +27 -18
  150. data/lib/principles/views/first_audit_brief.rb +2 -1
  151. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  152. data/lib/principles/views/invocation.rb +14 -4
  153. data/lib/principles/views/json_on_one_line.rb +18 -0
  154. data/lib/principles/views/member_repairs.rb +21 -5
  155. data/lib/principles/views/meta_principle_result.rb +26 -5
  156. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  157. data/lib/principles/views/parts_index_result.rb +8 -6
  158. data/lib/principles/views/principle_read_result.rb +2 -2
  159. data/lib/principles/views/problem_facts.rb +46 -0
  160. data/lib/principles/views/problem_lines.rb +8 -3
  161. data/lib/principles/views/problem_result.rb +53 -31
  162. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
  163. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  164. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  165. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  166. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  167. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  168. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  169. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  170. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  171. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-check.md +4 -3
  172. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +4 -3
  173. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  174. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +7 -8
  175. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  176. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +4 -3
  177. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member-check.md +4 -3
  178. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +4 -3
  179. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +13 -12
  180. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  181. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  182. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +12 -12
  183. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  184. data/lib/principles/views/prompts/start-a-session/act-on-the-changed-principles.md +2 -0
  185. data/lib/principles/views/prompts.rb +7 -4
  186. metadata +26 -8
  187. data/lib/principles/controllers/repoint.rb +0 -67
  188. data/lib/principles/models/repoint.rb +0 -125
  189. data/lib/principles/models/write_up_repoint.rb +0 -38
  190. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  191. data/lib/principles/views/repoint_result.rb +0 -80
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "disposition_text_field"
5
+ require_relative "named_placeholder"
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 a correction's template prints in each disposition field the agent fills, which an answer may not
11
+ # send back unchanged: each text field's, with what to write instead, and the action's. Each names the finding
12
+ # of the disposition it is printed in, so no two dispositions' slots are alike and one edit fills one.
13
+ class DispositionPlaceholders
14
+ TEXT_FIELDS = {
15
+ "reason" => DispositionTextField.new(
16
+ placeholder: NamedPlaceholder.new("Why #{NamedPlaceholder::SLOT} takes this action, and what remains",
17
+ before: "Why, and what remains"),
18
+ repair: "Write why you chose this action and what remains."
19
+ ),
20
+ "reassessment" => DispositionTextField.new(
21
+ placeholder: NamedPlaceholder.new(
22
+ "fixed only: how the members changed for #{NamedPlaceholder::SLOT} now carry the principle. " \
23
+ "Leave as printed otherwise",
24
+ before: "fixed only: how the changed members now carry the principle. Leave as printed otherwise"
25
+ ),
26
+ repair: "Write how the changed members now carry the principle."
27
+ )
28
+ }.freeze #: Hash[String, DispositionTextField]
29
+ # The placeholder in each field, which the template prints with the disposition's finding in its slot.
30
+ PLACEHOLDERS = TEXT_FIELDS.transform_values { it.placeholder.slotted }.freeze #: Hash[String, String]
31
+ # What action takes, said where it is written when the correction's answer is printed with no answer guide
32
+ # beside it, as show-answer-check prints it, before it named the finding. It is help, never an action, so it
33
+ # is left unchosen.
34
+ ACTION_PLACEHOLDER = "One of fixed, deferred, accepted or disagreed, each with a reason: fixed lists " \
35
+ "changed_members for current text changes, optional removed_members for map removals, " \
36
+ "and evidence and gives a reassessment; deferred gives recorded_at, " \
37
+ "where the write-up is, and may give waits_on; any other action leaves changed_members, " \
38
+ "evidence and reassessment as printed" #: String
39
+ # The action's placeholder, naming the finding.
40
+ ACTION = NamedPlaceholder.new("For #{NamedPlaceholder::SLOT}, #{ACTION_PLACEHOLDER.sub(/\AO/, "o")}",
41
+ before: ACTION_PLACEHOLDER) #: NamedPlaceholder
42
+ # Every placeholder a slot of a correction's template prints, for any finding.
43
+ NAMED = [*TEXT_FIELDS.values.map(&:placeholder), ACTION].freeze #: Array[NamedPlaceholder]
44
+ # Every placeholder a correction's template prints, each text field's and the action's, each with its slot.
45
+ TEMPLATE_PLACEHOLDERS = PLACEHOLDERS.merge("action" => ACTION.slotted).freeze #: Hash[String, String]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_place"
5
+ require_relative "answer_text"
6
+ require_relative "named_placeholder"
7
+ require_relative "unfinished_field"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # A text field the agent must write: the placeholder the correction template leaves in it, which an answer may
13
+ # not send back unchanged, and what to write instead; reassessment applies only to a fix.
14
+ class DispositionTextField
15
+ # The problem with a field the agent gave back as the answer guide's sample.
16
+ SAMPLE_UNCHANGED = "is the answer guide's sample, unchanged" #: String
17
+
18
+ # The placeholder, naming the finding of the disposition it is printed in.
19
+ #: NamedPlaceholder
20
+ attr_reader :placeholder
21
+
22
+ #: (placeholder: NamedPlaceholder, repair: String) -> void
23
+ def initialize(placeholder:, repair:)
24
+ @placeholder = placeholder
25
+ @repair = repair
26
+ freeze
27
+ end
28
+
29
+ # The field named name, at place, when value leaves it empty, as the placeholder for any finding or as sample,
30
+ # the answer guide's illustration of this field for the disposition's action, if it gives one.
31
+ #: (untyped, AnswerPlace, String, sample: String?) -> UnfinishedField?
32
+ def left_in(value, place, name, sample:)
33
+ problem = if !AnswerText.new(value).written? then "must be a nonempty string"
34
+ elsif @placeholder.left?(value) then "is the template's placeholder, unchanged"
35
+ elsif value == sample then SAMPLE_UNCHANGED
36
+ end
37
+ UnfinishedField.new(place, name, problem:, repair: @repair) if problem
38
+ end
39
+ end
40
+ end
41
+ end
@@ -30,7 +30,7 @@ module Principles
30
30
 
31
31
  # The lines it names in the project's file at commit, or nil when that commit lacks the file or its place there.
32
32
  #: (ProjectHistory, String) -> Array[String]?
33
- def lines_at(history, commit) = history.lines_at(commit, @locator)
33
+ def lines_at(history, commit) = history.at(commit).lines(@locator)
34
34
 
35
35
  # The lines it names in the project's file now; refused when it no longer resolves.
36
36
  #: (Project) -> Array[String]
@@ -0,0 +1,84 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "answer_place"
6
+ require_relative "answer_text"
7
+ require_relative "recorded_finding"
8
+ require_relative "waits_on"
9
+ require_relative "write_up_pointer"
10
+
11
+ module Principles
12
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
13
+ module Models
14
+ # One decision an answer to start-audit --open-findings gives on an open finding, between full audits: only the
15
+ # fields that change, each kept beside the finding with when and why. Whether the change is right is the agent's
16
+ # judgement; this tool checks its shape.
17
+ class FindingDecision
18
+ # The actions a decision may leave its finding at: those that keep it open. Closing it judges the problem
19
+ # against the text now, which is a full audit's work.
20
+ OPEN_ACTIONS = %w[deferred accepted].freeze #: Array[String]
21
+
22
+ # Each field a decision may give beside its finding_id, with its one-line meaning, which the template of
23
+ # start-audit --open-findings prints at its head in decision_fields, where an agent filling it reads.
24
+ FIELDS = {
25
+ "waits_on" => "One line, on a deferred finding only: whom it now waits on and to decide what. Or null, " \
26
+ "even on a deferred finding, to drop it.",
27
+ "action" => "deferred or accepted, as when the owner rules; its reason becomes the finding's own.",
28
+ "recorded_at" => "Where its write-up is now, in a committed file: {\"path\": ..., \"heading\": ...}, or null.",
29
+ "reason" => "One line saying why, required with any change. A field left out keeps its value; " \
30
+ "decision_fields may be kept or deleted."
31
+ }.freeze #: Hash[String, String]
32
+
33
+ # decision is one entry of the answer's decisions, at place in the answer, on a finding of principle_id's;
34
+ # recorded_at is its new pointer, already located, or nil when it gives none or null.
35
+ #: (Hash[String, untyped], AnswerPlace, principle_id: String, ?recorded_at: WriteUpPointer?) -> void
36
+ def initialize(decision, place, principle_id:, recorded_at: nil)
37
+ @decision = decision
38
+ @place = place
39
+ @principle_id = principle_id
40
+ @recorded_at = recorded_at
41
+ freeze
42
+ end
43
+
44
+ # The id of the finding it decides.
45
+ #: () -> String
46
+ def finding_id = @decision.fetch("finding_id")
47
+
48
+ # finding with this decision's changes made at at, its action before its wait, which is checked against the
49
+ # action it leaves; or finding itself when it changes nothing.
50
+ #: (RecordedFinding, at: String) -> RecordedFinding
51
+ def applied_to(finding, at:)
52
+ acted = @decision.key?("action") ? finding.acting(open_action, at:, reason:) : finding
53
+ acted = acted.pointed_at(@recorded_at, at:, reason:) if @decision.key?("recorded_at")
54
+ return acted unless @decision.key?("waits_on")
55
+
56
+ WaitsOn.new(@decision["waits_on"], action: acted.action).check(code: "invalid_answer",
57
+ subject: "Finding #{finding_id}")
58
+ acted.waiting_on(@decision["waits_on"], at:, reason:)
59
+ end
60
+
61
+ private
62
+
63
+ # The action it gives, refused unless it keeps the finding open.
64
+ #: () -> String
65
+ def open_action
66
+ action = @decision.fetch("action")
67
+ return action if OPEN_ACTIONS.include?(action)
68
+
69
+ raise @place.refusal(Error.new("invalid_answer",
70
+ "action #{action} closes the finding, which only a full audit judges",
71
+ "Give deferred or accepted, or run a full audit: " \
72
+ "#{Error::EXECUTABLE} start-audit #{@principle_id}"))
73
+ end
74
+
75
+ # Why it changes the finding, which the record keeps beside each change.
76
+ #: () -> String
77
+ def reason
78
+ AnswerText.new(@decision["reason"]).required("decision.reason")
79
+ rescue Error => e
80
+ raise @place.child("reason").refusal(e)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -12,7 +12,8 @@ module Principles
12
12
  # now.
13
13
  class FindingWriteUps
14
14
  # What to do about a recorded_at that no longer resolves, worded for a write-up rather than a member.
15
- REPAIR = "Fix the write-up, or point recorded_at at it again with start-audit --write-ups, without a full audit."
15
+ REPAIR = "Fix the write-up, or point recorded_at at it again with start-audit --open-findings, without a full " \
16
+ "audit."
16
17
  # What the repair adds when git detects a rename for the write-up's missing file.
17
18
  RENAMED = " git_detected_rename is git's match for its file, to #{MissingFiles::RENAME_MATCH}".freeze #: String
18
19
 
@@ -5,6 +5,7 @@ require_relative "../error"
5
5
  require_relative "audit_record"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # A principle's first full audit, which one background subagent runs from show-first-audit-brief so the session
10
11
  # that starts it spends little of its context on it: its id, and its record, or nil with none.
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "../error"
5
5
  require_relative "answer_text"
6
+ require_relative "named_placeholder"
6
7
 
7
8
  module Principles
8
9
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -12,8 +13,8 @@ module Principles
12
13
  # them as printed, and claims no change.
13
14
  class FixOnlyFields
14
15
  # disposition is the disposition as the agent gave it; left_reassessment is the reassessment its template
15
- # prints, which a disposition not fixed leaves as printed.
16
- #: (Hash[String, untyped], left_reassessment: String) -> void
16
+ # prints, for any finding, which a disposition not fixed leaves as printed.
17
+ #: (Hash[String, untyped], left_reassessment: NamedPlaceholder) -> void
17
18
  def initialize(disposition, left_reassessment:)
18
19
  @disposition = disposition
19
20
  @left_reassessment = left_reassessment
@@ -69,7 +70,7 @@ module Principles
69
70
  #: () -> void
70
71
  def fix_text_unclaimed
71
72
  reassessment = @disposition["reassessment"]
72
- written = reassessment != @left_reassessment && AnswerText.new(reassessment).written?
73
+ written = !@left_reassessment.left?(reassessment) && AnswerText.new(reassessment).written?
73
74
  field = ("reassessment" if written) || ("evidence" unless list("evidence").empty?) or return
74
75
  raise Error.new("invalid_disposition", "Only a fixed disposition may give #{field}",
75
76
  "Mark it fixed, or leave #{field} as printed.")
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "json_path_query"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The YAML frontmatter at the head of a Markdown file, read as lines and never parsed as YAML, since a
11
11
  # YAML parser over untrusted bytes is attack surface. A field is a top-level `key:` line and the indented,
@@ -4,7 +4,7 @@
4
4
  require_relative "../error"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # A glob the agent names for additional guidance inside this project, never a path outside it.
10
10
  class GuidanceSearchPath
@@ -5,7 +5,7 @@ require_relative "../data/guidance_search_paths_file"
5
5
  require_relative "guidance_search_path"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The additional guidance globs this project records, with one owner for normalized additions and removals.
11
11
  class GuidanceSearchPaths
@@ -42,6 +42,10 @@ module Principles
42
42
  #: (GuidanceSearchPaths) -> bool
43
43
  def same_as?(other) = @globs == other.globs
44
44
 
45
+ # The glob this list records that other did not, which a survey of just its matches reads; nil when none is.
46
+ #: (GuidanceSearchPaths) -> String?
47
+ def added_since(other) = (@globs - other.globs).first
48
+
45
49
  #: () -> String
46
50
  def save
47
51
  @file.write("format" => Data::GuidanceSearchPathsFile::FORMAT, "globs" => @globs)
@@ -5,6 +5,7 @@ require_relative "after_commit_input"
5
5
  require_relative "../data/head_reflog"
6
6
 
7
7
  module Principles
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
9
  module Models
9
10
  # Which repositories' HEAD a shell call moved by committing, each named once, in the order the call's
10
11
  # directories name them, with the commit HEAD named before the move: what report-after-commit reports on. A
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The candidate files git ignores, which this tool names but never reads. A folder git ignores can hold many
8
8
  # copies of instruction files written there by specs or builds, and listing each buries a file ignored on
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "../prose_list"
6
6
 
7
7
  module Principles
8
- # The domain of principles and their maps: each model owns its rules and loads and saves itself through data/.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The instruction field start-audit --instruction names, read whole from the request a full audit asks. Only a
11
11
  # field the request prints an instruction under can be read: the others explain fields it does not hold.
@@ -7,7 +7,7 @@ require_relative "json_path_string"
7
7
  require_relative "json_path_selectors"
8
8
 
9
9
  module Principles
10
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
12
  # A query in this tool's own profile of RFC 9535 JSONPath: from $, name selectors in dot or bracket
13
13
  # form, wildcards, and filters that keep the children whose relative paths equal strings, joined by &&.
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The selector * in a JSONPath query: every member value of an object, or every element of an array.
8
8
  class JsonPathWildcard
@@ -5,7 +5,7 @@ require "strscan"
5
5
  require_relative "../error"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # One quoted name or string in a JSONPath query, read as RFC 9535 writes it: single or double quotes, the
11
11
  # escapes it defines, and no raw control character. Anything else refuses the whole query.
@@ -5,7 +5,7 @@ require_relative "../error"
5
5
  require_relative "audit_record"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # The revision of a principle's last completed audit record when a request was printed, or nil when there was
11
11
  # none. An assessment's basis and a correction's carry it, so either answer is refused once that record changed,
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # Where two versions of a member's lines differ: each run of lines one side changed, in order, as a line diff finds
8
8
  # them by their longest common subsequence. The lines both sides share from the start and from the end are never
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
6
  module Models
7
7
  # The lines a member spans in its file, first to last, as a LocatedText gives them, and whether the member is
8
8
  # its whole file, so two members' spans are compared in one place.
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
5
6
  module Models
6
7
  # Literal loading-scope qualifiers for mapping feedback, distinct from persisted LoadingFacts.
7
8
  class LoadingScope
@@ -1,33 +1,32 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "digest"
4
5
  require_relative "line_span"
6
+ require_relative "locator"
5
7
 
6
8
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
10
  module Models
9
11
  # The text a locator found now: its file, the lines it spans and the hash of what it says. A Locator says where
10
- # to look; this is what was found there, as Project#locate finds it.
12
+ # to look; this is what was found there, as MemberFile#locate finds it.
11
13
  class LocatedText
12
- # The text found, from what Project#locate gives.
13
- #: (Hash[String, untyped]) -> LocatedText
14
- def self.of(found)
15
- new(path: found.fetch("path"), first_line: found.fetch("first_line"), last_line: found.fetch("last_line"),
16
- sha256: found.fetch("sha256"))
17
- end
18
-
19
14
  #: String
20
15
  attr_reader :path, :sha256
21
16
 
22
17
  #: Integer
23
18
  attr_reader :first_line, :last_line
24
19
 
25
- #: (path: String, first_line: Integer, last_line: Integer, sha256: String) -> void
26
- def initialize(path:, first_line:, last_line:, sha256:)
20
+ # path is the file's spelling as git tracks it, which may differ from the locator's in case; text is what
21
+ # was found, whose hash and length it keeps, so the two never disagree.
22
+ #: (locator: Locator, path: String, first_line: Integer, last_line: Integer, text: String) -> void
23
+ def initialize(locator:, path:, first_line:, last_line:, text:)
24
+ @locator = locator
27
25
  @path = path
28
26
  @first_line = first_line
29
27
  @last_line = last_line
30
- @sha256 = sha256
28
+ @sha256 = Digest::SHA256.hexdigest(text) #: String
29
+ @characters = text.length #: Integer
31
30
  freeze
32
31
  end
33
32
 
@@ -38,6 +37,15 @@ module Principles
38
37
  # Its first and last lines, as a request prints them.
39
38
  #: () -> Hash[String, Integer]
40
39
  def lines = { "first_line" => @first_line, "last_line" => @last_line }
40
+
41
+ # Where it was found and the hash of what it says, as show-principle prints a member's snapshot. query appears
42
+ # only for a locator that has one, so every other member's snapshot, and each request id digesting it, is
43
+ # unchanged.
44
+ #: () -> Hash[String, untyped]
45
+ def to_h
46
+ { "path" => @path, "heading" => @locator.heading, "starting_at" => @locator.starting_at,
47
+ "sha256" => @sha256, "characters" => @characters, **lines }.merge(@locator.to_h.slice("query"))
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -0,0 +1,66 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+ require_relative "../prose_list"
6
+ require_relative "principle"
7
+
8
+ module Principles
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
10
+ module Models
11
+ # How a principle's map differs from the one an audit's request was printed from: each field of the map, and of
12
+ # each member both maps hold, as it was and is now, which a stale request's refusal names.
13
+ class MapChange
14
+ #: (Principle, Principle) -> void
15
+ def initialize(base, current)
16
+ @base = base
17
+ @current = current
18
+ freeze
19
+ end
20
+
21
+ # Each change as a clause, such as: CLAUDE.md#Names's role was "a" and is now "b".
22
+ #: () -> String
23
+ def to_s = ProseList.new(clauses).to_s
24
+
25
+ # Whether it names no change, as when only the members' order, or which members the map holds, changed.
26
+ #: () -> bool
27
+ def empty? = clauses.empty?
28
+
29
+ # What an answer carried to a new request must judge again: each member whose entry changed, or, when a field of
30
+ # the map itself changed, every member.
31
+ #: () -> String
32
+ def to_judge_again
33
+ return "every member again against the map as it is now" unless map_fields.empty?
34
+
35
+ changed = @current.members.select { |member| member_fields_of(member).any? }.map(&:id)
36
+ entries = changed.one? ? "its map entry as it is" : "their map entries as they are"
37
+ "#{ProseList.new(changed)} again against #{entries} now"
38
+ end
39
+
40
+ private
41
+
42
+ #: () -> Array[String]
43
+ def clauses = map_fields + member_fields
44
+
45
+ #: () -> Array[String]
46
+ def map_fields = differing("its", @base.to_h.except("members"), @current.to_h.except("members"))
47
+
48
+ #: () -> Array[String]
49
+ def member_fields = @current.members.flat_map { |member| member_fields_of(member) }
50
+
51
+ # How member's entry differs from the one the base map holds under its key, none when it holds none.
52
+ #: (Member) -> Array[String]
53
+ def member_fields_of(member)
54
+ was = @base.members.with_key(member.key)
55
+ was ? differing("#{member.id}'s", was.to_h, member.to_h) : []
56
+ end
57
+
58
+ #: (String, Hash[String, untyped], Hash[String, untyped]) -> Array[String]
59
+ def differing(whose, was, now)
60
+ (was.keys | now.keys).reject { |field| was[field] == now[field] }.map do |field|
61
+ "#{whose} #{field} was #{JSON.generate(was[field])} and is now #{JSON.generate(now[field])}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -144,6 +144,10 @@ module Principles
144
144
  @files.relative(id)
145
145
  end
146
146
 
147
+ # Map id's file and each file holding one of its members, which a full audit judges as committed.
148
+ #: (String, PrincipleMembers) -> Array[String]
149
+ def audited_files(id, members) = [file(id), *members.paths]
150
+
147
151
  # The file map id was kept in under the folder's earlier name, relative to the project.
148
152
  #: (String) -> String
149
153
  def earlier_file(id)
@@ -3,15 +3,36 @@
3
3
 
4
4
  require_relative "member_file"
5
5
  require_relative "frontmatter_fields"
6
+ require_relative "prose_line"
6
7
 
7
8
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
9
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
10
  module Models
10
11
  # A Markdown file, where a member may be a section: a heading and what follows it, up to the next heading
11
12
  # at its level or above.
12
13
  class MarkdownFile < MemberFile
14
+ # The last line of the paragraph or list item that a passage named by its opening alone maps only the first
15
+ # line of, so the agent can judge whether it meant the whole; nil when no line continues it.
16
+ #: (Locator) -> Integer?
17
+ def continues_to(locator)
18
+ return unless locator.starting_at && !locator.ending_at
19
+
20
+ last = locate(locator).last_line
21
+ ending = block_end(last)
22
+ ending unless ending == last
23
+ end
24
+
13
25
  private
14
26
 
27
+ # The last line of the paragraph or list item that line, counted from 1, is in, read on from it; the line
28
+ # itself for a heading, a block of its own line.
29
+ #: (Integer) -> Integer
30
+ def block_end(line)
31
+ return line if ProseLine.new(@text.lines.fetch(line - 1)).heading?
32
+
33
+ line + @text.lines.drop(line).take_while { ProseLine.new(it).continues? }.length
34
+ end
35
+
15
36
  # The frontmatter field the reference's query names, or the section under its heading, or the whole text.
16
37
  #: (Array[String], Locator) -> [Integer, Integer]
17
38
  def region(lines, locator)
@@ -7,7 +7,7 @@ require_relative "meta_principle"
7
7
  require_relative "report_hooks"
8
8
 
9
9
  module Principles
10
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
12
  # One member of a principle as its map records it: a file, a Markdown section of it, or a passage
13
13
  # starting at a quoted first line. Its id names all three, so an agent can read where the member is
@@ -10,6 +10,7 @@ require_relative "principle_members"
10
10
  require_relative "answered_time"
11
11
  require_relative "member_sighting"
12
12
  require_relative "misspelt_member_id"
13
+ require_relative "named_placeholder"
13
14
  require_relative "record_judged_against"
14
15
  require_relative "reported_check"
15
16
  require_relative "template_placeholders"
@@ -25,10 +26,16 @@ module Principles
25
26
  # What a record entry keeps for a member carried forward, until completion puts back its last assessment.
26
27
  CARRIED = { "carried_forward" => true }.freeze #: Hash[String, untyped]
27
28
 
28
- # The text a fresh member's template prints in its assessment, which an answer may not send back unchanged, as a
29
- # correction may not send back its own.
29
+ # The text a fresh member's template printed in its assessment before each named its member, which an answer
30
+ # may not send back unchanged, as a correction may not send back its own.
30
31
  PLACEHOLDER = "Your assessment, including its context cost" #: String
31
32
 
33
+ # The text a fresh member's template prints in its assessment now, naming the member.
34
+ NAMED_PLACEHOLDER = "Your assessment of #{NamedPlaceholder::SLOT}, including its context cost".freeze #: String
35
+
36
+ # The assessment's placeholder, which any member's assessment leaves as printed for any member's id.
37
+ ASSESSMENT = NamedPlaceholder.new(NAMED_PLACEHOLDER, before: PLACEHOLDER) #: NamedPlaceholder
38
+
32
39
  # The text the template printed alone gives a sighting's fields beside delivery, each left as printed when the
33
40
  # delivery gives none.
34
41
  SIGHTING = TemplatePlaceholders.new(
@@ -74,12 +81,12 @@ module Principles
74
81
 
75
82
  # Each member's assessment by id, as its record entry keeps it: what the agent said, and the hash of each piece
76
83
  # of evidence it cited, which the block locates, so the next audit can say whether that evidence changed.
77
- #: () { (Locator) -> Hash[String, untyped] } -> Hash[String, Hash[String, untyped]]
84
+ #: () { (Locator) -> LocatedText } -> Hash[String, Hash[String, untyped]]
78
85
  def kept(&locate)
79
86
  @assessments.to_h do |assessment|
80
87
  next [assessment.fetch("member_id"), { "assessment" => CARRIED }] if carried_forward?(assessment)
81
88
 
82
- hashes = assessment.fetch("evidence").map { |reference| locate.call(Locator.new(reference)).fetch("sha256") }
89
+ hashes = assessment.fetch("evidence").map { |reference| locate.call(Locator.new(reference)).sha256 }
83
90
  [assessment.fetch("member_id"),
84
91
  { "assessment" => assessment.slice("assessment", "delivery", "observation", "observed_at", "evidence")
85
92
  .reject { |key, value| key == "observed_at" && value.nil? }
@@ -5,7 +5,7 @@ require_relative "line_span"
5
5
  require_relative "member"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # A member of another principle's map whose text shares a line with one located member: its principle, id,
11
11
  # role there and lines, and how its lines stand to the located member's: the same lines, all of them, within