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
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
+ require_relative "../models/carried_member"
5
6
  require_relative "../models/check_since_last_audit"
6
7
  require_relative "../models/open_findings_elsewhere"
7
8
  require_relative "../views/acknowledged_since_last_audit"
@@ -38,7 +39,7 @@ module Principles
38
39
  @principle_id = principle_id
39
40
  @record = @audit_records.find(principle_id) #: Models::AuditRecord?
40
41
  @completed = @record&.last_completed #: Models::AuditRecord?
41
- @checks = Models::CheckSinceLastAudit.new(id: principle_id, history: @history, member_maps: @member_maps,
42
+ @checks = Models::CheckSinceLastAudit.new(id: principle_id, history: @history, principles: @principles,
42
43
  record: @record) #: Models::CheckSinceLastAudit
43
44
  end
44
45
 
@@ -52,17 +53,24 @@ module Principles
52
53
  map = audit.map
53
54
  carried = carried_assessments(audit)
54
55
  elsewhere = elsewhere(map, current)
55
- members = map.members_shown.map do |fields|
56
- member = Models::Member.new(fields)
57
- judged = carried(member, carried)
58
- located(member, current).merge(checked(member), acknowledged(fields), judged,
59
- changed_since(fields, judged), shared_lines(member, elsewhere))
60
- end
56
+ members = map.members_shown.map { |fields| member_listed(fields, carried, elsewhere, current) }
61
57
  Listing.new(members: members, open_findings_elsewhere: elsewhere_listed(elsewhere, current))
62
58
  end
63
59
 
64
60
  private
65
61
 
62
+ # One member of the map, from its fields there, as the request lists it: located as current has it, with its
63
+ # check, the edits acknowledged since the last full audit, its carried assessment or why it is judged again,
64
+ # and the other principles' members sharing its lines.
65
+ #: (Hash[String, untyped], Models::CarriedAssessments, Models::OpenFindingsElsewhere, Models::MemberSnapshots)
66
+ #| -> Hash[String, untyped]
67
+ def member_listed(fields, carried, elsewhere, current)
68
+ member = Models::Member.new(fields)
69
+ judged = carried(member, carried, elsewhere)
70
+ located(member, current).merge(checked(member), acknowledged(fields), judged,
71
+ changed_since(fields, judged), shared_lines(member, elsewhere))
72
+ end
73
+
66
74
  # Each finding elsewhere names, once, with each evidence item's lines beside this audit's members, where current
67
75
  # locates them; the project locates each item now (D64).
68
76
  #: (Models::OpenFindingsElsewhere, Models::MemberSnapshots) -> Array[Hash[String, untyped]]
@@ -74,7 +82,7 @@ module Principles
74
82
  # findings their records leave open on them, each record read once (#772, D62). The request id hashes this
75
83
  # principle's members, not other maps or their records: another principle changing after the request is its
76
84
  # own audit to judge, and does not make this one stale.
77
- #: (Models::MemberMap, Models::MemberSnapshots) -> Models::OpenFindingsElsewhere
85
+ #: (Models::Principle, Models::MemberSnapshots) -> Models::OpenFindingsElsewhere
78
86
  def elsewhere(map, current)
79
87
  sharing = map.members.ids.to_h do |id|
80
88
  [id, Models::MembersSharingLines.new(@project, current.of(id), id: id).elsewhere(except: @principle_id)]
@@ -92,16 +100,25 @@ module Principles
92
100
 
93
101
  # The member's last assessment carried forward, with whether any evidence it cited changed since and, in git,
94
102
  # whether its file changed since the last full audit's base commit, outside the member, whose own text did not;
95
- # or why it is judged again. These are facts: the agent may re-judge any carried member (D49).
96
- #: (Models::Member, Models::CarriedAssessments) -> Hash[String, untyped]
97
- def carried(member, carried)
103
+ # or why it is judged again. These are facts: the agent may re-judge any carried member (D49). flagged says
104
+ # whether any fires, or another principle leaves a finding open on its lines, so the request prints the member
105
+ # whole rather than compactly (D93).
106
+ #: (Models::Member, Models::CarriedAssessments, Models::OpenFindingsElsewhere) -> Hash[String, untyped]
107
+ def carried(member, carried, elsewhere)
98
108
  shown = carried.shown(member.id) { |locator, sha| evidence_changed?(locator, sha) }
99
- kept = shown["carried_forward"]
100
- base = @completed&.base_commit
101
- return shown unless kept && base
109
+ kept = shown["carried_forward"] or return shown
110
+
111
+ Models::CarriedMember.new(kept, file_changed_outside_member: file_changed_outside(member),
112
+ open_elsewhere: elsewhere.open_beside?(member.id),
113
+ open_here: @record&.open_ids_on(member.key) || []).shown
114
+ end
115
+
116
+ # Whether member's file changed since the last full audit's base commit; nil with no such commit, as outside git.
117
+ #: (Models::Member) -> bool?
118
+ def file_changed_outside(member)
119
+ base = @completed&.base_commit or return
102
120
 
103
- { "carried_forward" => kept.merge("file_changed_outside_member" =>
104
- @history.commits_since(base, member.path).any?) }
121
+ @history.commits_since(base, member.path).any?
105
122
  end
106
123
 
107
124
  # Whether the evidence at locator no longer hashes to sha, or can no longer be found.
@@ -127,7 +144,7 @@ module Principles
127
144
  base = @completed&.base_commit
128
145
  return {} unless judged["judge_because"] && base
129
146
 
130
- paths = map_history(@principle_id).paths_from(base, Models::Member.new(fields).key, fields)
147
+ paths = principle_history(@principle_id).paths_from(base, Models::Member.new(fields).key, fields)
131
148
  { "read_the_change" => Views::DiffSinceLastAudit.new(last_audited_commit: base, paths: paths).to_s }
132
149
  end
133
150
 
@@ -150,10 +167,8 @@ module Principles
150
167
 
151
168
  #: (Models::Member) -> Hash[String, untyped]
152
169
  def checked(member)
153
- check = member.check or return {}
154
170
  hidden = member.check_hidden_characters
155
- { "check" => check, "check_since_last_audit" => @checks.of(member, check) }
156
- .merge(hidden.empty? ? {} : { "check_hidden_characters" => hidden })
171
+ @checks.entry(member).merge(hidden.empty? ? {} : { "check_hidden_characters" => hidden })
157
172
  end
158
173
  end
159
174
  end
@@ -32,7 +32,7 @@ module Principles
32
32
  # to judge whether one is the passage.
33
33
  #: () -> untyped
34
34
  def show_meta_principle_passage
35
- map = @member_maps.addable(Models::MetaPrinciple::ID)
35
+ map = @principles.addable(Models::MetaPrinciple::ID)
36
36
  view = meta_principle_result
37
37
  view.proposal(printed_principle(map), placement(view), map_in_project(map),
38
38
  existing_principles: existing_principles).merge("wrote" => [])
@@ -40,17 +40,17 @@ module Principles
40
40
 
41
41
  # map as the project holds it: whether it was there before this run, its members already in an entry file, and
42
42
  # whether principles is set up, its map having a member (D75).
43
- #: (Models::MemberMap) -> Views::MetaPrincipleResult::MapInProject
43
+ #: (Models::Principle) -> Views::MetaPrincipleResult::MapInProject
44
44
  def map_in_project(map)
45
45
  Views::MetaPrincipleResult::MapInProject.new(
46
- already_mapped: @member_maps.mapped?(map.id), members_in_entry_files: map.members_in(Models::EntryFiles::PATHS),
47
- set_up: @member_maps.set_up?
46
+ already_mapped: @principles.mapped?(map.id), members_in_entry_files: map.members_in(Models::EntryFiles::PATHS),
47
+ set_up: @principles.set_up?
48
48
  )
49
49
  end
50
50
 
51
51
  # The project's other principles, as list-principles lists them, which this principle's first audit keeps held.
52
52
  #: () -> Array[Hash[String, untyped]]
53
- def existing_principles = handed(Inventory).rows(@member_maps.ids - [Models::MetaPrinciple::ID])
53
+ def existing_principles = handed(Inventory).rows(@principles.ids - [Models::MetaPrinciple::ID])
54
54
 
55
55
  # Where the passage can go: how this run was started and whether the hook runs in this session, the project's
56
56
  # entry files, and the passage.
@@ -2,9 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "time"
5
- require_relative "command"
5
+ require_relative "answer_phase"
6
6
  require_relative "../models/finding_write_ups"
7
- require_relative "../models/last_completed_revision"
8
7
  require_relative "../models/repoint"
9
8
  require_relative "../views/repoint_result"
10
9
 
@@ -14,51 +13,48 @@ module Principles
14
13
  module Controllers
15
14
  # A repoint of a principle's open findings' write-ups (D59): start-audit ID --write-ups lists each open finding
16
15
  # with where its write-up is now, and submit-answer points the recorded_at the agent gives in the audit record.
17
- class Repoint < Command
16
+ class Repoint < AnswerPhase
18
17
  # The request for principle id's open findings.
19
18
  #: (String) -> Hash[String, untyped]
20
19
  def start(id)
21
20
  naming_the_executable do
22
21
  record = @audit_records.find(id)
23
- repoint = Models::Repoint.new(principle_id: id, record: record, history: @history)
22
+ repoint = repoint_of(id, record)
24
23
  findings = Models::FindingWriteUps.of(@project, [record].compact).listed
25
24
  view.request(request_id: repoint.request_id.to_s, principle_id: id, revision: repoint.revision,
26
25
  findings: findings).merge("wrote" => [])
27
26
  end
28
27
  end
29
28
 
30
- # The result of answering request_id with response, and the record it changes, not yet written. It is
31
- # refused once the last completed record changed after the request was printed, unless it writes nothing.
32
- #: (Models::RequestId, untyped) -> [Hash[String, untyped], Array[Models::AuditRecord]]
33
- def answered(request_id, response)
34
- id = request_id.principle_id
35
- record = @audit_records.find(id)
36
- repoint = Models::Repoint.new(principle_id: id, record: record, history: @history)
37
- repointed = repoint.accepted(response, at: Time.now.utc.iso8601) { |locator| snapshot(locator) }
38
- changes = writable_changes(record, repointed, response.dig("basis", "revision"))
29
+ # The result of answering, and the record it changes, not yet written, which the repoint refuses once the last
30
+ # completed record changed after the request was printed, unless it writes nothing.
31
+ # @override
32
+ #: (Models::SubmittedAnswer) -> [Hash[String, untyped], Array[Models::AuditRecord]]
33
+ def answered(submitted)
34
+ id = submitted.request_id.principle_id
35
+ response = submitted.response
36
+ repoint = repoint_of(id, @audit_records.find(id))
37
+ repointed, changes = repoint.writable(response, records: @audit_records, at: Time.now.utc.iso8601) do |locator|
38
+ snapshot(locator)
39
+ end
39
40
  [view.repointed(principle_id: id, file: @audit_records.file(id), outcome: outcome(repoint, repointed)), changes]
40
41
  end
41
42
 
42
43
  private
43
44
 
45
+ # The repoint of principle id's open findings, as its record holds them.
46
+ #: (String, Models::AuditRecord?) -> Models::Repoint
47
+ def repoint_of(id, record) = Models::Repoint.new(principle_id: id, record: record, history: @history)
48
+
44
49
  # What the repoint did, and each other principle's open finding whose write-up cannot be found (T16).
45
50
  #: (Models::Repoint, Models::AuditRecord) -> Views::RepointResult::Outcome
46
51
  def outcome(repoint, repointed)
47
- others = @audit_records.of(@member_maps.ids - [repointed.principle_id])
52
+ others = @audit_records.of(@principles.ids - [repointed.principle_id])
48
53
  Views::RepointResult::Outcome.new(repointed: repoint.moved_ids(repointed),
49
54
  unchanged: repoint.unchanged_ids(repointed),
50
55
  not_found_elsewhere: Models::FindingWriteUps.of(@project, others).not_found)
51
56
  end
52
57
 
53
- # The records repointed changes from record. Refused once record changed after the request, whose revision the
54
- # answer quotes back, was printed, unless there are none.
55
- #: (Models::AuditRecord?, Models::AuditRecord, String?) -> Array[Models::AuditRecord]
56
- def writable_changes(record, repointed, revision)
57
- changes = @audit_records.changes(repointed)
58
- Models::LastCompletedRevision.new(revision).confirm_writable(repointed.principle_id, record, changes)
59
- changes
60
- end
61
-
62
58
  #: () -> Views::RepointResult
63
59
  def view
64
60
  Views::RepointResult.new(invocation)
@@ -29,7 +29,7 @@ module Principles
29
29
 
30
30
  # The release of principles this run comes from, as the audit of map's principle keeps it: the version running
31
31
  # and the passage as setup prints it, which only a view holds; nil for a principle whose audit keeps none (D68).
32
- #: (Models::MemberMap) -> Models::PrinciplesPackage?
32
+ #: (Models::Principle) -> Models::PrinciplesPackage?
33
33
  def release_kept_by(map)
34
34
  return unless map.keeps_package?
35
35
 
@@ -33,21 +33,25 @@ module Principles
33
33
  @directory.exist?(id)
34
34
  end
35
35
 
36
- # The record of id's last audit, or nil when it has none, checked against its schema (D29).
37
- #: (String) -> Hash[String, untyped]?
38
- def read(id)
36
+ # The record of id's last audit, or nil when it has none, checked against its schema (D29), handing the block
37
+ # a record the schema refuses, as parse does.
38
+ #: (String) ?{ (untyped) -> void } -> Hash[String, untyped]?
39
+ def read(id, &)
39
40
  return unless exist?(id)
40
41
 
41
- parse(id, @directory.read(id, shown_as: relative(id)))
42
+ parse(id, @directory.read(id, shown_as: relative(id)), &)
42
43
  end
43
44
 
44
- # The record of id from its text, with an older version's key upgraded, checked against its schema (D29).
45
- #: (String, String) -> Hash[String, untyped]
46
- def parse(id, text)
45
+ # The record of id from its text, with an older version's key upgraded, checked against its schema (D29). A
46
+ # record the schema refuses is handed to the block first, which may refuse it otherwise, as a model does one a
47
+ # later copy wrote (D85).
48
+ #: (String, String) ?{ (untyped) -> void } -> Hash[String, untyped]
49
+ def parse(id, text, &)
47
50
  record = upgraded(JsonText.new(text).parsed)
48
51
  problems = SchemaCheck.new("audit-record").problems(record)
49
52
  return record if problems.empty?
50
53
 
54
+ yield record if block_given?
51
55
  raise Error.new("invalid_audit_record", "#{relative(id)} is not in the shape this tool writes",
52
56
  "Repair each field listed, or restore the record from version control.", relative(id),
53
57
  fields: problems)
@@ -12,18 +12,23 @@ module Principles
12
12
  # Far above any instruction file, map, audit record or answer, and far below what exhausts memory.
13
13
  LIMIT = 4 * 1024 * 1024 #: Integer
14
14
 
15
- #: (String, ?shown_as: String) -> void
16
- def initialize(path, shown_as: path)
15
+ # shown_as is the path a refusal gives; named is what its message calls the file, such as "The answer" for a
16
+ # file the agent named and holds the path of (#1118).
17
+ #: (String, ?shown_as: String, ?named: String) -> void
18
+ def initialize(path, shown_as: path, named: shown_as)
17
19
  @path = path
18
20
  @shown_as = shown_as
21
+ @named = named
19
22
  freeze
20
23
  end
21
24
 
22
25
  # The file's text, read once it is known to be a regular file within LIMIT.
23
26
  #: (?encoding: String) -> String
24
27
  def read(encoding: "UTF-8")
28
+ raise Error.new("unreadable_file", "#{@named} does not exist", "Name a file that exists.", @shown_as) unless
29
+ File.exist?(@path)
25
30
  unless File.file?(@path)
26
- raise Error.new("not_a_file", "#{@shown_as} is not a regular file", "Name a regular file.", @shown_as)
31
+ raise Error.new("not_a_file", "#{@named} is not a regular file", "Name a regular file.", @shown_as)
27
32
  end
28
33
 
29
34
  refuse_larger(File.size(@path))
@@ -31,12 +36,23 @@ module Principles
31
36
  File.read(@path, encoding: encoding)
32
37
  end
33
38
 
39
+ # A bounded regular file whose text must also be valid UTF-8, as project members require.
40
+ #: () -> String
41
+ def read_text
42
+ text = read
43
+ unless text.valid_encoding?
44
+ raise Error.new("invalid_encoding", "Cannot read UTF-8 text", "Choose a text member.", @shown_as)
45
+ end
46
+
47
+ text
48
+ end
49
+
34
50
  # Refuses bytes of text, such as stdin's, that are more than this tool reads from one file.
35
51
  #: (Integer) -> void
36
52
  def refuse_larger(bytes)
37
53
  return if bytes <= LIMIT
38
54
 
39
- raise Error.new("file_too_large", "#{@shown_as} holds #{bytes} bytes, more than the #{LIMIT} bytes " \
55
+ raise Error.new("file_too_large", "#{@named} holds #{bytes} bytes, more than the #{LIMIT} bytes " \
40
56
  "read at most",
41
57
  "Name a smaller file, or map a smaller part of it.", @shown_as)
42
58
  end
@@ -11,6 +11,7 @@
11
11
  "any-command": ["file_too_large", "invalid_invocation", "invalid_shape", "filesystem_error", "unknown_command", "missing_id", "invalid_command_steps"],
12
12
  "read-map": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unknown_principle", "unparseable_map", "invalid_map", "newer_format", "duplicate_member"],
13
13
  "read-audit": ["principles_folder_not_moved", "both_principles_folders", "symlinked_directory", "unparseable_audit", "invalid_audit_record"],
14
+ "rewrite-audit": ["newer_audit_record"],
14
15
  "locate-text": ["outside_project", "not_a_file", "unreadable_file", "invalid_encoding", "section_needs_markdown", "query_needs_frontmatter", "query_with_other_locators", "unsupported_query", "unsupported_frontmatter", "duplicate_frontmatter_key", "field_not_found", "section_not_found",
15
16
  "ambiguous_heading", "passage_not_found", "ambiguous_passage", "passage_end_not_found",
16
17
  "broken_members"]
@@ -24,7 +25,7 @@
24
25
  { "id": "list-instruction-files", "actor": "cli",
25
26
  "does": "Lists the instruction files agent hosts load by convention, naming git-ignored ones unread rather than listing them, each folder git ignores counted once, leaving out folders that hold their own git repository, and names any under a fixtures, examples or samples folder and, in git, any git does not track." },
26
27
  { "id": "choose-one-principle", "actor": "agent",
27
- "does": "Choose one principle several listed files reinforce. Decide whether each file named in possibly_test_data is guidance or a sample.",
28
+ "does": "Show the user a table of the principles several listed files reinforce, asking nothing before it, then choose one to map with the user. Decide whether each file named in possibly_test_data is guidance or a sample.",
28
29
  "prompt": "find-a-principle-to-map/choose-one-principle",
29
30
  "cannot_check": "whether a file is guidance or test data; ask the project's owner when you cannot tell.",
30
31
  "answer_with": "create-principle" }
@@ -46,7 +47,7 @@
46
47
  "help": "learn-what-a-command-does/list-member-problems",
47
48
  "steps": [
48
49
  { "id": "compare-members-with-their-baselines", "actor": "cli",
49
- "does": "Finds each member of map ID, or of every map, and compares its own text with the last audit's hash for it, or else with its text at the commit that mapped it where it is. Refuses while any member cannot be found or read, or a map cannot be read, so a gate can stop on the exit status; otherwise lists each changed member with what it was compared with, and counts every state. With --short, prints one tab-separated line per changed member and exits 3 when any changed.",
50
+ "does": "Finds each member of map ID, or of every map, and compares its own text with the last audit's hash for it, or else with its text at the commit that mapped it where it is. Refuses while any member cannot be found or read, or a map cannot be read, so a gate can stop on the exit status; otherwise lists each changed member with what it was compared with, and counts every state. With --short, prints one tab-separated line per changed member and exits 3 when a member an audit assessed changed, and 4 when the only changes are edits to members no audit has assessed.",
50
51
  "refuses": ["broken_members"], "refuses_like": ["read-map", "read-audit"] },
51
52
  { "id": "repair-or-audit", "actor": "agent",
52
53
  "does": "For a refusal, say whether each listed member moved or is gone, and repair it. For a changed member, audit its principle when the change was meant to alter the principle.",
@@ -80,7 +81,7 @@
80
81
  "help": "learn-what-a-command-does/list-open-findings",
81
82
  "steps": [
82
83
  { "id": "read-open-findings", "actor": "cli",
83
- "does": "Reads the last audit record of principle ID, or of every principle, and lists each deferred or accepted finding with its action, its members, its recorded_at pointer and when the audit was made. Says that an earlier audit's open findings are only in git. With --short, prints one line saying how many are open, how long the oldest has waited and what it waits on, and nothing when none is open; --session-start clear or compact words it for a context just cleared or compacted.",
84
+ "does": "Reads the last audit record of principle ID, or of every principle, and lists each deferred or accepted finding with its action, its members, its recorded_at pointer and when the audit was made. Says that an earlier audit's open findings are only in git. With --short, prints one line saying how many are open, how long the oldest has waited and what it waits on, and nothing when none is open; --session-start clear or compact words it for a context just cleared or compacted, and resume shortens it to the facts, since a resumed conversation holds the whole line already.",
84
85
  "refuses_like": ["read-map", "read-audit"] },
85
86
  { "id": "follow-up-each-finding", "actor": "agent",
86
87
  "does": "Read each finding where its recorded_at points, and decide each one at its principle's next full audit.",
@@ -89,7 +90,7 @@
89
90
  ]
90
91
  },
91
92
  {
92
- "name": "show-answer-check", "usage": "show-answer-check REQUEST --file FILE|-", "group": "read", "options": ["file"],
93
+ "name": "show-answer-check", "usage": "show-answer-check REQUEST_ID --file FILE|-", "group": "read", "options": ["file"], "requires": ["file"],
93
94
  "summary": "Check an answer without submitting it.",
94
95
  "help": "learn-what-a-command-does/show-answer-check",
95
96
  "steps": [
@@ -98,7 +99,7 @@
98
99
  "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request", "stale_request", "stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git",
99
100
  "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding",
100
101
  "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes"],
101
- "refuses_like": ["read-map", "read-audit", "locate-text"] },
102
+ "refuses_like": ["read-map", "read-audit", "locate-text", "rewrite-audit"] },
102
103
  { "id": "submit-the-checked-answer", "actor": "agent",
103
104
  "does": "Fix what a refusal names and check again, or submit the answer unchanged.",
104
105
  "answer_with": "submit-answer" }
@@ -217,13 +218,13 @@
217
218
  ]
218
219
  },
219
220
  {
220
- "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups]", "group": "write-audit-record", "options": ["member", "write-ups"],
221
+ "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups] [--as template | --instruction FIELD]", "group": "write-audit-record", "options": ["member", "write-ups", "as", "instruction"],
221
222
  "summary": "Ask for an assessment of every member and the set.",
222
223
  "help": "learn-what-a-command-does/start-audit",
223
224
  "steps": [
224
225
  { "id": "snapshot-members", "actor": "cli",
225
- "does": "Refuses an empty map or, in git, an uncommitted map or member file; bases the audit on HEAD. Writes nothing.",
226
- "refuses": ["map_has_no_members", "uncommitted_files"], "refuses_like": ["read-map", "locate-text"],
226
+ "does": "Refuses an empty map or, in git, an uncommitted map or member file; bases the audit on HEAD. Fill --as template's output with your own judgement, under $TMPDIR; its left_as_printed_rule says how a field left as printed is read.",
227
+ "refuses": ["map_has_no_members", "uncommitted_files", "unknown_instruction"], "refuses_like": ["read-map", "locate-text", "rewrite-audit"],
227
228
  "next": [{ "to": "assess-every-member", "when": "you passed neither --member nor --write-ups" },
228
229
  { "to": "start-acknowledgement", "when": "you passed --member" },
229
230
  { "to": "start-repointing", "when": "you passed --write-ups" }] },
@@ -234,7 +235,7 @@
234
235
  "cannot_check": "whether your assessment is true, a member reached your context, or your findings are the right ones.",
235
236
  "answer_with": "submit-answer" },
236
237
  { "id": "start-acknowledgement", "actor": "cli",
237
- "does": "With --member, starts a one-member audit instead: in git, for a member the last completed audit assessed whose text changed since, names its baseline commit and the change to read. Writes nothing.",
238
+ "does": "With --member, starts a one-member audit, or with --as template its answer alone: in git, for a member the last completed audit assessed that changed since, names its baseline commit and the change to read. Writes nothing.",
238
239
  "refuses": ["cannot_acknowledge"] },
239
240
  { "id": "judge-the-change", "actor": "agent",
240
241
  "does": "Say whether the change keeps the member's principle, with a one-line reason and a quote from then and now.",
@@ -248,18 +249,18 @@
248
249
  ]
249
250
  },
250
251
  {
251
- "name": "submit-answer", "usage": "submit-answer REQUEST --file FILE|-", "group": "write-audit-record", "options": ["file"],
252
+ "name": "submit-answer", "usage": "submit-answer REQUEST_ID --file FILE|-", "group": "write-audit-record", "options": ["file"], "requires": ["file"],
252
253
  "summary": "Give the answer a request asked for.",
253
254
  "help": "learn-what-a-command-does/submit-answer",
254
255
  "steps": [
255
256
  { "id": "match-request", "actor": "cli",
256
- "does": "Reads FILE, or stdin for -, and checks that its request_id is REQUEST, an id this tool prints.",
257
- "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request"],
257
+ "does": "Reads FILE, or stdin for -, and checks that its request_id is REQUEST_ID, an id this tool prints.",
258
+ "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request"], "refuses_like": ["rewrite-audit"],
258
259
  "next": [{ "to": "acknowledge-the-change", "when": "the request was a one-member audit" },
259
260
  { "to": "record-the-repoints", "when": "the request was a repoint of write-ups" },
260
261
  { "to": "recheck-members", "when": "the request was an assessment or a correction" }] },
261
262
  { "id": "acknowledge-the-change", "actor": "cli",
262
- "does": "For a one-member audit, checks that the answer says the meaning is kept, with a one-line reason and a quote of the member then and now, then moves its hash in the audit record and keeps the acknowledgement beside it.",
263
+ "does": "For a one-member audit, checks the answer's kept meaning, one-line reason, quotes then and now and any check result, then moves the member's hash and check result in the audit record beside the acknowledgement.",
263
264
  "refuses": ["stale_request", "cannot_acknowledge", "quote_not_found"] },
264
265
  { "id": "commit-the-acknowledgement", "actor": "agent",
265
266
  "does": "Commit the audit record, then check that list-member-problems --short no longer reports the member.",
@@ -14,7 +14,7 @@ module Principles
14
14
  # .principles/maps/, committed in the audited repository. A map holds a description and its members,
15
15
  # each a project file, optionally narrowed to one Markdown section, with the role it plays.
16
16
  class MapFiles
17
- # The newest map format this version reads. Models::MemberMap says which member fields need which
17
+ # The newest map format this version reads. Models::Principle says which member fields need which
18
18
  # format, and a spec ties the two together.
19
19
  NEWEST_FORMAT = 2
20
20
 
@@ -39,7 +39,7 @@ module Principles
39
39
  @directory.exist?(id)
40
40
  end
41
41
 
42
- # The map id, which exists: Models::MemberMaps refuses one that does not, since which command creates it is
42
+ # The map id, which exists: Models::MappedPrinciples refuses one that does not, since which command creates it is
43
43
  # a decision.
44
44
  #: (String) -> Hash[String, untyped]
45
45
  def read(id)
@@ -38,7 +38,7 @@ module Principles
38
38
  # whose maps or records have not moved. A file an older version left beside no subfolder holds none.
39
39
  #: () -> Array[String]
40
40
  def held_in
41
- [FOLDER, EARLIER_FOLDER].select { |folder| File.directory?(File.join(@root, folder, @name)) }
41
+ [FOLDER, EARLIER_FOLDER].select { |folder| directory?(File.join(@root, folder, @name)) }
42
42
  end
43
43
 
44
44
  # The file id names in this directory.
@@ -78,6 +78,13 @@ module Principles
78
78
 
79
79
  private
80
80
 
81
+ #: (String) -> bool
82
+ def directory?(path)
83
+ File.stat(path).directory?
84
+ rescue Errno::ENOENT, Errno::ENOTDIR
85
+ false
86
+ end
87
+
81
88
  #: (String) -> void
82
89
  def refuse_link(relative)
83
90
  return unless File.symlink?(File.join(@root, relative))
@@ -25,13 +25,7 @@ module Principles
25
25
  # Models::MemberFile finds a member's place in it.
26
26
  #: (String) -> String
27
27
  def read_text(path)
28
- text = BoundedFile.new(resolve(path), shown_as: path).read
29
- unless text.valid_encoding?
30
- raise Error.new("invalid_encoding", "Cannot read UTF-8 text", "Choose a text member.",
31
- path)
32
- end
33
-
34
- text
28
+ BoundedFile.new(resolve(path), shown_as: path).read_text
35
29
  rescue SystemCallError => e
36
30
  raise Error.new("unreadable_file", e.message, "Restore a readable project-local file, then retry.", path)
37
31
  end
@@ -88,17 +82,20 @@ module Principles
88
82
  #: () -> Hash[String, untyped]
89
83
  def inventory = CandidateFilesFound.new(self).to_h
90
84
 
91
- #: (String) -> untyped
92
- def read_json(path)
93
- parse_json(BoundedFile.new(path).read, path)
85
+ # JSON from the file at path, which a refusal's message calls named (#1118).
86
+ #: (String, ?named: String) -> untyped
87
+ def read_json(path, named: path)
88
+ parse_json(BoundedFile.new(path, named:).read, path, named:)
94
89
  rescue SystemCallError => e
95
- raise Error.new("unreadable_file", e.message, "Supply a readable JSON file.", path)
90
+ # The system's reason alone, such as "Permission denied", without the path its message ends with.
91
+ reason = e.class.new(nil).message
92
+ raise Error.new("unreadable_file", "#{named} cannot be read: #{reason}", "Supply a readable JSON file.", path)
96
93
  end
97
94
 
98
- # JSON from text read elsewhere, such as stdin, named by source in a refusal.
99
- #: (String, String) -> untyped
100
- def parse_json(text, source)
101
- BoundedFile.new(source).refuse_larger(text.bytesize)
95
+ # JSON from text read elsewhere, such as stdin, given by source in a refusal, whose message calls it named.
96
+ #: (String, String, ?named: String) -> untyped
97
+ def parse_json(text, source, named: source)
98
+ BoundedFile.new(source, named:).refuse_larger(text.bytesize)
102
99
  JsonText.new(text).parsed
103
100
  rescue JSON::ParserError => e
104
101
  raise Error.new("unparseable_json", e.message, "Repair this JSON and retry; no response was accepted.",
@@ -0,0 +1,48 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "principles_subfolder"
5
+
6
+ module Principles
7
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
8
+ module Data
9
+ # The physical project boundary selected from an implicit working directory.
10
+ class ProjectRoot
11
+ #: (String) -> void
12
+ def initialize(directory)
13
+ @selected = File.realpath(directory) #: String
14
+ freeze
15
+ end
16
+
17
+ #: () -> String
18
+ def path
19
+ directory = @selected
20
+ loop do
21
+ return directory if store?(directory)
22
+ return @selected if entry?(directory, ".git") || File.dirname(directory) == directory
23
+
24
+ directory = File.dirname(directory)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ #: (String) -> bool
31
+ def store?(directory)
32
+ return true if entry?(directory, PrinciplesSubfolder::FOLDER)
33
+
34
+ %w[maps audits].any? do |name|
35
+ PrinciplesSubfolder.new(directory, name).held_in.include?(PrinciplesSubfolder::EARLIER_FOLDER)
36
+ end
37
+ end
38
+
39
+ #: (String, String) -> bool
40
+ def entry?(directory, name)
41
+ File.lstat(File.join(directory, name))
42
+ true
43
+ rescue Errno::ENOENT
44
+ false
45
+ end
46
+ end
47
+ end
48
+ end