principles 0.0.5 → 0.0.7

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 (192) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/cli.rb +9 -0
  4. data/lib/principles/command_line.rb +31 -30
  5. data/lib/principles/command_routes.rb +9 -3
  6. data/lib/principles/controllers/acknowledgement.rb +82 -95
  7. data/lib/principles/controllers/answer.rb +14 -11
  8. data/lib/principles/controllers/assessment.rb +27 -24
  9. data/lib/principles/controllers/audit.rb +24 -4
  10. data/lib/principles/controllers/audit_completion.rb +10 -4
  11. data/lib/principles/controllers/command.rb +2 -2
  12. data/lib/principles/controllers/correction.rb +16 -7
  13. data/lib/principles/controllers/full_audit_request.rb +8 -3
  14. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  15. data/lib/principles/controllers/inventory.rb +3 -22
  16. data/lib/principles/controllers/mapping.rb +9 -1
  17. data/lib/principles/controllers/member_acknowledgement.rb +137 -0
  18. data/lib/principles/controllers/member_addition.rb +65 -0
  19. data/lib/principles/controllers/member_entries.rb +6 -24
  20. data/lib/principles/controllers/member_problems_report.rb +33 -25
  21. data/lib/principles/controllers/members_to_assess.rb +1 -1
  22. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  23. data/lib/principles/controllers/repoint.rb +5 -2
  24. data/lib/principles/controllers/survey.rb +60 -0
  25. data/lib/principles/data/audit_files.rb +4 -0
  26. data/lib/principles/data/candidate_files_found.rb +48 -13
  27. data/lib/principles/data/command-steps.json +86 -25
  28. data/lib/principles/data/committed_tree.rb +84 -0
  29. data/lib/principles/data/first_parent_log.rb +48 -0
  30. data/lib/principles/data/first_parent_range.rb +122 -0
  31. data/lib/principles/data/git_command.rb +37 -0
  32. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  33. data/lib/principles/data/map_files.rb +35 -10
  34. data/lib/principles/data/principles_directory.rb +40 -0
  35. data/lib/principles/data/principles_subfolder.rb +39 -16
  36. data/lib/principles/data/project_files.rb +11 -3
  37. data/lib/principles/data/repository.rb +55 -29
  38. data/lib/principles/data/requested_candidate_files.rb +43 -0
  39. data/lib/principles/data/running_version.rb +3 -5
  40. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +6 -6
  41. data/lib/principles/data/schemas/acknowledgements-answer.schema.json +88 -0
  42. data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
  43. data/lib/principles/data/schemas/assessment-answer.schema.json +15 -1
  44. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  45. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  46. data/lib/principles/data/schemas/correction-answer.schema.json +12 -54
  47. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  48. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  49. data/lib/principles/data/verified_head.rb +162 -0
  50. data/lib/principles/invocation_options.rb +5 -4
  51. data/lib/principles/list_open_findings_options.rb +23 -0
  52. data/lib/principles/models/acknowledged_check.rb +94 -0
  53. data/lib/principles/models/acknowledgement.rb +40 -36
  54. data/lib/principles/models/acknowledgement_left_as_printed.rb +72 -0
  55. data/lib/principles/models/acknowledgements.rb +99 -0
  56. data/lib/principles/models/answered_time.rb +9 -0
  57. data/lib/principles/models/assessment_report.rb +13 -13
  58. data/lib/principles/models/audit.rb +17 -4
  59. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  60. data/lib/principles/models/audit_record.rb +9 -0
  61. data/lib/principles/models/audit_records.rb +34 -8
  62. data/lib/principles/models/candidate_files.rb +17 -6
  63. data/lib/principles/models/candidate_inventory.rb +51 -7
  64. data/lib/principles/models/captured_head.rb +72 -0
  65. data/lib/principles/models/check_since_last_audit.rb +4 -8
  66. data/lib/principles/models/correction_basis.rb +14 -5
  67. data/lib/principles/models/declared_map_changes.rb +25 -9
  68. data/lib/principles/models/declared_member_removals.rb +75 -0
  69. data/lib/principles/models/disposition.rb +4 -2
  70. data/lib/principles/models/fix_only_fields.rb +12 -0
  71. data/lib/principles/models/guidance_search_path.rb +26 -0
  72. data/lib/principles/models/guidance_search_paths.rb +57 -0
  73. data/lib/principles/models/line_span.rb +6 -0
  74. data/lib/principles/models/list_member_problems_check.rb +80 -0
  75. data/lib/principles/models/listed_members.rb +49 -0
  76. data/lib/principles/models/loaded_files.rb +1 -2
  77. data/lib/principles/models/loading_decision.rb +17 -8
  78. data/lib/principles/models/loading_scope.rb +61 -0
  79. data/lib/principles/models/loads_to_check.rb +0 -1
  80. data/lib/principles/models/locator.rb +6 -0
  81. data/lib/principles/models/mapped_principles.rb +39 -37
  82. data/lib/principles/models/member_assessments.rb +11 -2
  83. data/lib/principles/models/member_file.rb +20 -71
  84. data/lib/principles/models/member_history.rb +7 -5
  85. data/lib/principles/models/member_loading_scopes.rb +49 -0
  86. data/lib/principles/models/member_loads.rb +4 -0
  87. data/lib/principles/models/member_mapping_run.rb +30 -0
  88. data/lib/principles/models/member_moves.rb +4 -0
  89. data/lib/principles/models/member_problems.rb +57 -29
  90. data/lib/principles/models/member_region.rb +129 -0
  91. data/lib/principles/models/member_repair_moves.rb +9 -11
  92. data/lib/principles/models/member_sighting.rb +5 -8
  93. data/lib/principles/models/member_snapshots.rb +14 -1
  94. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  95. data/lib/principles/models/meta_principle.rb +14 -0
  96. data/lib/principles/models/missing_files.rb +2 -2
  97. data/lib/principles/models/other_templates_placeholders.rb +1 -1
  98. data/lib/principles/models/outline_budget.rb +29 -14
  99. data/lib/principles/models/principle.rb +14 -7
  100. data/lib/principles/models/principle_file_revision.rb +48 -0
  101. data/lib/principles/models/principle_history.rb +46 -19
  102. data/lib/principles/models/principle_lineage.rb +118 -0
  103. data/lib/principles/models/principle_map_revision.rb +39 -0
  104. data/lib/principles/models/principle_mapping_history.rb +132 -0
  105. data/lib/principles/models/principle_members.rb +14 -0
  106. data/lib/principles/models/principle_predecessor.rb +45 -0
  107. data/lib/principles/models/principle_publication.rb +177 -0
  108. data/lib/principles/models/principle_revision.rb +104 -0
  109. data/lib/principles/models/problem_report.rb +36 -9
  110. data/lib/principles/models/project.rb +47 -30
  111. data/lib/principles/models/project_history.rb +45 -25
  112. data/lib/principles/models/record_format.rb +6 -0
  113. data/lib/principles/models/reported_check.rb +16 -12
  114. data/lib/principles/models/request_id.rb +1 -1
  115. data/lib/principles/models/sent_answer.rb +35 -5
  116. data/lib/principles/models/survey_search_paths.rb +26 -0
  117. data/lib/principles/models/uncommitted_files.rb +50 -0
  118. data/lib/principles/models/unknown_principle.rb +29 -0
  119. data/lib/principles/positional_arguments.rb +38 -0
  120. data/lib/principles/session_start_options.rb +3 -3
  121. data/lib/principles/start_audit_options.rb +10 -2
  122. data/lib/principles/version.rb +2 -2
  123. data/lib/principles/views/acknowledgement_result.rb +54 -16
  124. data/lib/principles/views/added_member.rb +41 -0
  125. data/lib/principles/views/answered_request.rb +21 -0
  126. data/lib/principles/views/assessed_members.rb +26 -5
  127. data/lib/principles/views/assessment_request.rb +24 -4
  128. data/lib/principles/views/audit_result.rb +30 -27
  129. data/lib/principles/views/candidate_files_result.rb +56 -12
  130. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  131. data/lib/principles/views/check_result_template.rb +18 -17
  132. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  133. data/lib/principles/views/correction_request.rb +38 -10
  134. data/lib/principles/views/findings_result.rb +21 -0
  135. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  136. data/lib/principles/views/invocation.rb +19 -4
  137. data/lib/principles/views/json_with_entries_on_lines.rb +12 -4
  138. data/lib/principles/views/loads_to_check_result.rb +3 -2
  139. data/lib/principles/views/map_added_to.rb +56 -2
  140. data/lib/principles/views/map_result.rb +22 -42
  141. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  142. data/lib/principles/views/member_change_since_baseline.rb +2 -1
  143. data/lib/principles/views/member_repairs.rb +2 -1
  144. data/lib/principles/views/member_row.rb +61 -0
  145. data/lib/principles/views/members_a_commit_changed.rb +2 -1
  146. data/lib/principles/views/members_with_no_baseline.rb +8 -1
  147. data/lib/principles/views/new_loading_scope.rb +31 -0
  148. data/lib/principles/views/one_member_check_result_template.rb +37 -21
  149. data/lib/principles/views/open_findings_line.rb +2 -1
  150. data/lib/principles/views/principle_read_result.rb +4 -1
  151. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  152. data/lib/principles/views/problem_lines.rb +50 -45
  153. data/lib/principles/views/problem_result.rb +59 -25
  154. data/lib/principles/views/prompts/acknowledge-a-change/report-the-exit-status-its-own-listing-gives.md +3 -0
  155. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -3
  156. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-each-change-keeps-its-meaning.md +8 -0
  157. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -6
  158. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -43
  159. data/lib/principles/views/prompts/assess-every-member/decide-each-member-loading.md +2 -1
  160. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  161. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +5 -3
  162. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  163. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +12 -0
  164. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  165. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  166. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  167. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +4 -2
  168. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  169. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +2 -2
  170. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  171. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  172. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  173. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  174. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  175. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  176. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -2
  177. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +37 -4
  178. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +20 -19
  179. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +65 -61
  180. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  181. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  182. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  183. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +33 -7
  184. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  185. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +10 -10
  186. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  187. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  188. data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +1 -1
  189. data/lib/principles/views/prompts/start-a-session/every-loaded-line-costs-every-session.md +1 -0
  190. data/lib/principles/views/prompts/start-a-session/start-with-the-principles-skill.md +1 -0
  191. metadata +67 -4
  192. data/lib/principles/models/candidate_listing.rb +0 -41
@@ -21,7 +21,8 @@
21
21
  "base_commit",
22
22
  "map_version",
23
23
  "last_completed_revision",
24
- "findings"
24
+ "findings",
25
+ "assessment_report_sha256"
25
26
  ],
26
27
  "properties": {
27
28
  "last_completed_revision": {
@@ -101,59 +102,10 @@
101
102
  "items": { "type": "string" },
102
103
  "description": "The paths the assessment's recent decision cites as evidence, which the record does not keep, carried so the completed audit asks to commit those that differ from HEAD (#860). Copy it as the template gives it."
103
104
  },
104
- "entry_fields": {
105
- "type": "object",
106
- "description": "By member id, the fields the assessment reported for each member's record entry: its assessment (D49), its check's result (D30) and its accepted loading decision (#355), carried from the assessment so the completed record keeps them.",
107
- "additionalProperties": {
108
- "type": "object",
109
- "additionalProperties": false,
110
- "properties": {
111
- "check_result": {
112
- "type": "object",
113
- "additionalProperties": false,
114
- "required": [
115
- "command"
116
- ],
117
- "properties": {
118
- "command": {
119
- "type": "string"
120
- },
121
- "exit_status": {
122
- "type": "integer"
123
- },
124
- "not_run_reason": {
125
- "type": "string"
126
- },
127
- "review_basis": {
128
- "type": "string"
129
- },
130
- "review_basis_since": {
131
- "type": "string"
132
- }
133
- }
134
- },
135
- "loading_accepted": {
136
- "type": "object",
137
- "additionalProperties": false,
138
- "required": [
139
- "reason",
140
- "loads"
141
- ],
142
- "properties": {
143
- "reason": {
144
- "type": "string"
145
- },
146
- "loads": {
147
- "type": "object"
148
- }
149
- }
150
- },
151
- "assessment": {
152
- "type": "object",
153
- "description": "The member's assessment as the assessment gave it, with the grounds it was judged on, which the completed record keeps (D49)."
154
- }
155
- }
156
- }
105
+ "assessment_report_sha256": {
106
+ "type": "string",
107
+ "pattern": "\\A[0-9a-f]{64}\\z",
108
+ "description": "A digest of the assessment the open audit record keeps, which the correction reads back from that record, so it is refused once the record changed or was discarded (D87). Copy it as the template gives it."
157
109
  },
158
110
  "prior_findings": {
159
111
  "type": "object",
@@ -272,6 +224,12 @@
272
224
  "type": "string"
273
225
  }
274
226
  },
227
+ "removed_members": {
228
+ "type": "array",
229
+ "items": {
230
+ "type": "string"
231
+ }
232
+ },
275
233
  "reassessment": {
276
234
  "type": "string"
277
235
  },
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "guidance-search-paths.schema.json",
4
+ "title": "Recorded guidance search paths",
5
+ "description": "Additional root-relative guidance globs recorded after the principles table, in the project's one .principles/guidance-search-paths.json file.",
6
+ "type": "object",
7
+ "required": ["format", "globs"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "format": { "type": "integer", "enum": [1] },
11
+ "globs": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
12
+ }
13
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "member-map-history.schema.json",
4
+ "title": "Linked member map history",
5
+ "description": "The additional shape of a format-3 map's exact immediate predecessor, checked beside the common member-map schema. Earlier formats keep predecessor as unknown metadata.",
6
+ "type": "object",
7
+ "required": ["format", "predecessor"],
8
+ "properties": {
9
+ "format": { "const": 3 },
10
+ "predecessor": {
11
+ "type": "object",
12
+ "required": ["principle_id", "commit"],
13
+ "additionalProperties": false,
14
+ "properties": {
15
+ "principle_id": { "type": "string", "pattern": "\\A[a-z0-9]+(?:-[a-z0-9]+)*\\z" },
16
+ "commit": { "type": "string", "pattern": "\\A[0-9a-f]{40}([0-9a-f]{24})?\\z" }
17
+ }
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,162 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "git_command"
6
+ require_relative "first_parent_range"
7
+ require_relative "committed_tree"
8
+
9
+ module Principles
10
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
11
+ module Data
12
+ # A permission-specific captured Git head, distinct from best-effort history display. Absence needs positive
13
+ # unborn evidence or inspectable physical ancestry without repository markers; failed access never grants it.
14
+ class VerifiedHead
15
+ OVERRIDES = %w[GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR].freeze #: Array[String]
16
+ SHA = /\A\h{40}(?:\h{24})?\z/ #: Regexp
17
+
18
+ #: (String) -> void
19
+ def initialize(root)
20
+ @root = root
21
+ @git = GitCommand.new(root) #: GitCommand
22
+ @commit = nil #: String?
23
+ @read = false #: bool
24
+ end
25
+
26
+ #: () -> String?
27
+ def commit
28
+ return @commit if @read
29
+
30
+ @commit = capture&.freeze
31
+ @read = true
32
+ @commit
33
+ end
34
+
35
+ # A raw tree entry counts even when it is not readable JSON, a tree or a dangling link. Paths remain relative
36
+ # to the project, not the repository top; literal pathspecs come from GitCommand.
37
+ #: (String) -> bool
38
+ def entry?(path)
39
+ sha = commit or return false
40
+ entry_at?(sha, path)
41
+ end
42
+
43
+ #: (String, String) -> bool
44
+ def entry_at?(revision, path) = CommittedTree.new(@git, revision, unavailable).entry?(path)
45
+
46
+ #: (String, String) -> Hash[String, String]?
47
+ def raw_entry_at(revision, path) = CommittedTree.new(@git, revision, unavailable).raw_entry(path)
48
+
49
+ # This span proves only base to through; its upper's membership in captured HEAD needs a separate proof.
50
+ #: (String?, through: String) -> FirstParentRange
51
+ def first_parent_range(base, through:) = FirstParentRange.new(@git, base, through)
52
+
53
+ #: (String) -> String?
54
+ def first_parent_of(revision)
55
+ raise unavailable unless SHA.match?(revision)
56
+
57
+ output, status = @git.run_with_status(["cat-file", "commit", revision])
58
+ raise unavailable unless status&.zero?
59
+
60
+ parent_names(output, revision.length).first&.freeze
61
+ end
62
+
63
+ #: (String, Array[String]) -> Array[String]
64
+ def commits_touching_since(base, paths)
65
+ head = commit or raise unavailable
66
+ FirstParentRange.new(@git, base, head).touching(paths)
67
+ end
68
+
69
+ private
70
+
71
+ #: (String, Integer) -> Array[String]
72
+ def parent_names(output, name_length)
73
+ header, message = output.b.split("\n\n", 2)
74
+ rows = header.to_s.lines.map(&:chomp)
75
+ tree = rows.first.to_s
76
+ raise unavailable unless message && tree.start_with?("tree ")
77
+
78
+ parents = rows.grep(/\Aparent\b/).map { it.delete_prefix("parent ") }
79
+ confirm_object_names([tree.delete_prefix("tree "), *parents], name_length)
80
+
81
+ parents
82
+ end
83
+
84
+ #: (Array[String], Integer) -> void
85
+ def confirm_object_names(names, name_length)
86
+ raise unavailable unless names.all? { SHA.match?(it) && it.length == name_length }
87
+ end
88
+
89
+ #: () -> String?
90
+ def capture
91
+ output, status = @git.run_with_status(["rev-parse", "--is-inside-work-tree"])
92
+ return inside_commit if status&.zero? && output.strip == "true"
93
+ return nil if status == 128 && physically_outside?
94
+
95
+ raise unavailable
96
+ end
97
+
98
+ #: () -> String?
99
+ def inside_commit
100
+ output, status = @git.run_with_status(["rev-parse", "--verify", "--quiet", "HEAD^{commit}"])
101
+ return output.strip if status&.zero? && SHA.match?(output.strip)
102
+
103
+ raise unavailable unless status == 1
104
+
105
+ unborn_commit
106
+ end
107
+
108
+ # Only a symbolic branch whose ref is positively absent certifies an unborn work tree.
109
+ #: () -> nil
110
+ def unborn_commit
111
+ branch, symbolic = @git.run_with_status(["symbolic-ref", "--quiet", "HEAD"])
112
+ raise unavailable unless symbolic&.zero? && branch.start_with?("refs/heads/")
113
+
114
+ _, exists = @git.run_with_status(["show-ref", "--exists", branch.strip])
115
+ raise unavailable unless exists == 2
116
+
117
+ nil
118
+ end
119
+
120
+ # Git performs positive discovery. This only proves a failed discovery has no physical repository to hide;
121
+ # ambiguous metadata, explicit discovery overrides and filesystem errors are not evidence of absence.
122
+ #: () -> bool
123
+ def physically_outside?
124
+ return false if OVERRIDES.any? { |name| ENV[name] }
125
+
126
+ directory = File.realpath(@root)
127
+ loop do
128
+ return false if repository_marker?(directory)
129
+
130
+ parent = File.dirname(directory)
131
+ return true if parent == directory
132
+
133
+ directory = parent
134
+ end
135
+ rescue SystemCallError
136
+ false
137
+ end
138
+
139
+ #: (String) -> bool
140
+ def repository_marker?(directory)
141
+ return true if entry_exists?(File.join(directory, ".git"))
142
+
143
+ %w[HEAD objects refs].count { |name| entry_exists?(File.join(directory, name)) } >= 2
144
+ end
145
+
146
+ #: (String) -> bool
147
+ def entry_exists?(path)
148
+ File.lstat(path)
149
+ true
150
+ rescue Errno::ENOENT
151
+ false
152
+ end
153
+
154
+ #: () -> Error
155
+ def unavailable
156
+ Error.new("git_history_unavailable", "Git history could not be verified safely",
157
+ "Restore access to a healthy Git work tree and retry. Before the first commit, make an initial " \
158
+ "commit or use Git supporting show-ref --exists. No map was created or removed.")
159
+ end
160
+ end
161
+ end
162
+ end
@@ -9,11 +9,12 @@ module Principles
9
9
  class InvocationOptions
10
10
  # The options that take a value; --help, -h and --version take none.
11
11
  VALUE_OPTIONS = %w[project file description path section starting-at ending-at query role
12
- check member session-start commits-after hook-event as instruction].freeze #: Array[String]
12
+ check session-start commits-after hook-event as instruction].freeze #: Array[String]
13
13
  # The options that take no value, as list-member-problems --short (#291).
14
- FLAG_OPTIONS = %w[short when-invoked always write-ups].freeze #: Array[String]
15
- # The options that may be given more than once, each value kept in order, as change-activation --when-files.
16
- LIST_OPTIONS = %w[when-files].freeze #: Array[String]
14
+ FLAG_OPTIONS = %w[short lines when-invoked always write-ups confirm].freeze #: Array[String]
15
+ # The options that may be given more than once, each value kept in order, as change-activation --when-files and
16
+ # start-audit --member (#1169).
17
+ LIST_OPTIONS = %w[when-files also member].freeze #: Array[String]
17
18
  # The words that name an option taking the next word as its value.
18
19
  VALUE_WORDS = (VALUE_OPTIONS + LIST_OPTIONS).map { |name| "--#{name}" }.freeze #: Array[String]
19
20
  # Every word the parser reads as an option, which an option taking a value refuses as its value (#750).
@@ -0,0 +1,23 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The options choosing which form list-open-findings prints, --lines or --short (#1156), and what is wrong with them
8
+ # as given, which CommandLine refuses as a usage error.
9
+ class ListOpenFindingsOptions
10
+ #: (InvocationOptions) -> void
11
+ def initialize(options)
12
+ @lines = !options.value("lines").nil? #: bool
13
+ @short = !options.value("short").nil? #: bool
14
+ freeze
15
+ end
16
+
17
+ # What is wrong with the options as given, or nil when they fit.
18
+ #: () -> String?
19
+ def fault
20
+ "--lines and --short each print a different form of the list; give one" if @lines && @short
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,94 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "acknowledgement_refusal"
6
+ require_relative "answer_place"
7
+ require_relative "audit_record"
8
+ require_relative "listed_members"
9
+ require_relative "../prose_list"
10
+ require_relative "member"
11
+ require_relative "reported_check"
12
+
13
+ module Principles
14
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
15
+ module Models
16
+ # The run of its member's check that a one-member audit's answer reports (D30, D33): checked against the check
17
+ # the record ran, carrying the line its last review rested on (D63), and accepted only once it passed, since a
18
+ # check that failed or could not run is a full audit's to judge (#1071).
19
+ class AcknowledgedCheck
20
+ # Where a one-member audit's answer gives its check_result, which a refusal of a field in it points into.
21
+ CHECK_RESULT = AnswerPlace.new("/check_result", "The acknowledgement") #: AnswerPlace
22
+
23
+ # record is the completed record the member is judged against. listed is what the member's check lists now,
24
+ # when it is this tool's own list-member-problems, which exits 3 while it lists the member (#1276).
25
+ #: (member: Member, principle_id: String, record: AuditRecord, ?listed: ListedMembers?) -> void
26
+ def initialize(member:, principle_id:, record:, listed: nil)
27
+ @member = member
28
+ @principle_id = principle_id
29
+ @record = record
30
+ @listed = listed
31
+ freeze
32
+ end
33
+
34
+ # The result the answer reports for the member's check, once it passed; nil for a member without a check,
35
+ # whose answer may report none.
36
+ #: (untyped) -> Hash[String, untyped]?
37
+ def result(answer)
38
+ check = @member.check
39
+ refuse("it has no check, so its answer reports no check_result") if !check && answer.key?("check_result")
40
+ return unless check
41
+
42
+ sent = answer["check_result"]
43
+ passed(ReportedCheck.new(AnswerPlace.new("", "The acknowledgement"), check,
44
+ ran: @record.check_run_for(@member.key), kept: @record.check_review_for(@member.key))
45
+ .result(reported(sent, check)), sent)
46
+ end
47
+
48
+ private
49
+
50
+ # result, once its check exited 0, or 3 for this tool's own list-member-problems while it lists only members
51
+ # this answer acknowledges, which it lists no more once the record is committed (#1276). It always gives an
52
+ # exit status, since the answer's schema refuses not_run_reason (#1115). sent is the check_result as given.
53
+ #: (Hash[String, untyped], Hash[String, untyped]) -> Hash[String, untyped]
54
+ def passed(result, sent)
55
+ status = result.fetch("exit_status")
56
+ command = result.fetch("command")
57
+ return result if status.zero? || (status == 3 && lists_only_the_acknowledged?(command, sent))
58
+
59
+ refuse("its check `#{command}` exited #{status}, so a full audit judges it")
60
+ end
61
+
62
+ # Whether the member's check is this tool's own list-member-problems and lists only members this answer
63
+ # acknowledges, refusing a listed_members that is not what it lists now, and a listing of another member,
64
+ # which it would still list once the record is committed (#1276).
65
+ #: (String, Hash[String, untyped]) -> bool
66
+ def lists_only_the_acknowledged?(command, sent)
67
+ listed = @listed or return false
68
+ misreported(command) unless listed.reported?(sent["listed_members"])
69
+ others = listed.unacknowledged
70
+ return true if others.empty?
71
+
72
+ refuse("its check `#{command}` exited 3 and lists #{ProseList.new(others)}, which this " \
73
+ "answer does not acknowledge, so a full audit judges it")
74
+ end
75
+
76
+ # Refuses a listed_members that is not what the member's own list-member-problems check lists now (#1276).
77
+ #: (String) -> bot
78
+ def misreported(command)
79
+ raise CHECK_RESULT.child("listed_members").refusal(
80
+ Error.new("invalid_answer", "check_result.listed_members is not what `#{command}` lists now",
81
+ "Run `#{command}` and give, under check_result.listed_members, the member id in the second " \
82
+ "column of each line it prints.")
83
+ )
84
+ end
85
+
86
+ # The check_result the answer reports, its command read as the request printed it when left out (#1166).
87
+ #: (untyped, String) -> untyped
88
+ def reported(sent, check) = sent.is_a?(Hash) ? { "command" => check, **sent.except("listed_members") } : sent
89
+
90
+ #: (String) -> bot
91
+ def refuse(why) = AcknowledgementRefusal.new(@member, @principle_id).refuse(why)
92
+ end
93
+ end
94
+ end
@@ -2,6 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../error"
5
+ require_relative "acknowledged_check"
6
+ require_relative "acknowledgement_left_as_printed"
5
7
  require_relative "acknowledgement_refusal"
6
8
  require_relative "request_id"
7
9
  require_relative "audit_record"
@@ -10,7 +12,6 @@ require_relative "member_lines"
10
12
  require_relative "placement"
11
13
  require_relative "quoted_change"
12
14
  require_relative "reported_check"
13
- require_relative "answer_place"
14
15
  require_relative "template_placeholders"
15
16
 
16
17
  module Principles
@@ -22,15 +23,22 @@ module Principles
22
23
  class Acknowledgement
23
24
  PHASE = "acknowledgement"
24
25
  # The text the answer's template prints in each field the agent judges, which an answer may not send back, so
25
- # a template returned as printed acknowledges nothing (#773). Its quotes print first_changed_lines instead,
26
- # which the answer may send back as printed (#1111). After a pure insertion, meaning_kept's says that an
26
+ # a template returned as printed acknowledges nothing (#773). It prints no quotes, which an answer leaving them
27
+ # out reads as first_changed_lines (#1111, #1166, #1170). After a pure insertion, meaning_kept's says that an
27
28
  # inserted line usually adds a rule, for an agent that reads the template alone (#1142).
28
29
  PLACEHOLDERS = TemplatePlaceholders.new(
29
30
  { "meaning_kept" => "true only if the member still says the same thing",
30
31
  "reason" => "Why, in one line of your own" },
31
- also_printed: { "meaning_kept" => "true only if the member still says the same thing; old_line \"\" means a " \
32
- "line was inserted, which usually adds a rule" }
32
+ also_printed: { "meaning_kept" => "true only if the member still says the same thing; this change inserted " \
33
+ "a line, which usually adds a rule" }
33
34
  ) #: TemplatePlaceholders
35
+ # The text a checked member's template prints where its check's exit status goes, short since the request's
36
+ # context says how to run the check (#1170).
37
+ EXIT_STATUS_PLACEHOLDER = ReportedCheck::EXIT_STATUS_PLACEHOLDER #: String
38
+ # The fields an answer may not send back as the template printed them, refused before its shape (#773, #1170).
39
+ LEFT_AS_PRINTED = AcknowledgementLeftAsPrinted.new(
40
+ PLACEHOLDERS, exit_status: EXIT_STATUS_PLACEHOLDER
41
+ ) #: AcknowledgementLeftAsPrinted
34
42
 
35
43
  # The placeholders the template prints beside quotes, its first_changed_lines.
36
44
  #: (Hash[String, String]) -> Hash[String, untyped]
@@ -94,6 +102,14 @@ module Principles
94
102
  record.members.acknowledgements_for(@member.key).last&.fetch("commit") || record.base_commit.to_s
95
103
  end
96
104
 
105
+ # Keep the record's named reference and stable member key together during placement lookup.
106
+ #: (Project) -> Enumerator::Lazy[Placement]
107
+ def placements_in(project)
108
+ commit = last_judged_commit
109
+ fields = project.principles.find(@principle_id).member(@member.id)
110
+ project.principle_history(@principle_id).placements_since(commit, @member.key, fields)
111
+ end
112
+
97
113
  # The request's id: the member, its hash at the baseline and now, and the commit it is judged at.
98
114
  #: () -> RequestId
99
115
  def request_id
@@ -112,30 +128,26 @@ module Principles
112
128
  # The record with this member's baseline moved to its text now, once the answer is checked against the
113
129
  # member's lines at the baseline commit and now. The change keeps the check run the answer reported, which the
114
130
  # member's check_result cannot show was this run when the last audit's passed with the same command (#1112).
115
- #: (untyped, MemberLines, at: String) -> AuditRecord
116
- def accepted(answer, lines, at:)
131
+ # into is the record the change is made to: the one this member is judged against, unless another member's
132
+ # acknowledgement in the same answer has already changed it. listed is what the member's check lists now, when
133
+ # it is this tool's own list-member-problems (#1276).
134
+ #: (untyped, MemberLines, at: String, ?into: AuditRecord?, ?listed: ListedMembers?) -> AuditRecord
135
+ def accepted(answer, lines, at:, into: nil, listed: nil)
117
136
  checked(answer, lines)
118
- result = check_result(answer)
137
+ result = check_result(answer, listed)
119
138
  run = result ? { "check_result" => result.slice("command", "exit_status") } : {}
120
- acknowledgeable.acknowledged(@member.key, { "from_sha256" => acknowledgeable.members.hash_for(@member.key),
121
- "to_sha256" => @now_sha256, "commit" => @base,
122
- "reason" => answer.fetch("reason"), "acknowledged_at" => at,
123
- **open_findings, **run }, check_result: result)
139
+ from = acknowledgeable.members.hash_for(@member.key)
140
+ (into || acknowledgeable).acknowledged(@member.key, { "from_sha256" => from, "to_sha256" => @now_sha256,
141
+ "commit" => @base, "reason" => answer.fetch("reason"),
142
+ "acknowledged_at" => at, **open_findings, **run },
143
+ check_result: result)
124
144
  end
125
145
 
126
- # The result the answer reports for the member's check, checked against the check the record ran and carrying
127
- # the line its last review rested on (D30, D63), once it passed: a check that failed or could not run is a full
128
- # audit's to judge (#1071). nil for a member without a check, whose answer may report none.
129
- #: (untyped) -> Hash[String, untyped]?
130
- def check_result(answer)
131
- check = @member.check
132
- refuse("it has no check, so its answer reports no check_result") if !check && answer.key?("check_result")
133
- return unless check
134
-
135
- record = acknowledgeable
136
- passed(ReportedCheck.new(AnswerPlace.new("", "The acknowledgement"), check,
137
- ran: record.check_run_for(@member.key), kept: record.check_review_for(@member.key))
138
- .result(answer["check_result"]))
146
+ # The result the answer reports for the member's check, once it passed; nil for a member without a check.
147
+ #: (untyped, ?ListedMembers?) -> Hash[String, untyped]?
148
+ def check_result(answer, listed = nil)
149
+ AcknowledgedCheck.new(member: @member, principle_id: @principle_id, record: acknowledgeable, listed:)
150
+ .result(answer)
139
151
  end
140
152
 
141
153
  # The first line on each side of the change that the other lacks, which the request hints the quotes from.
@@ -144,16 +156,6 @@ module Principles
144
156
 
145
157
  private
146
158
 
147
- # result, once its check exited 0. It always gives an exit status, since the answer's schema refuses
148
- # not_run_reason (#1115).
149
- #: (Hash[String, untyped]) -> Hash[String, untyped]
150
- def passed(result)
151
- status = result.fetch("exit_status")
152
- return result if status.zero?
153
-
154
- refuse("its check `#{result.fetch("command")}` exited #{status}, so a full audit judges it")
155
- end
156
-
157
159
  # The change the answer quotes, between the member's lines at the baseline and now.
158
160
  #: (MemberLines) -> QuotedChange
159
161
  def quoted_change(lines) = QuotedChange.new(lines, member_id: @member.id)
@@ -179,7 +181,9 @@ module Principles
179
181
  refuse("the answer says the change does not keep #{@member.id}'s meaning") unless answer["meaning_kept"] == true
180
182
  reason = answer.fetch("reason").to_s
181
183
  refuse("the reason must be one line") if reason.include?("\n")
182
- quoted_change(lines).check(old_line: answer.fetch("old_line"), new_line: answer.fetch("new_line"))
184
+ change = quoted_change(lines)
185
+ quotes = change.first_changed_lines.merge(answer.slice("old_line", "new_line"))
186
+ change.check(old_line: quotes.fetch("old_line"), new_line: quotes.fetch("new_line"))
183
187
  end
184
188
 
185
189
  #: (String) -> bot
@@ -0,0 +1,72 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "acknowledgements"
5
+ require_relative "left_as_printed"
6
+ require_relative "refusal_before_shape"
7
+ require_relative "template_placeholders"
8
+
9
+ module Principles
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
+ module Models
12
+ # The fields a one-member audit's answer leaves as its template printed them, refused in one refusal before the
13
+ # answer's shape: its judgement's, meaning_kept and reason (#773), and a checked member's exit_status, which was
14
+ # otherwise refused as text with a repair offering the not_run_reason this template refuses (#1170). It holds the
15
+ # placeholders the template prints in each; Acknowledgement::LEFT_AS_PRINTED is the one a one-member audit uses.
16
+ class AcknowledgementLeftAsPrinted
17
+ include RefusalBeforeShape
18
+
19
+ # The field, named as a refusal names it, where a checked member's answer reports its exit status.
20
+ EXIT_STATUS = "check_result.exit_status" #: String
21
+
22
+ # judged holds the placeholders of the judgement's fields, exit_status the one printed where the status goes;
23
+ # with each_member, they are read in each entry of an answer to several members' members, keyed by member id
24
+ # (#1169), not in the answer itself.
25
+ #: (TemplatePlaceholders, exit_status: String, ?each_member: bool) -> void
26
+ def initialize(judged, exit_status:, each_member: false)
27
+ @judged = judged
28
+ @exit_status = exit_status
29
+ @each_member = each_member
30
+ freeze
31
+ end
32
+
33
+ # The same fields, read in each entry of an answer to several members (#1169).
34
+ #: () -> AcknowledgementLeftAsPrinted
35
+ def in_each_member = AcknowledgementLeftAsPrinted.new(@judged, exit_status: @exit_status, each_member: true)
36
+
37
+ # @override
38
+ #: (untyped, String, Array[Hash[String, String]]) -> void
39
+ def refuse_in(answer, _source, shape_problems)
40
+ return unless answer.is_a?(Hash)
41
+
42
+ LeftAsPrinted.new(pointers_in(answer)).refuse(besides: shape_problems)
43
+ end
44
+
45
+ private
46
+
47
+ # Each field left as printed, by name, beside its pointer: in the answer, or in each entry of its members.
48
+ #: (Hash[String, untyped]) -> Hash[String, String]
49
+ def pointers_in(answer)
50
+ return left_in(answer).to_h { [it, "/#{it.tr(".", "/")}"] } unless @each_member
51
+
52
+ members = answer["members"]
53
+ return {} unless members.is_a?(Hash)
54
+
55
+ members.select { |_id, entry| entry.is_a?(Hash) }.flat_map do |id, entry|
56
+ left_in(entry).map { ["#{id} #{it}", "#{Acknowledgements.entry_pointer(id)}/#{it.tr(".", "/")}"] }
57
+ end.to_h
58
+ end
59
+
60
+ # Each field answer leaves as printed, by name.
61
+ #: (Hash[String, untyped]) -> Array[String]
62
+ def left_in(answer)
63
+ judged = @judged.to_h.keys.select { @judged.left?(it, answer[it]) }
64
+ status_left?(answer["check_result"]) ? [*judged, EXIT_STATUS] : judged
65
+ end
66
+
67
+ # Whether check_result's exit_status is the placeholder the template prints there.
68
+ #: (untyped) -> bool
69
+ def status_left?(check_result) = check_result.is_a?(Hash) && check_result["exit_status"] == @exit_status
70
+ end
71
+ end
72
+ end