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
@@ -12,6 +12,16 @@ module Principles
12
12
  # broken, so a gate can stop on its exit status alone, and otherwise every changed member and a count of
13
13
  # each state.
14
14
  class ProblemReport
15
+ # What list-member-problems reports for map id, or every map, listing a map it cannot read among them, with the
16
+ # project's history, which lets each missing file carry the rename git detects for it.
17
+ #: (Project, String?) -> ProblemReport
18
+ def self.for(project, id)
19
+ maps = if id then [MemberProblems.for(project, id)]
20
+ else project.principles.ids.map { MemberProblems.for(project, it, listing_all: true) }
21
+ end
22
+ new(maps, history: project.history)
23
+ end
24
+
15
25
  # history, when given, lets each missing file carry the rename git detects for it (#276).
16
26
  #: (Array[MemberProblems], ?history: ProjectHistory?) -> void
17
27
  def initialize(maps, history: nil)
@@ -21,15 +31,17 @@ module Principles
21
31
  end
22
32
 
23
33
  # The changed members and the count of each state, refused when any member is broken. Given a block, each
24
- # changed member gains the history the block makes of its map id, member, baseline hash and hash now.
25
- #: () ?{ (String, Member, String, String) -> Hash[String, untyped] } -> Hash[String, untyped]
34
+ # changed member gains the history the block makes of its map id, member, baseline hash, hash now and
35
+ # the selected automatic history when its mapping supplies the baseline.
36
+ #: () ?{ (String, Member, String, String, PrincipleMappingHistory?) -> Hash[String, untyped] }
37
+ #| -> Hash[String, untyped]
26
38
  def checked(&)
27
39
  broken = @maps.flat_map(&:broken)
28
40
  refuse(broken) unless broken.empty?
29
41
 
30
42
  { "members" => changed(&),
31
43
  "counts" => @maps.flat_map(&:entries).map { |each| each.fetch("state") }.tally.sort.to_h,
32
- "compared_with" => compared_with, **no_baseline_because, **awaiting_first_audit_field }
44
+ "compared_with" => compared_with, **no_baseline_because, **awaiting_first_audit_field, **mapping_facts }
33
45
  end
34
46
 
35
47
  # The principles that await their first full audit, in map order, which list-member-problems names in one
@@ -42,12 +54,17 @@ module Principles
42
54
  #: () -> bool
43
55
  def assessed_change? = @maps.any?(&:assessed_change?)
44
56
 
45
- # Whether any map's member no audit assessed was edited since the commit that mapped it (D44).
46
- #: () -> bool
47
- def unassessed_change? = @maps.any?(&:unassessed_change?)
57
+ # For each map with a changed member an audit or acknowledgement assessed, how many, which --session-start
58
+ # counts instead of listing each (#1261).
59
+ #: () -> Hash[String, Integer]
60
+ def assessed_changes = @maps.to_h { [it.principle_id, it.assessed_changes] }.reject { |_, count| count.zero? }
61
+
62
+ # For each map with members no audit has assessed, how many, which --short counts on stdout (#1254).
63
+ #: () -> Hash[String, Integer]
64
+ def never_assessed = @maps.to_h { [it.principle_id, it.never_assessed] }.reject { |_, count| count.zero? }
48
65
 
49
66
  # For each map with a changed member a one-member audit may judge, the ids of those members, which
50
- # list-member-problems offers that audit for, one command each (#626, D56).
67
+ # list-member-problems offers that audit for, one command per principle (#626, D56, #1263).
51
68
  #: () -> Hash[String, Array[String]]
52
69
  def acknowledgeable
53
70
  @maps.to_h { |map| [map.principle_id, map.acknowledgeable_member_ids] }.reject { |_, ids| ids.empty? }
@@ -72,12 +89,15 @@ module Principles
72
89
  @maps.to_h { |map| [map.principle_id, map.no_baseline_paths] }.reject { |_, paths| paths.empty? }
73
90
  end
74
91
 
75
- #: () ?{ (String, Member, String, String) -> Hash[String, untyped] } -> Array[Hash[String, untyped]]
92
+ #: () ?{ (String, Member, String, String, PrincipleMappingHistory?) -> Hash[String, untyped] }
93
+ #| -> Array[Hash[String, untyped]]
76
94
  def changed(&history)
77
95
  @maps.flat_map do |map|
78
96
  next map.changed unless history
79
97
 
80
- map.changed { |member, baseline, now| history.call(map.principle_id, member, baseline, now) }
98
+ map.changed do |member, baseline, now, mapping|
99
+ history.call(map.principle_id, member, baseline, now, mapping)
100
+ end
81
101
  end
82
102
  end
83
103
 
@@ -101,6 +121,13 @@ module Principles
101
121
  awaiting.empty? ? {} : { "awaiting_first_audit" => awaiting }
102
122
  end
103
123
 
124
+ # Completion and empty-map facts, distinct from whether members have a baseline ready for a first audit.
125
+ #: () -> Hash[String, Array[String]]
126
+ def mapping_facts
127
+ { "no_completed_audit" => @maps.select(&:no_completed_audit?).map(&:principle_id),
128
+ "empty_maps" => @maps.select(&:empty_map?).map(&:principle_id) }.reject { |_key, ids| ids.empty? }
129
+ end
130
+
104
131
  #: (Array[Hash[String, untyped]]) -> bot
105
132
  def refuse(broken)
106
133
  named = broken.map { |each| [each["principle"], each["id"]].compact.join(" ") }
@@ -3,7 +3,6 @@
3
3
 
4
4
  require_relative "../data/project_files"
5
5
  require_relative "../data/project_root"
6
- require_relative "../data/schema_check"
7
6
  require_relative "../data/map_files"
8
7
  require_relative "../data/audit_files"
9
8
  require_relative "../data/principles_subfolder"
@@ -23,15 +22,18 @@ require_relative "missing_files"
23
22
  require_relative "locate_refusal"
24
23
  require_relative "audit_records"
25
24
  require_relative "project_history"
25
+ require_relative "principle_history"
26
26
  require_relative "principles_folder_move"
27
27
  require_relative "sent_answer"
28
+ require_relative "guidance_search_paths"
29
+ require_relative "survey_search_paths"
28
30
 
29
31
  module Principles
30
32
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
31
33
  module Models
32
34
  # The user's project as this tool reads it: its instruction files, each member's text, the answers an
33
35
  # agent hands in, and the maps, audit records and git history kept beside them. Controllers reach the
34
- # project only through this model. It is handed its four data adapters, so a spec can hand it stand-ins
36
+ # project only through this model. It is handed its five data adapters, so a spec can hand it stand-ins
35
37
  # that meet the same contracts (#337).
36
38
  class Project
37
39
  # An implicit invocation reuses its nearest established project; an explicit root uses .at directly.
@@ -44,16 +46,20 @@ module Principles
44
46
  files = Data::ProjectFiles.new(root)
45
47
  new(files: files, maps: Data::MapFiles.new(Data::PrinciplesSubfolder.new(files.root, "maps")),
46
48
  audits: Data::AuditFiles.new(Data::PrinciplesSubfolder.new(files.root, "audits")),
47
- repository: Data::Repository.new(files.root))
49
+ repository: Data::Repository.new(files.root),
50
+ guidance_search_paths: Data::GuidanceSearchPathsFile.new(Data::PrinciplesDirectory.new(files.root)))
48
51
  end
49
52
 
50
53
  #: (files: Data::ProjectFiles, maps: Data::MapFiles, audits: Data::AuditFiles,
51
- #| repository: Data::Repository) -> void
52
- def initialize(files:, maps:, audits:, repository:)
54
+ #| repository: Data::Repository, guidance_search_paths: Data::GuidanceSearchPathsFile) -> void
55
+ def initialize(files:, maps:, audits:, repository:, guidance_search_paths:)
53
56
  @files = files
54
57
  @maps = maps
55
58
  @audits = audits
56
59
  @repository = repository
60
+ @guidance_search_paths = guidance_search_paths
61
+ @history = nil #: ProjectHistory?
62
+ @principle_histories = {} #: Hash[[String, PrincipleMappingHistory?], PrincipleHistory]
57
63
  end
58
64
 
59
65
  # The project's root, resolved.
@@ -65,7 +71,7 @@ module Principles
65
71
  #: () -> MappedPrinciples
66
72
  def principles
67
73
  refuse_unmoved_folder
68
- MappedPrinciples.new(@maps)
74
+ MappedPrinciples.new(@maps, history)
69
75
  end
70
76
 
71
77
  #: () -> AuditRecords
@@ -74,9 +80,24 @@ module Principles
74
80
  AuditRecords.new(@audits, history)
75
81
  end
76
82
 
83
+ #: () -> GuidanceSearchPaths
84
+ def guidance_search_paths
85
+ refuse_unmoved_folder
86
+ GuidanceSearchPaths.read(@guidance_search_paths)
87
+ end
88
+
89
+ # The project's history, one for the whole command, so every read names the HEAD it first read (#1161).
77
90
  #: () -> ProjectHistory
78
91
  def history
79
- ProjectHistory.new(@repository, @files)
92
+ @history ||= ProjectHistory.new(@repository, @files)
93
+ end
94
+
95
+ # Each principle's history view belongs to this command, sharing its captured project history.
96
+ #: (String, ?mapping: PrincipleMappingHistory?) -> PrincipleHistory
97
+ def principle_history(id, mapping: nil)
98
+ key = [id.dup.freeze, mapping].freeze #: [String, PrincipleMappingHistory?]
99
+ @principle_histories[key] ||= PrincipleHistory.new(id: key.first, history: history,
100
+ principles: principles, mapping: mapping)
80
101
  end
81
102
 
82
103
  # Whether two paths name one file, as their symbolic links lead them, so an edit through either is an edit
@@ -90,6 +111,10 @@ module Principles
90
111
  member_file(locator.path).locate(locator)
91
112
  end
92
113
 
114
+ # Check the location an add or move is about to persist, with the authoring-only ending constraint.
115
+ #: (Locator) -> Hash[String, untyped]
116
+ def locate_for_authoring(locator) = member_file(locator.path).locate_for_authoring(locator)
117
+
93
118
  # The text locator finds now, as one value: its path, its lines and the hash of what it says (#909).
94
119
  #: (Locator) -> LocatedText
95
120
  def located_text(locator) = LocatedText.of(locate(locator))
@@ -121,16 +146,7 @@ module Principles
121
146
  # Each of map's members by id, where it is in its file now and the hash of what it says there. It is
122
147
  # refused once, listing every member that cannot be found or read, so the agent repairs them together.
123
148
  #: (Principle) -> MemberSnapshots
124
- def snapshots(map)
125
- broken = [] #: Array[Hash[String, untyped]]
126
- found = map.members.to_h do |member|
127
- [member.id, locate(member.locator)]
128
- rescue Error => e
129
- broken << { "id" => member.id }.merge(e.payload.except("status"))
130
- [member.id, {}]
131
- end
132
- broken.empty? ? MemberSnapshots.new(found) : refuse_broken(map.id, broken)
133
- end
149
+ def snapshots(map) = MemberSnapshots.read(self, map)
134
150
 
135
151
  # The superseded, git-ignored file where an older version kept audit runs; this version never reads it.
136
152
  OLDER_STATE = ".memeplex/state.json" #: String
@@ -191,22 +207,23 @@ module Principles
191
207
  #: () -> EntryFiles
192
208
  def entry_files = EntryFiles.read(@files, history)
193
209
 
194
- # An answer to a phase's request from file, where - means it was read from stdin, its head checked against
195
- # the phase's answer schema (D29) and the rest left to check once its request is known (#1052).
196
- #: (String, stdin: String?, phase: String) -> SentAnswer
197
- def answer(file, stdin:, phase:)
198
- parsed = if file == "-" then @files.parse_json(stdin.to_s, "-", named: SentAnswer::NAMED)
199
- else @files.read_json(file, named: SentAnswer::FILE_NAMED)
200
- end
201
- SentAnswer.new(parsed, file, Data::SchemaCheck.new("#{phase}-answer"))
202
- end
210
+ # An answer to the request given, or to the one it names when none is (#995), from file, where - means it was
211
+ # read from stdin, its head checked against that request's phase's answer schema (D29) and the rest left to
212
+ # check once its request is known (#1052).
213
+ #: (String, stdin: String?, given: String?) -> SentAnswer
214
+ def answer(file, stdin:, given:) = SentAnswer.read(@files, file, stdin:, given:)
203
215
 
204
- # What list-candidate-files found: the candidate files as it lists them, and which git does not track.
205
- #: () -> CandidateInventory
206
- def candidate_files
207
- CandidateInventory.found(@files.inventory, history) { |path| @files.read_text(path) }
216
+ # What list-candidate-files found, as CandidateInventory reads it from the project, after a commit when given.
217
+ #: (?after: String?, ?also: Array[String]) -> CandidateInventory
218
+ def candidate_files(after: nil, also: [])
219
+ mapped = after ? principles.readable_paths : []
220
+ search_paths = SurveySearchPaths.new(recorded: guidance_search_paths.globs, also:)
221
+ CandidateInventory.read(@files, history, search_paths:, after:, mapped:)
208
222
  end
209
223
 
224
+ #: (Array[String]) -> CandidateInventory
225
+ def candidate_outlines(paths) = CandidateInventory.requested(@files, history, paths:)
226
+
210
227
  private
211
228
 
212
229
  # Refuses while the maps or records are still in the folder's earlier name (#536).
@@ -9,6 +9,8 @@ require_relative "principle_members"
9
9
  require_relative "member"
10
10
  require_relative "member_file"
11
11
  require_relative "commits_brought_in"
12
+ require_relative "uncommitted_files"
13
+ require_relative "captured_head"
12
14
 
13
15
  module Principles
14
16
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -28,6 +30,7 @@ module Principles
28
30
  def initialize(repository, files)
29
31
  @repository = repository
30
32
  @files = files
33
+ @head = CapturedHead.new(repository) #: CapturedHead
31
34
  end
32
35
 
33
36
  # Which of paths, and of the links and files they lead through, git does not track, which an audit refuses as
@@ -44,6 +47,25 @@ module Principles
44
47
  #: () -> bool
45
48
  def inside_git? = @repository.inside?
46
49
 
50
+ # The full sha of the commit revision names, which a survey of the commits after it starts from. Refuses outside
51
+ # git, where there are no commits, and a revision git resolves to no commit (#1171).
52
+ #: (String) -> String
53
+ def commit_named(revision)
54
+ unless @repository.inside?
55
+ raise Error.new("range_needs_git", "--commits-after needs git, to read the commits after #{revision}",
56
+ "To survey every candidate instead, run it without --commits-after.")
57
+ end
58
+
59
+ @repository.commit_of(revision) or
60
+ raise Error.new("unknown_revision", "git resolves #{revision} to no commit",
61
+ "Name a commit git knows, such as a sha from git log, a branch or HEAD~3.")
62
+ .including("revision" => revision)
63
+ end
64
+
65
+ # Each file the commits after commit, a full sha, changed up to HEAD that the project still holds (#1171).
66
+ #: (String) -> Array[String]
67
+ def changed_after(commit) = @repository.changed_since(commit).select { |path| @files.file?(path) }
68
+
47
69
  # The project's files, other than paths, that differ from HEAD or are untracked, ignored ones aside; nil
48
70
  # outside git or when there are none. A check and an answer's evidence read them as they are now (#409).
49
71
  #: (Array[String]) -> Array[String]?
@@ -58,17 +80,7 @@ module Principles
58
80
  # pointing at it, so a fresh clone would find nothing there (#760). Nothing outside git.
59
81
  #: (String) -> void
60
82
  def refuse_uncommitted_write_up(path)
61
- return unless @repository.inside?
62
-
63
- dirty = uncommitted([path])
64
- return if dirty.empty?
65
-
66
- linked = dirty - [path]
67
- raise Error.new("uncommitted_files",
68
- "The write-up at #{path} differs from the last commit" +
69
- (linked.empty? ? "" : ", through #{linked.join(", ")}"),
70
- "The record will point at the write-up as committed.\n" \
71
- "Commit the write-up, then submit the same answer again.")
83
+ UncommittedFiles.new(uncommitted([path])).refuse_write_up(path) if @repository.inside?
72
84
  end
73
85
 
74
86
  # The commit an audit of id is based on: HEAD, refused while any of files, or a file their links lead to,
@@ -77,15 +89,8 @@ module Principles
77
89
  def base_commit(id, files)
78
90
  return unless @repository.inside?
79
91
 
80
- dirty = uncommitted(files)
81
- unless dirty.empty?
82
- raise Error.new("uncommitted_files", "The map or members of #{id} differ from the last commit: " \
83
- "#{dirty.join(", ")}",
84
- "An audit assesses the map and members as committed, so its record can name the commit " \
85
- "it began from.\nCommit them, then start it again: #{Error::EXECUTABLE} start-audit #{id}")
86
- end
87
-
88
- @repository.head
92
+ UncommittedFiles.new(uncommitted(files)).refuse_audit(id)
93
+ head
89
94
  end
90
95
 
91
96
  # path's text at commit, or nil when commit does not hold it.
@@ -159,9 +164,14 @@ module Principles
159
164
  #: (Array[String]) -> Array[String]
160
165
  def existing(paths) = paths.select { |path| @files.file?(path) }
161
166
 
162
- # The commit at HEAD now; nil outside git.
167
+ # The commit HEAD named when this history first asked, kept for the rest of the command, so a commit landing
168
+ # while it runs leaves no read at one commit and the next at another (#1161); nil outside git. A history serves
169
+ # one command at most, so the next command sees the new commit.
163
170
  #: () -> String?
164
- def head = (@repository.head if @repository.inside?)
171
+ def head = @head.commit
172
+
173
+ #: () -> CapturedHead
174
+ def captured_head = @head
165
175
 
166
176
  # The commits after commit that changed path, a link on the way to it or the file they lead to, newest
167
177
  # first.
@@ -170,11 +180,11 @@ module Principles
170
180
  @repository.commits_since(commit, through_links([path]))
171
181
  end
172
182
 
173
- # Every commit on HEAD's first-parent line that changed any of paths, newest first; with since, only those
174
- # after it.
183
+ # Every commit on the first-parent line of head, the HEAD this history first named, that changed any of paths,
184
+ # newest first; with since, only those after it.
175
185
  #: (Array[String], ?since: String?) -> Array[Hash[String, String]]
176
186
  def commits_touching(paths, since: nil)
177
- @repository.commits_touching(through_links(paths), since: since)
187
+ @repository.commits_touching(through_links(paths), since: since, up_to: head || "HEAD")
178
188
  end
179
189
 
180
190
  # The commits after commit, up to HEAD, that one move of HEAD brought in, whatever they changed (D73).
@@ -191,6 +201,16 @@ module Principles
191
201
  !@repository.commits_since(commit, [*OWN_FOLDERS, *through_links(paths)]).empty?
192
202
  end
193
203
 
204
+ # Whether one raw entry belongs to the permission-specific captured head.
205
+ #: (String) -> bool
206
+ def entry_at_head?(path) = @head.entry?(path)
207
+
208
+ #: (String, Array[String]) -> Array[String]
209
+ def commits_touching_since(base, paths) = @head.commits_touching_since(base, paths)
210
+
211
+ #: (String, String) -> bool
212
+ def entry_at?(revision, path) = @head.entry_at?(revision, path)
213
+
194
214
  private
195
215
 
196
216
  # paths, each with the links on the way to it and the file they lead to, once each.
@@ -22,6 +22,12 @@ module Principles
22
22
  FIRST_RELEASE = "0.0.4"
23
23
  FIELDS = %w[format format_first_release].freeze
24
24
 
25
+ #: (untyped) -> RecordFormat?
26
+ def self.newer_of(fields)
27
+ format = new(fields) if fields.is_a?(Hash)
28
+ format if format&.newer?
29
+ end
30
+
25
31
  #: (Hash[String, untyped]) -> void
26
32
  def initialize(fields)
27
33
  @fields = fields
@@ -13,32 +13,36 @@ module Principles
13
13
  # One member's check and the result an agent reports for it (D30). This tool never runs the check: it
14
14
  # refuses a report that cannot be about the member's own check, and cannot confirm the run happened.
15
15
  class ReportedCheck
16
- SHAPES = "Give check_result as answer_guide.check_result shows."
16
+ SHAPES = "Merge one inner example from answer_guide.check_result.examples into that member's " \
17
+ "response_template.check_result as copy_from says."
17
18
  # How review_basis records a review the agent made itself, which the placeholder and the repair both give.
18
19
  SELF_REVIEWED = "\"Self-reviewed by the agent: <what you checked it against>\"" #: String
19
20
  # The not_run_reason a template prints beside exit_status's placeholder, which an answer that leaves it as
20
- # printed has not given, so filling exit_status alone reports a run (#993).
21
- NOT_RUN_PLACEHOLDER = "Only if the command could not be run here: why, such as a missing tool or a sandbox. " \
22
- "Leave this as printed once exit_status gives the run's status" #: String
21
+ # printed has not given, so filling exit_status alone reports a run (#993). Short, as the template's rule on
22
+ # fields left as printed says the rest (#1191).
23
+ NOT_RUN_PLACEHOLDER = "Only if the check could not run here: why" #: String
23
24
  # The review_basis a template prints for a check no audit ran, or one changed since, which an exit_status needs
24
- # beside it, and which beside not_run_reason left as printed is not given (D63, #993).
25
- REVIEW_BASIS_PLACEHOLDER = "One line saying what the review before the run rested on, such as who reviewed " \
26
- "it or the document that confirms it; for your own review, #{SELF_REVIEWED}. " \
27
- "Leave this as printed only beside not_run_reason".freeze #: String
25
+ # beside it, and which beside not_run_reason left as printed is not given (D63, #993); what to write is the
26
+ # check's instruction (#1191).
27
+ REVIEW_BASIS_PLACEHOLDER = "One line: what the review before the run rested on" #: String
28
28
  # Why an exit status for a check no audit ran is refused without review_basis, and when given its placeholder.
29
29
  NEEDS_BASIS = "check_result needs review_basis beside exit_status, since no audit ran this command" #: String
30
30
  LEFT_BASIS = "check_result.review_basis is the template's placeholder, unchanged, and an exit_status for a " \
31
31
  "command no audit ran needs it" #: String
32
+ # The exit_status a template prints where the run's status goes, what to do being the check's instruction
33
+ # (#1170, #1191).
34
+ EXIT_STATUS_PLACEHOLDER = "the check's exit status, an integer" #: String
32
35
  # The placeholder a template prints in each field an answer may leave as printed to give none.
33
- PLACEHOLDERS = TemplatePlaceholders.new({ "not_run_reason" => NOT_RUN_PLACEHOLDER,
36
+ PLACEHOLDERS = TemplatePlaceholders.new({ "exit_status" => EXIT_STATUS_PLACEHOLDER,
37
+ "not_run_reason" => NOT_RUN_PLACEHOLDER,
34
38
  "review_basis" => REVIEW_BASIS_PLACEHOLDER }) #: TemplatePlaceholders
35
39
  # The review_basis a template prints for a check the last audit ran, which left as printed keeps the line that
36
40
  # audit kept, and replaced gives a new one (#1010).
37
- KEPT_BASIS_PLACEHOLDER = "Only to give a new line for what this run's review rested on; leave this as " \
38
- "printed to keep the line the last audit kept, if any" #: String
41
+ KEPT_BASIS_PLACEHOLDER = "Only for a new line on what this run's review rested on; else kept" #: String
39
42
  # The placeholders a template prints for a check the last audit ran.
40
43
  UNCHANGED_PLACEHOLDERS = TemplatePlaceholders.new(
41
- { "not_run_reason" => NOT_RUN_PLACEHOLDER, "review_basis" => KEPT_BASIS_PLACEHOLDER }
44
+ { "exit_status" => EXIT_STATUS_PLACEHOLDER, "not_run_reason" => NOT_RUN_PLACEHOLDER,
45
+ "review_basis" => KEPT_BASIS_PLACEHOLDER }
42
46
  ) #: TemplatePlaceholders
43
47
  BASIS = "Say in review_basis, in one line, what the review before the run rested on, such as " \
44
48
  "\"The owner reviewed the command in this session.\" or the document that confirms it. If you did " \
@@ -12,7 +12,7 @@ module Principles
12
12
  # the digest from the project as it is now: a different digest means something the request depended
13
13
  # on has changed (D25). The digest has no secret, so it catches mistakes, not forgery.
14
14
  class RequestId
15
- PHASES = %w[assessment correction acknowledgement repointing].freeze
15
+ PHASES = %w[assessment correction acknowledgement acknowledgements repointing].freeze
16
16
  FORMAT = /\A(?<principle>[a-z0-9]+(?:-[a-z0-9]+)*)\.(?<phase>[a-z]+)\.(?<digest>[0-9a-f]{12})\z/
17
17
 
18
18
  #: String
@@ -2,8 +2,10 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "../data/schema_check"
5
+ require_relative "../data/project_files"
5
6
  require_relative "../error"
6
7
  require_relative "refusal_before_shape"
8
+ require_relative "request_id"
7
9
 
8
10
  module Principles
9
11
  module Models
@@ -22,13 +24,41 @@ module Principles
22
24
 
23
25
  REPAIR = "Repair each field listed, starting from the request's response_template." #: String
24
26
 
25
- # parsed is the answer as its source, a file or - for stdin, holds it; check is its phase's answer schema.
26
- #: (untyped, String, Data::SchemaCheck) -> void
27
- def initialize(parsed, source, check)
27
+ # The answer read from the file or stdin the agent named, to the request given, the REQUEST_ID the agent typed,
28
+ # or when it typed none the request_id the answer names, as its template printed it (#995), using that request's
29
+ # phase's schema.
30
+ #: (Data::ProjectFiles, String, stdin: String?, given: String?) -> SentAnswer
31
+ def self.read(files, file, stdin:, given:)
32
+ parsed = if file == "-" then files.parse_json(stdin.to_s, "-", named: NAMED)
33
+ else files.read_json(file, named: FILE_NAMED)
34
+ end
35
+ new(parsed, file, RequestId.parse(given || named_request(parsed)))
36
+ end
37
+
38
+ # The request_id the answer names, refused when it names none, since no REQUEST_ID was typed either (#995).
39
+ #: (untyped) -> String
40
+ def self.named_request(parsed)
41
+ named = parsed["request_id"] if parsed.is_a?(Hash)
42
+ return named if named.is_a?(String)
43
+
44
+ raise Error.new("unknown_request", "#{NAMED} names no request_id, and no REQUEST_ID was given",
45
+ "Keep the request_id the request's response_template printed in the answer, or give it as " \
46
+ "REQUEST_ID.")
47
+ end
48
+ private_class_method :named_request
49
+
50
+ #: RequestId
51
+ attr_reader :request_id
52
+
53
+ # parsed is the answer as its source, a file or - for stdin, holds it, to request_id, whose phase's answer schema
54
+ # it is checked against.
55
+ #: (untyped, String, RequestId) -> void
56
+ def initialize(parsed, source, request_id)
28
57
  @parsed = parsed
29
58
  @source = source
30
- @check = check
31
- check.only(HEAD).checked(parsed, code: "invalid_answer", source: source, repair: REPAIR, named: NAMED)
59
+ @request_id = request_id
60
+ @check = Data::SchemaCheck.new("#{request_id.phase}-answer") #: Data::SchemaCheck
61
+ @check.only(HEAD).checked(parsed, code: "invalid_answer", source: source, repair: REPAIR, named: NAMED)
32
62
  freeze
33
63
  end
34
64
 
@@ -0,0 +1,26 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "guidance_search_path"
5
+
6
+ module Principles
7
+ # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The project's recorded guidance search paths and this invocation's temporary selections, combined once.
10
+ class SurveySearchPaths
11
+ #: Array[String]
12
+ attr_reader :globs
13
+
14
+ #: (recorded: Array[String], also: Array[String]) -> void
15
+ def initialize(recorded:, also:)
16
+ @recorded = recorded.map { |glob| GuidanceSearchPath.new(glob).glob }.uniq.freeze #: Array[String]
17
+ @globs = (@recorded | also.map { |glob| GuidanceSearchPath.new(glob).glob }).freeze #: Array[String]
18
+ freeze
19
+ end
20
+
21
+ # Saved provenance is distinct from all match counts; omit it when the project records no search paths.
22
+ #: () -> Hash[String, untyped]
23
+ def recorded_listing = @recorded.empty? ? {} : { "recorded_guidance_search_paths" => @recorded }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # The files, and the files their links lead to, that differ from HEAD or are not yet committed, as ProjectHistory
10
+ # found them for a write-up or an audit's members, and the refusal each gives while there are any.
11
+ class UncommittedFiles
12
+ # An existing assessment keeps its prepared answer while these whole files are brought back to a commit.
13
+ ASSESSMENT_REPAIR = "An audit requires the whole map and member files to be committed, even when an edit " \
14
+ "is outside a judged passage.\nCommit the intended changes in the named files, then retry " \
15
+ "the same answer unchanged. If that retry is refused as stale, follow its repair to " \
16
+ "start a new audit."
17
+
18
+ #: (Array[String]) -> void
19
+ def initialize(paths)
20
+ @paths = paths
21
+ freeze
22
+ end
23
+
24
+ # Refuses the write-up at path while it, or a file its links lead to, differs from HEAD: the record is committed
25
+ # pointing at it, so a fresh clone would find nothing there (#760).
26
+ #: (String) -> void
27
+ def refuse_write_up(path)
28
+ return if @paths.empty?
29
+
30
+ linked = @paths - [path]
31
+ raise Error.new("uncommitted_files",
32
+ "The write-up at #{path} differs from the last commit" +
33
+ (linked.empty? ? "" : ", through #{linked.join(", ")}"),
34
+ "The record will point at the write-up as committed.\n" \
35
+ "Commit the write-up, then submit the same answer again.")
36
+ end
37
+
38
+ # Refuses an audit of id while any of its map or members differs from HEAD.
39
+ #: (String) -> void
40
+ def refuse_audit(id)
41
+ return if @paths.empty?
42
+
43
+ raise Error.new("uncommitted_files", "The map or members of #{id} differ from the last commit: " \
44
+ "#{@paths.join(", ")}",
45
+ "An audit assesses the map and members as committed, so its record can name the commit " \
46
+ "it began from.\nCommit them, then start it again: #{Error::EXECUTABLE} start-audit #{id}")
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "meta_principle"
6
+
7
+ module Principles
8
+ module Models
9
+ # An absent principle id, whose repair creates an ordinary map or sets up the keeping principle.
10
+ class UnknownPrinciple
11
+ #: (String) -> void
12
+ def initialize(id)
13
+ @id = id.dup.freeze #: String
14
+ freeze
15
+ end
16
+
17
+ #: () -> Error
18
+ def refusal
19
+ creating = if @id == MetaPrinciple::ID
20
+ MetaPrinciple::SET_UP
21
+ else
22
+ "To create it: #{Error::EXECUTABLE} create-principle #{@id} --description TEXT"
23
+ end
24
+ Error.new("unknown_principle", "No map named #{@id}",
25
+ "#{creating}\nTo see the mapped ids: #{Error::EXECUTABLE} list-principles")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,38 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The positional words a command takes and the values the invocation gives them, after option parsing.
6
+ class PositionalArguments
7
+ #: (Array[String], Array[String]) -> void
8
+ def initialize(names, values)
9
+ @names = names.dup.freeze #: Array[String]
10
+ @values = values.dup.freeze #: Array[String]
11
+ freeze
12
+ end
13
+
14
+ #: () -> String?
15
+ def id = %w[id id?].include?(@names.first) ? @values.first : nil
16
+
17
+ # Every named argument other than the principle id, as the controller receives it, an optional one by its name
18
+ # without the ?.
19
+ #: () -> Hash[String, untyped]
20
+ def bindings
21
+ bound = @names.map { it.chomp("?") }.zip(@values).to_h.except("id")
22
+ repeated = @names.last
23
+ return bound unless repeated == "path..."
24
+
25
+ bound.except(repeated).merge("path" => @values.drop(@names.length - 1))
26
+ end
27
+
28
+ #: () -> Array[String]
29
+ def missing = @names.drop(@values.length).reject { |name| name.end_with?("?") }.map(&:upcase)
30
+
31
+ #: () -> bool
32
+ def too_many? = @names.last != "path..." && @values.length > @names.length
33
+
34
+ # The command's positional arguments as usage shows them, optional ones in brackets.
35
+ #: () -> String
36
+ def shown = @names.map { |name| name.end_with?("?") ? "[#{name.chomp("?").upcase}]" : name.upcase }.join(" ")
37
+ end
38
+ end