principles 0.0.5 → 0.0.6

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/command_line.rb +12 -28
  4. data/lib/principles/command_routes.rb +7 -1
  5. data/lib/principles/controllers/acknowledgement.rb +36 -26
  6. data/lib/principles/controllers/answer.rb +7 -5
  7. data/lib/principles/controllers/assessment.rb +14 -3
  8. data/lib/principles/controllers/audit_completion.rb +3 -1
  9. data/lib/principles/controllers/command.rb +2 -2
  10. data/lib/principles/controllers/correction.rb +3 -1
  11. data/lib/principles/controllers/full_audit_request.rb +1 -1
  12. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  13. data/lib/principles/controllers/inventory.rb +3 -22
  14. data/lib/principles/controllers/mapping.rb +9 -1
  15. data/lib/principles/controllers/member_addition.rb +65 -0
  16. data/lib/principles/controllers/member_entries.rb +6 -24
  17. data/lib/principles/controllers/member_problems_report.rb +2 -2
  18. data/lib/principles/controllers/members_to_assess.rb +1 -1
  19. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  20. data/lib/principles/controllers/repoint.rb +5 -2
  21. data/lib/principles/controllers/survey.rb +60 -0
  22. data/lib/principles/data/audit_files.rb +4 -0
  23. data/lib/principles/data/candidate_files_found.rb +48 -13
  24. data/lib/principles/data/command-steps.json +77 -16
  25. data/lib/principles/data/committed_tree.rb +84 -0
  26. data/lib/principles/data/first_parent_log.rb +48 -0
  27. data/lib/principles/data/first_parent_range.rb +122 -0
  28. data/lib/principles/data/git_command.rb +37 -0
  29. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  30. data/lib/principles/data/map_files.rb +35 -10
  31. data/lib/principles/data/principles_directory.rb +40 -0
  32. data/lib/principles/data/principles_subfolder.rb +39 -16
  33. data/lib/principles/data/project_files.rb +11 -3
  34. data/lib/principles/data/repository.rb +55 -29
  35. data/lib/principles/data/requested_candidate_files.rb +43 -0
  36. data/lib/principles/data/running_version.rb +3 -5
  37. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +4 -5
  38. data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
  39. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  40. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  41. data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
  42. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  43. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  44. data/lib/principles/data/verified_head.rb +162 -0
  45. data/lib/principles/invocation_options.rb +2 -2
  46. data/lib/principles/models/acknowledgement.rb +28 -6
  47. data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
  48. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  49. data/lib/principles/models/audit_record.rb +4 -0
  50. data/lib/principles/models/audit_records.rb +34 -8
  51. data/lib/principles/models/candidate_files.rb +17 -6
  52. data/lib/principles/models/candidate_inventory.rb +51 -7
  53. data/lib/principles/models/captured_head.rb +72 -0
  54. data/lib/principles/models/check_since_last_audit.rb +4 -8
  55. data/lib/principles/models/declared_map_changes.rb +25 -9
  56. data/lib/principles/models/declared_member_removals.rb +75 -0
  57. data/lib/principles/models/disposition.rb +4 -2
  58. data/lib/principles/models/fix_only_fields.rb +12 -0
  59. data/lib/principles/models/guidance_search_path.rb +26 -0
  60. data/lib/principles/models/guidance_search_paths.rb +57 -0
  61. data/lib/principles/models/line_span.rb +6 -0
  62. data/lib/principles/models/loaded_files.rb +1 -2
  63. data/lib/principles/models/loading_scope.rb +61 -0
  64. data/lib/principles/models/locator.rb +6 -0
  65. data/lib/principles/models/mapped_principles.rb +39 -37
  66. data/lib/principles/models/member_file.rb +20 -71
  67. data/lib/principles/models/member_history.rb +7 -5
  68. data/lib/principles/models/member_loading_scopes.rb +49 -0
  69. data/lib/principles/models/member_loads.rb +4 -0
  70. data/lib/principles/models/member_mapping_run.rb +30 -0
  71. data/lib/principles/models/member_moves.rb +4 -0
  72. data/lib/principles/models/member_problems.rb +48 -24
  73. data/lib/principles/models/member_region.rb +129 -0
  74. data/lib/principles/models/member_repair_moves.rb +9 -11
  75. data/lib/principles/models/member_snapshots.rb +14 -1
  76. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  77. data/lib/principles/models/meta_principle.rb +14 -0
  78. data/lib/principles/models/missing_files.rb +2 -2
  79. data/lib/principles/models/other_templates_placeholders.rb +1 -1
  80. data/lib/principles/models/outline_budget.rb +29 -14
  81. data/lib/principles/models/principle.rb +14 -7
  82. data/lib/principles/models/principle_file_revision.rb +48 -0
  83. data/lib/principles/models/principle_history.rb +46 -19
  84. data/lib/principles/models/principle_lineage.rb +118 -0
  85. data/lib/principles/models/principle_map_revision.rb +39 -0
  86. data/lib/principles/models/principle_mapping_history.rb +132 -0
  87. data/lib/principles/models/principle_members.rb +14 -0
  88. data/lib/principles/models/principle_predecessor.rb +45 -0
  89. data/lib/principles/models/principle_publication.rb +177 -0
  90. data/lib/principles/models/principle_revision.rb +104 -0
  91. data/lib/principles/models/problem_report.rb +17 -5
  92. data/lib/principles/models/project.rb +43 -27
  93. data/lib/principles/models/project_history.rb +45 -25
  94. data/lib/principles/models/record_format.rb +6 -0
  95. data/lib/principles/models/reported_check.rb +2 -1
  96. data/lib/principles/models/sent_answer.rb +10 -0
  97. data/lib/principles/models/survey_search_paths.rb +26 -0
  98. data/lib/principles/models/uncommitted_files.rb +50 -0
  99. data/lib/principles/models/unknown_principle.rb +29 -0
  100. data/lib/principles/positional_arguments.rb +37 -0
  101. data/lib/principles/version.rb +2 -2
  102. data/lib/principles/views/acknowledgement_result.rb +16 -12
  103. data/lib/principles/views/added_member.rb +41 -0
  104. data/lib/principles/views/answered_request.rb +21 -0
  105. data/lib/principles/views/assessment_request.rb +2 -1
  106. data/lib/principles/views/audit_result.rb +21 -26
  107. data/lib/principles/views/candidate_files_result.rb +56 -12
  108. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  109. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  110. data/lib/principles/views/correction_request.rb +32 -1
  111. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  112. data/lib/principles/views/json_with_entries_on_lines.rb +12 -4
  113. data/lib/principles/views/map_added_to.rb +56 -2
  114. data/lib/principles/views/map_result.rb +22 -42
  115. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  116. data/lib/principles/views/member_change_since_baseline.rb +2 -1
  117. data/lib/principles/views/member_repairs.rb +2 -1
  118. data/lib/principles/views/new_loading_scope.rb +31 -0
  119. data/lib/principles/views/one_member_check_result_template.rb +25 -21
  120. data/lib/principles/views/principle_read_result.rb +4 -1
  121. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  122. data/lib/principles/views/problem_lines.rb +3 -1
  123. data/lib/principles/views/problem_result.rb +8 -3
  124. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -3
  125. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -6
  126. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -43
  127. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  128. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +12 -0
  129. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  130. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  131. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  132. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +4 -2
  133. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  134. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +2 -2
  135. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  136. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  137. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  138. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  139. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  140. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  141. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +37 -4
  142. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +5 -4
  143. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  144. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  145. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  146. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +26 -0
  147. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  148. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +2 -2
  149. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  150. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  151. metadata +55 -4
  152. data/lib/principles/models/candidate_listing.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40e41136c5be852cc2019089d41ab1548144e52138ab51c80211befe32bfa411
4
- data.tar.gz: 3d7d56d9ba40d0678e39fcd4b7f6ecca2b231ac5b449f07af84617b8e0ad1a91
3
+ metadata.gz: ec72c7b217d3e48437dcdb1e8166654efe8b27fe3888d35d90eeeb31fcfa0c8c
4
+ data.tar.gz: b8de7786425d0a890ff2452b78b50b667e895e39fe45552c4d2e37c69a80a4c3
5
5
  SHA512:
6
- metadata.gz: ff6dd21e3e9a0e929ae135aaaa587b8781e6bea67ac6547fa8b23ce43d15a75d05a3c9490eaecf1049d76384df1e39eb7e5d6c0605a883dc67ff5051b308f12b
7
- data.tar.gz: cd61142617ebf7f28eba7b2ae5bc89e1dd18d745fb8d9c763bacf68c6e2dacc7a5cc5f66869c0bf4da24d584134612b4f9ae52a63d682931c342a96217476bb0
6
+ metadata.gz: 528513b4102743cb1fc16d599fc3760b4e1dd8eafa3cd5ea5ce305a50f9f0a19f37777aeff2a5e15b936003050635c27ab9153b2d2892eb4aade644a1372e6ac
7
+ data.tar.gz: 7fa772560fdbb6ead5720db8dc8381eaa094426766d111a51968a222899eaa6a29f6ce89b1c692e37ce1275ab87b557434ffb32747d45e8c8d1f4d7e41f2ac74
@@ -5,12 +5,15 @@ require_relative "invocation_options"
5
5
 
6
6
  module Principles
7
7
  # The options the plugin's after-commit hook gives list-member-problems, --commits-after and --hook-event (D73),
8
- # and what is wrong with them as given, which CommandLine refuses as a usage error.
8
+ # and what is wrong with them as given, which CommandLine refuses as a usage error. list-candidate-files takes
9
+ # --commits-after for a range of its own, so CommandLine checks these on COMMAND alone (#1171).
9
10
  class AfterCommitHookOptions
10
11
  # The events Claude Code runs the after-commit hook on, which --hook-event echoes back to it.
11
12
  EVENTS = %w[PostToolUse PostToolUseFailure].freeze #: Array[String]
12
13
  # A commit's full sha, SHA-1 or SHA-256, which the hook resolves HEAD@{1} to before passing it.
13
14
  FULL_SHA = /\A\h{40}(?:\h{24})?\z/ #: Regexp
15
+ # The command the hook runs, the one these options are checked on.
16
+ COMMAND = "list-member-problems"
14
17
 
15
18
  #: (InvocationOptions) -> void
16
19
  def initialize(options)
@@ -8,6 +8,7 @@ require_relative "session_start_options"
8
8
  require_relative "start_audit_options"
9
9
  require_relative "models/command_steps"
10
10
  require_relative "prose_list"
11
+ require_relative "positional_arguments"
11
12
 
12
13
  module Principles
13
14
  # One invocation's words: the command, its positional arguments and its options, refused with an
@@ -81,43 +82,30 @@ module Principles
81
82
  # The principle id, for a command whose first argument is one.
82
83
  #: () -> String?
83
84
  def id
84
- %w[id id?].include?(names.first) ? values.first : nil
85
+ positionals.id
85
86
  end
86
87
 
87
88
  # The options, with every positional argument but the id under its name.
88
89
  #: () -> Hash[String, untyped]
89
90
  def command_options
90
- names.zip(values).each_with_object(@options.to_h) do |(name, value), all|
91
- all[name] = value unless %w[id id?].include?(name)
92
- end
91
+ @options.to_h.merge(positionals.bindings)
93
92
  end
94
93
 
95
94
  private
96
95
 
97
- #: () -> Array[String]
98
- def names
99
- @positional.fetch(command.to_s)
100
- end
101
-
102
- #: () -> Array[String]
103
- def values
104
- @arguments.drop(1)
105
- end
96
+ #: () -> PositionalArguments
97
+ def positionals = PositionalArguments.new(@positional.fetch(command.to_s), @arguments.drop(1))
106
98
 
107
99
  # Each argument the command needs and was not given, named in one refusal: an agent that met one refusal per
108
100
  # missing argument repaired them one at a time (#1083). Each option command-steps.json says it requires is one.
109
101
  #: (String) -> void
110
102
  def check_missing(name)
111
- missing = missing_arguments + missing_options(name)
103
+ missing = positionals.missing + missing_options(name)
112
104
  return if missing.empty?
113
105
 
114
106
  raise OptionParser::MissingArgument, "#{name} needs #{ProseList.new(missing)}"
115
107
  end
116
108
 
117
- # The positional arguments the command needs past those given, as usage names them.
118
- #: () -> Array[String]
119
- def missing_arguments = names.drop(values.length).reject { |each| each.end_with?("?") }.map(&:upcase)
120
-
121
109
  # The options command name requires and was not given, as a refusal names them.
122
110
  #: (String) -> Array[String]
123
111
  def missing_options(name)
@@ -128,18 +116,12 @@ module Principles
128
116
  # Too many arguments; check_missing has refused too few.
129
117
  #: (String) -> void
130
118
  def check_arguments(name)
131
- return if values.length <= names.length
119
+ return unless positionals.too_many?
132
120
 
133
- takes = "#{name} takes #{shown_arguments}".strip.sub(/ takes\z/, " takes no arguments")
121
+ takes = "#{name} takes #{positionals.shown}".strip.sub(/ takes\z/, " takes no arguments")
134
122
  raise OptionParser::InvalidArgument, takes
135
123
  end
136
124
 
137
- # The positional arguments as usage shows them; a name ending in ? is optional and shown in brackets.
138
- #: () -> String
139
- def shown_arguments
140
- names.map { |each| each.end_with?("?") ? "[#{each.chomp("?").upcase}]" : each.upcase }.join(" ")
141
- end
142
-
143
125
  # An option a command does not take is refused, so a mistyped command never runs as something else.
144
126
  #: (String) -> void
145
127
  def check_options(name)
@@ -166,10 +148,12 @@ module Principles
166
148
  end
167
149
 
168
150
  # Options checked together, each set owning what is wrong with it as given: --session-start (#717), the
169
- # after-commit hook's pair (D73) and the audit start-audit begins (#760); the first fault is refused.
151
+ # after-commit hook's pair on the command it runs (D73) and the audit start-audit begins (#760); the first fault is
152
+ # refused.
170
153
  #: (String) -> void
171
154
  def check_combined_options(name)
172
- sets = [SessionStartOptions.new(@options), AfterCommitHookOptions.new(@options), StartAuditOptions.new(@options)]
155
+ hook = (AfterCommitHookOptions.new(@options) if name == AfterCommitHookOptions::COMMAND)
156
+ sets = [SessionStartOptions.new(@options), hook, StartAuditOptions.new(@options)].compact
173
157
  fault = sets.filter_map(&:fault).first or return
174
158
  raise UsageRefusal.new(fault, help_repair(name))
175
159
  end
@@ -2,6 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "controllers/inventory"
5
+ require_relative "controllers/survey"
6
+ require_relative "controllers/guidance_search_paths"
5
7
  require_relative "controllers/member_problems_report"
6
8
  require_relative "controllers/mapping"
7
9
  require_relative "controllers/meta_principle_setup"
@@ -31,7 +33,10 @@ module Principles
31
33
  end
32
34
 
33
35
  ROUTES = {
34
- "list-candidate-files" => Route.new(Controllers::Inventory, []),
36
+ "list-candidate-files" => Route.new(Controllers::Survey, []),
37
+ "show-candidate-outlines" => Route.new(Controllers::Survey, ["path..."]),
38
+ "add-guidance-search-path" => Route.new(Controllers::GuidanceSearchPaths, %w[glob]),
39
+ "remove-guidance-search-path" => Route.new(Controllers::GuidanceSearchPaths, %w[glob]),
35
40
  "list-principles" => Route.new(Controllers::Inventory, []),
36
41
  "list-member-problems" => Route.new(Controllers::MemberProblemsReport, %w[id?]),
37
42
  "show-principle" => Route.new(Controllers::Inventory, %w[id]),
@@ -39,6 +44,7 @@ module Principles
39
44
  "list-open-findings" => Route.new(Controllers::Audit, %w[id?]),
40
45
  "show-meta-principle-passage" => Route.new(Controllers::MetaPrincipleSetup, []),
41
46
  "create-principle" => Route.new(Controllers::Mapping, %w[id]),
47
+ "remove-principle" => Route.new(Controllers::Mapping, %w[id]),
42
48
  "change-description" => Route.new(Controllers::Mapping, %w[id]),
43
49
  "change-activation" => Route.new(Controllers::Mapping, %w[id]),
44
50
  "add-member" => Route.new(Controllers::MemberEntries, %w[id path]),
@@ -21,9 +21,10 @@ module Principles
21
21
  #: (String, String) -> Hash[String, untyped]
22
22
  def start(id, member_id)
23
23
  naming_the_executable(rerun: one_member_audit(id)) do
24
- acknowledgement, change, check_result = asked(id, member_id)
24
+ acknowledgement, change, check = asked(id, member_id)
25
25
  view.request(request_id: acknowledgement.request_id.to_s, principle_id: id, change: change,
26
- open_findings: acknowledgement.open_findings, placeholders: placeholders(check_result, change))
26
+ context: { **acknowledgement.open_findings, **instruction_for(check) },
27
+ placeholders: placeholders(check&.to_h, change))
27
28
  .merge("wrote" => [])
28
29
  end
29
30
  end
@@ -33,15 +34,15 @@ module Principles
33
34
  #: (String, String) -> Hash[String, untyped]
34
35
  def to_fill(id, member_id)
35
36
  naming_the_executable(rerun: one_member_audit(id)) do
36
- acknowledgement, change, check_result = asked(id, member_id)
37
+ acknowledgement, change, check = asked(id, member_id)
37
38
  view.answer_to_fill(request_id: acknowledgement.request_id.to_s, change: change,
38
- placeholders: placeholders(check_result, change))
39
+ placeholders: placeholders(check&.to_h, change))
39
40
  end
40
41
  end
41
42
 
42
43
  # The result of answering, and the record it changes, not yet written.
43
44
  # @override
44
- #: (Models::SubmittedAnswer) -> [Hash[String, untyped], Array[Models::AuditRecord]]
45
+ #: (Models::SubmittedAnswer) -> [Views::AnsweredRequest, Array[Models::AuditRecord]]
45
46
  def answered(submitted)
46
47
  request_id = submitted.request_id
47
48
  response = submitted.response
@@ -53,9 +54,10 @@ module Principles
53
54
  end
54
55
 
55
56
  # The refusals an answer meets before its shape: any phase's, then a placeholder its template printed left in,
56
- # which the shape would refuse in meaning_kept without naming it (#773).
57
+ # which the shape would refuse in meaning_kept without naming it (#773), or in a checked member's exit_status
58
+ # with a repair this template does not take (#1170).
57
59
  #: (Models::RequestId) -> Array[Models::RefusalBeforeShape]
58
- def before_shape(request_id) = [*super, Models::Acknowledgement::PLACEHOLDERS]
60
+ def before_shape(request_id) = [*super, Models::Acknowledgement::LEFT_AS_PRINTED]
59
61
 
60
62
  private
61
63
 
@@ -64,45 +66,54 @@ module Principles
64
66
  # answer, not the request id, so this names the check's whether the member has one.
65
67
  # @override
66
68
  #: (Models::RequestId) -> Hash[String, untyped]?
67
- def printed_placeholders(_request_id) = placeholders(Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h)
69
+ def printed_placeholders(_request_id)
70
+ placeholders(Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.to_h
71
+ .merge("exit_status" => Models::Acknowledgement::EXIT_STATUS_PLACEHOLDER))
72
+ end
68
73
 
69
74
  # The acknowledgement of principle id's member, its change since its baseline, as the request shows it, and the
70
- # check_result its answer fills, if the member has a check.
71
- #: (String, String) -> [Models::Acknowledgement, Views::MemberChangeSinceBaseline, Hash[String, untyped]?]
75
+ # check_result its answer fills with the instruction beside it, if the member has a check.
76
+ #: (String, String)
77
+ #| -> [Models::Acknowledgement, Views::MemberChangeSinceBaseline, Views::OneMemberCheckResultTemplate?]
72
78
  def asked(id, member_id)
73
79
  acknowledgement, member, base = prepared(id, member_id)
74
80
  baseline, lines = since_baseline(id, acknowledgement, member)
75
- check_result = check_template(id, member)
81
+ check = check_template(id, member)
76
82
  [acknowledgement,
77
83
  Views::MemberChangeSinceBaseline.new(
78
- member: shown(acknowledgement, member, baseline), member_lines: lines.shown(taken: bytes_of(check_result)),
84
+ member: shown(acknowledgement, member, baseline), member_lines: lines.shown(taken: bytes_of(check)),
79
85
  first_changed_lines: acknowledgement.first_changed_lines(lines),
80
86
  commits: commits(acknowledgement, baseline, base), paths: acknowledgement.paths_since(baseline)
81
- ), check_result]
87
+ ), check]
82
88
  end
83
89
 
84
- # The bytes check_result takes as the request prints it, which the member's lines give up (#1119).
85
- #: (Hash[String, untyped]?) -> Integer
86
- def bytes_of(check_result) = check_result ? JSON.pretty_generate(check_result).bytesize : 0
90
+ # The request's check_instruction for a checked member, how to run and report its check; none without one (#1170).
91
+ #: (Views::OneMemberCheckResultTemplate?) -> Hash[String, String]
92
+ def instruction_for(check) = check ? { "check_instruction" => check.instruction } : {}
93
+
94
+ # The bytes the check's template and instruction take as the request prints them, which the member's lines
95
+ # give up (#1119).
96
+ #: (Views::OneMemberCheckResultTemplate?) -> Integer
97
+ def bytes_of(check) = check ? JSON.pretty_generate(check.to_h).bytesize + check.instruction.bytesize : 0
87
98
 
88
- # The text the template prints in each field the agent writes: its judgement's placeholders, the quotes as the
89
- # change's first_changed_lines hints them (#1111), and check_result's for a checked member.
99
+ # The text the template prints in each field the agent writes: its judgement's placeholders, meaning_kept's
100
+ # chosen by whether the change's first_changed_lines is a pure insertion (#1142), and check_result's for a
101
+ # checked member. The quotes the answer reads as first_changed_lines when left out are not printed (#1170).
90
102
  #: (Hash[String, untyped]?, ?Views::MemberChangeSinceBaseline?) -> Hash[String, untyped]
91
103
  def placeholders(check_result, change = nil)
92
104
  quotes = change&.first_changed_lines.to_h
93
- { **Models::Acknowledgement.placeholders_beside(quotes), **quotes,
105
+ { **Models::Acknowledgement.placeholders_beside(quotes),
94
106
  **(check_result ? { "check_result" => check_result } : {}) }
95
107
  end
96
108
 
97
109
  # The check_result a checked member's answer fills, for the check the last audit ran, which a one-member audit
98
110
  # requires (D30, D63, #1071), asking for a passing run alone (#1112); nil for a member without a check.
99
- #: (String, Models::Member) -> Hash[String, untyped]?
111
+ #: (String, Models::Member) -> Views::OneMemberCheckResultTemplate?
100
112
  def check_template(id, member)
101
- checks = Models::CheckSinceLastAudit.new(id:, history: @history, principles: @principles,
113
+ checks = Models::CheckSinceLastAudit.new(principle_history: principle_history(id),
102
114
  record: @audit_records.find(id))
103
115
  Views::OneMemberCheckResultTemplate.for(checks.entry(member),
104
- review_basis:
105
- Models::ReportedCheck::UNCHANGED_PLACEHOLDERS.fetch("review_basis"))
116
+ exit_status: Models::Acknowledgement::EXIT_STATUS_PLACEHOLDER)
106
117
  end
107
118
 
108
119
  # The one-member audit of principle id's member, as a refusal naming a near miss leads its repair with (D56).
@@ -138,9 +149,8 @@ module Principles
138
149
  # record vouches for, placed as that commit's map placed it or as it is placed now (#547, #550), and its own
139
150
  # lines there and now, which the answer's quotes are checked against (#379).
140
151
  #: (String, Models::Acknowledgement, Models::Member) -> [Models::Placement, Models::MemberLines]
141
- def since_baseline(id, acknowledgement, member)
142
- placements = principle_history(id).placements_since(acknowledgement.last_judged_commit, member.key,
143
- @principles.find(id).member(member.id))
152
+ def since_baseline(_id, acknowledgement, member)
153
+ placements = acknowledgement.placements_in(@project)
144
154
  baseline = acknowledgement.baseline(placements)
145
155
  lines = @project.member_lines(member.locator, since: baseline.commit, then_locator: baseline.locator)
146
156
  [baseline, acknowledgement.compared(lines)]
@@ -28,7 +28,7 @@ module Principles
28
28
  def call(command, _id, options)
29
29
  naming_the_executable do
30
30
  case command
31
- when "submit-answer" then submit_answer(submitted(options))
31
+ when "submit-answer" then submit_answer(submitted(options), options.fetch("file"))
32
32
  when "show-answer-check" then check_answer(submitted(options), options.fetch("file"))
33
33
  else unknown(command)
34
34
  end
@@ -59,11 +59,12 @@ module Principles
59
59
  end
60
60
 
61
61
  # Accepts the answer and writes the record changes it makes.
62
- #: (Models::SubmittedAnswer) -> untyped
63
- def submit_answer(submitted)
62
+ #: (Models::SubmittedAnswer, String) -> untyped
63
+ def submit_answer(submitted, answer_file)
64
64
  output, changes = judged(submitted)
65
65
  wrote = changes.map { |record| @audit_records.save(record) }
66
- audit_result.present(output).merge("wrote" => wrote)
66
+ audit_result.present(output, source_request_id: submitted.request_id.to_s,
67
+ answer_file: answer_file).merge("wrote" => wrote)
67
68
  end
68
69
 
69
70
  # Runs every check submit-answer would, and says what it would write, writing nothing; its submit command
@@ -72,7 +73,8 @@ module Principles
72
73
  #: (Models::SubmittedAnswer, String) -> untyped
73
74
  def check_answer(submitted, answer_file)
74
75
  output, changes = judged(submitted)
75
- audit_result.with_correction_to_fill(acceptable(submitted, answer_file, changes), output).merge("wrote" => [])
76
+ audit_result.with_correction_to_fill(acceptable(submitted, answer_file, changes), output,
77
+ answer_file: answer_file).merge("wrote" => [])
76
78
  end
77
79
 
78
80
  # The answer passed every check: what submitting it would write, and its submit command.
@@ -7,6 +7,7 @@ require_relative "../models/assessment_left_as_printed"
7
7
  require_relative "../models/audit"
8
8
  require_relative "../models/request_id"
9
9
  require_relative "../models/unchecked_members"
10
+ require_relative "../models/uncommitted_files"
10
11
  require_relative "audit_completion"
11
12
  require_relative "full_audit_request"
12
13
 
@@ -40,8 +41,11 @@ module Principles
40
41
  def checked_request(request_id, head)
41
42
  audit = audit_now(request_id.principle_id)
42
43
  basis = Models::AssessmentBasis.new(head.fetch("basis"))
43
- audit.check_assessment_request(request_id, basis: basis, committed: committed(basis.base, audit.map),
44
- record: @audit_records.find(audit.id), loads: loads_to_check(audit))
44
+ prior = audit.check_assessment_request(request_id, basis: basis, committed: committed(basis.base, audit.map),
45
+ record: @audit_records.find(audit.id),
46
+ loads: loads_to_check(audit))
47
+ principle_history(audit.id).confirm_current_id_since(basis.base)
48
+ prior
45
49
  end
46
50
 
47
51
  # The refusals an answer meets before its shape: first a check_result on a member with no check, which the
@@ -59,7 +63,14 @@ module Principles
59
63
 
60
64
  # The placeholders a full audit's template printed, as start-audit --as template prints it now (#1084).
61
65
  #: (Models::RequestId) -> Hash[String, untyped]?
62
- def printed_placeholders(request_id) = handed(FullAuditRequest, principle_id: request_id.principle_id).to_fill
66
+ def printed_placeholders(request_id)
67
+ handed(FullAuditRequest, principle_id: request_id.principle_id).to_fill
68
+ rescue Error => e
69
+ # Template construction keeps the start guard, but this caller already has an answer to retry.
70
+ raise unless e.payload.fetch("code") == "uncommitted_files"
71
+
72
+ raise e.including("repair" => Models::UncommittedFiles::ASSESSMENT_REPAIR)
73
+ end
63
74
 
64
75
  # The assessment's fields and its decisions on the prior findings checked, then the audit completed or its
65
76
  # correction asked for.
@@ -8,6 +8,8 @@ require_relative "../models/commits_since_base"
8
8
  require_relative "../models/other_principles"
9
9
  require_relative "../views/prior_finding_decisions_result"
10
10
 
11
+ require_relative "../views/answered_request"
12
+
11
13
  module Principles
12
14
  # Each runs one command: reads models, applies their rules and prints through a view.
13
15
  # controllers/CLAUDE.md owns the boundary.
@@ -35,7 +37,7 @@ module Principles
35
37
  written = record(start, audit.outcomes(findings, dispositions, decided), "completed", audit.now)
36
38
  changes = @audit_records.changes(written)
37
39
  @replacing&.confirm_writable(audit.id, @audit_records.find(audit.id), changes)
38
- [completion_result(start, audit, dispositions, decided, written), changes]
40
+ [Views::AnsweredRequest.new(completion_result(start, audit, dispositions, decided, written)), changes]
39
41
  end
40
42
 
41
43
  # The record an audit writes, made now, saying what its assessments answered, with each assessment carried
@@ -53,10 +53,10 @@ module Principles
53
53
 
54
54
  private
55
55
 
56
- # The history of principle_id's map, read through the collaborators this controller already holds.
56
+ # The command's shared history view for principle_id's map.
57
57
  #: (String) -> Models::PrincipleHistory
58
58
  def principle_history(principle_id)
59
- Models::PrincipleHistory.new(id: principle_id, history: @history, principles: @principles)
59
+ @project.principle_history(principle_id)
60
60
  end
61
61
 
62
62
  # Saves the map, and nothing else, then prints the result the block builds from the map as written.
@@ -97,7 +97,9 @@ module Principles
97
97
  map = started_from(basis, audit, changes)
98
98
  base = basis.base_commit
99
99
  found = base ? committed(base, map) : @audit_records.find(audit.id)&.base_members
100
- audit.confirmed_start(request_id, basis, found)
100
+ checked = audit.confirmed_start(request_id, basis, found)
101
+ principle_history(audit.id).confirm_current_id_since(base)
102
+ checked
101
103
  end
102
104
 
103
105
  #: (Models::DeclaredMapChanges, Models::CorrectionBasis) -> AuditCompletion
@@ -45,7 +45,7 @@ module Principles
45
45
  # The request as start-audit prints it, with a notice when the last audit's record was left uncommitted.
46
46
  #: () -> Hash[String, untyped]
47
47
  def printed
48
- audit_result.present(with_record_notice(audit_result.assessment_request(asked))).merge("wrote" => [])
48
+ audit_result.request(with_record_notice(audit_result.assessment_request(asked))).merge("wrote" => [])
49
49
  end
50
50
 
51
51
  # The answer alone, as start-audit --as template prints it, to fill and submit under the request's id (D81).
@@ -0,0 +1,31 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../views/guidance_search_paths_result"
6
+
7
+ module Principles
8
+ # Each runs one command: reads models, applies their rules and prints through a view.
9
+ # controllers/CLAUDE.md owns the boundary.
10
+ module Controllers
11
+ # The writes to the project's recorded guidance search paths, separate from member maps and audits.
12
+ class GuidanceSearchPaths < Command
13
+ COMMANDS = { "add-guidance-search-path" => :adding, "remove-guidance-search-path" => :removing }
14
+ .freeze #: Hash[String, Symbol]
15
+
16
+ #: (String, String?, Hash[String, untyped]) -> untyped
17
+ def call(command, _id, options)
18
+ naming_the_executable do
19
+ operation = COMMANDS[command] or unknown(command)
20
+ current = @project.guidance_search_paths
21
+ updated = current.public_send(operation, options.fetch("glob"))
22
+ unchanged = updated.same_as?(current)
23
+ wrote = unchanged ? [] : [updated.save]
24
+ Views::GuidanceSearchPathsResult.new(invocation)
25
+ .result(status: unchanged ? "unchanged" : "guidance_search_paths_updated",
26
+ globs: updated.globs, wrote:)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -4,22 +4,19 @@
4
4
  require_relative "command"
5
5
  require_relative "../models/member_state"
6
6
  require_relative "../models/meta_principle"
7
- require_relative "../views/candidate_files_result"
8
- require_relative "../views/json_with_entries_on_lines"
9
7
  require_relative "../views/principle_read_result"
10
8
 
11
9
  module Principles
12
10
  # Each runs one command: reads models, applies their rules and prints through a view.
13
11
  # controllers/CLAUDE.md owns the boundary.
14
12
  module Controllers
15
- # The reads that show what a project holds: its candidate instruction files, its principles, and each
16
- # member and how fresh it is against the last audit. None changes anything on disk.
13
+ # The reads that show what a project has mapped: its principles, and each member and how fresh it is against the
14
+ # last audit. None changes anything on disk. Survey runs the survey of candidate files (#1015).
17
15
  class Inventory < Command
18
16
  #: (String, String?, Hash[String, untyped]) -> untyped
19
17
  def call(command, id, _options)
20
18
  naming_the_executable do
21
19
  case command
22
- when "list-candidate-files" then list_candidate_files
23
20
  when "list-principles" then listing.merge("wrote" => [])
24
21
  when "show-principle" then members(required_id(id)).merge("wrote" => [])
25
22
  else unknown(command)
@@ -34,22 +31,6 @@ module Principles
34
31
 
35
32
  private
36
33
 
37
- #: () -> untyped
38
- def list_candidate_files
39
- found = @project.candidate_files.within_budget { |inventory| candidate_files_result(inventory).text.bytesize }
40
- candidate_files_result(found)
41
- end
42
-
43
- # list-candidate-files' result for one inventory, as it prints.
44
- #: (Models::CandidateInventory) -> Views::JsonWithEntriesOnLines
45
- def candidate_files_result(found)
46
- listed = Views::CandidateFilesResult::Found.new(inventory: found.to_h, untracked: found.untracked,
47
- owner_asks: found.owner_asks)
48
- question = Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
49
- map_file: @principles.file("ID"))
50
- Views::JsonWithEntriesOnLines.new(question.merge("wrote" => []), under: "inventory", key: "files")
51
- end
52
-
53
34
  #: (String) -> untyped
54
35
  def members(id)
55
36
  principle = @principles.find(id)
@@ -129,7 +110,7 @@ module Principles
129
110
  #: (String) -> Hash[String, untyped]
130
111
  def entry(id)
131
112
  map = @principles.find(id)
132
- row = { "id" => id, "description" => map.description, "members_by_freshness" => members_by_freshness(map) }
113
+ row = map.description_with_id.merge("members_by_freshness" => members_by_freshness(map))
133
114
  row = row.merge(read_result.no_members(@principles.file(id))) if map.unstarted?
134
115
  row.merge(waiting_on_an_upgrade(id)&.marker || {})
135
116
  rescue Error => e
@@ -15,7 +15,7 @@ module Principles
15
15
  # Each command and the method that runs it.
16
16
  COMMANDS = {
17
17
  "create-principle" => :create_principle, "change-description" => :change_description,
18
- "change-activation" => :change_activation
18
+ "change-activation" => :change_activation, "remove-principle" => :remove_principle
19
19
  }.freeze #: Hash[String, Symbol]
20
20
 
21
21
  #: (String, String?, Hash[String, untyped]) -> untyped
@@ -28,6 +28,14 @@ module Principles
28
28
 
29
29
  private
30
30
 
31
+ #: (String, Hash[String, untyped]) -> Hash[String, untyped]
32
+ def remove_principle(id, options)
33
+ map = @principles.find(id)
34
+ @audit_records.refuse_map_removal(id, confirmed: options["confirm"] == true)
35
+ file = @principles.remove(map)
36
+ map_result.removed(id, file: file)
37
+ end
38
+
31
39
  #: (String, Hash[String, untyped]) -> untyped
32
40
  def create_principle(id, options)
33
41
  map = @principles.create(id) { text(options["description"], "--description") }
@@ -0,0 +1,65 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/member"
6
+ require_relative "../models/members_in_consecutive_sections"
7
+ require_relative "../models/member_loading_scopes"
8
+ require_relative "../views/map_added_to"
9
+ require_relative "../views/consecutive_sections_elsewhere"
10
+ require_relative "../views/new_loading_scope"
11
+
12
+ module Principles
13
+ module Controllers
14
+ # A located new member and its before-save map, with reminder facts captured before the map is written.
15
+ class MemberAddition < Command
16
+ #: (Models::Project, tool: RunningTool, map: Models::Principle, member: Hash[String, untyped]) -> void
17
+ def initialize(project, tool:, map:, member:)
18
+ super(project, tool: tool)
19
+ @map = map
20
+ @member = Models::Member.new(member) #: Models::Member
21
+ @joined = joined #: Views::MapAddedTo
22
+ end
23
+
24
+ # Locate and report the added member after the caller saved exactly its new map.
25
+ #: (Views::PrintedPrinciple, added_to: Models::Principle) -> Hash[String, untyped]
26
+ def printed(principle, added_to:)
27
+ added = located_member
28
+ shared = lines_shared(@member, @map)
29
+ joined = joined_for(added_to)
30
+ sections = Models::MembersInConsecutiveSections.new(@project, @member).elsewhere(except: @map.id)
31
+ consecutive = Views::ConsecutiveSectionsElsewhere.new(sections)
32
+ map_result.member_added(principle, added: added, shared: shared, joined: joined, consecutive: consecutive)
33
+ end
34
+
35
+ private
36
+
37
+ # The updated map's after-save context, keeping the reminder facts captured before the write.
38
+ #: (Models::Principle) -> Views::MapAddedTo
39
+ def joined_for(added_to)
40
+ no_completed = @audit_records.known_no_completed_audit?(@map.id)
41
+ joined = @joined.with_completeness_question(
42
+ asks: added_to.members.asks_about_completeness?(no_completed_audit: no_completed)
43
+ )
44
+ scopes = Models::MemberLoadingScopes.new(@project.member_loads(added_to.members))
45
+ joined.with_loading_scope(Views::NewLoadingScope.new(scopes.introduced_by(@member.id)))
46
+ end
47
+
48
+ # The new member's id, current lines and stored check, located only after its map was saved.
49
+ #: () -> Hash[String, untyped]
50
+ def located_member
51
+ { "id" => @member.id }.merge(snapshot(@member.locator).slice("first_line", "last_line"))
52
+ .merge(@member.to_h.slice("check"))
53
+ end
54
+
55
+ # The history must inspect the old map before the write, so a batch repeats its reminders only once.
56
+ #: () -> Views::MapAddedTo
57
+ def joined
58
+ history = principle_history(@map.id)
59
+ Views::MapAddedTo.new(keeps_others_held: @map.keeps_others_held?,
60
+ correction_may_be_open: history.startable_at_head?,
61
+ reminded: history.first_add_since_commit?(@map))
62
+ end
63
+ end
64
+ end
65
+ end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
+ require_relative "member_addition"
5
6
 
6
7
  module Principles
7
8
  # Each runs one command: reads models, applies their rules and prints through a view.
@@ -48,33 +49,14 @@ module Principles
48
49
  started = !@principles.mapped?(id)
49
50
  map = @principles.addable(id)
50
51
  member = located(options, { "path" => text(options["path"], "PATH") }).merge(played(options))
51
- facts = joined(map)
52
- write_map(map.adding(member)) do |printed|
53
- added = member_added(printed, map, member, facts)
52
+ addition = handed(MemberAddition, map: map, member: member)
53
+ updated = map.adding(member)
54
+ write_map(updated) do |printed|
55
+ added = addition.printed(printed, added_to: updated)
54
56
  started ? added.merge(map_result.map_created(printed)) : added
55
57
  end
56
58
  end
57
59
 
58
- # What add-member reports of the member it added to map: its id, lines and check, and the members, in
59
- # this map or another, that share a line with it, so the agent sees an edit there shows on each (#383), and,
60
- # when a correction may be open on map, how a fix claims the member (D72, #1023).
61
- #: (Views::PrintedPrinciple, Models::Principle, Hash[String, untyped], Views::MapAddedTo) -> Hash[String, untyped]
62
- def member_added(printed, map, member, joined)
63
- added = Models::Member.new(member)
64
- map_result.member_added(printed, added: span(member).merge(member.slice("check")),
65
- shared: lines_shared(added, map), joined: joined)
66
- end
67
-
68
- # What add-member says of map, read before the member joins it and the map is saved, so the history can say
69
- # whether this is the first add-member since the map was last committed (#1025).
70
- #: (Models::Principle) -> Views::MapAddedTo
71
- def joined(map)
72
- history = principle_history(map.id)
73
- Views::MapAddedTo.new(keeps_others_held: map.keeps_others_held?,
74
- correction_may_be_open: history.startable_at_head?,
75
- reminded: history.first_add_since_commit?(map))
76
- end
77
-
78
60
  # The part a new member plays, and the check that enforces it when one is named (D30).
79
61
  #: (Hash[String, untyped]) -> Hash[String, untyped]
80
62
  def played(options)
@@ -153,7 +135,7 @@ module Principles
153
135
  LOCATION_OPTIONS.each { |key, flag| member[key] = text(options[key], flag) if options[key] }
154
136
  place = Models::Member.new(member)
155
137
  place.check_location
156
- snapshot(place.locator)
138
+ @project.locate_for_authoring(place.locator)
157
139
  member
158
140
  end
159
141
  end