principles 0.0.4 → 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.
- checksums.yaml +4 -4
- data/lib/principles/after_commit_hook_options.rb +4 -1
- data/lib/principles/cli.rb +3 -1
- data/lib/principles/command_line.rb +38 -26
- data/lib/principles/command_routes.rb +11 -4
- data/lib/principles/controllers/acknowledgement.rb +93 -17
- data/lib/principles/controllers/answer.rb +45 -76
- data/lib/principles/controllers/answer_phase.rb +54 -0
- data/lib/principles/controllers/assessment.rb +46 -11
- data/lib/principles/controllers/audit.rb +17 -6
- data/lib/principles/controllers/audit_completion.rb +9 -5
- data/lib/principles/controllers/command.rb +5 -4
- data/lib/principles/controllers/correction.rb +22 -10
- data/lib/principles/controllers/full_audit_request.rb +11 -1
- data/lib/principles/controllers/guidance_search_paths.rb +31 -0
- data/lib/principles/controllers/inventory.rb +15 -29
- data/lib/principles/controllers/mapping.rb +9 -1
- data/lib/principles/controllers/member_addition.rb +65 -0
- data/lib/principles/controllers/member_entries.rb +6 -24
- data/lib/principles/controllers/member_problems_report.rb +13 -6
- data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
- data/lib/principles/controllers/members_to_assess.rb +21 -13
- data/lib/principles/controllers/meta_principle_setup.rb +1 -1
- data/lib/principles/controllers/repoint.rb +22 -23
- data/lib/principles/controllers/survey.rb +60 -0
- data/lib/principles/data/audit_files.rb +4 -0
- data/lib/principles/data/bounded_file.rb +9 -4
- data/lib/principles/data/candidate_files_found.rb +48 -13
- data/lib/principles/data/command-steps.json +85 -24
- data/lib/principles/data/committed_tree.rb +84 -0
- data/lib/principles/data/first_parent_log.rb +48 -0
- data/lib/principles/data/first_parent_range.rb +122 -0
- data/lib/principles/data/git_command.rb +37 -0
- data/lib/principles/data/guidance_search_paths_file.rb +107 -0
- data/lib/principles/data/map_files.rb +35 -10
- data/lib/principles/data/principles_directory.rb +40 -0
- data/lib/principles/data/principles_subfolder.rb +39 -16
- data/lib/principles/data/project_files.rb +22 -11
- data/lib/principles/data/repository.rb +55 -29
- data/lib/principles/data/requested_candidate_files.rb +43 -0
- data/lib/principles/data/running_version.rb +3 -5
- data/lib/principles/data/schema_check.rb +16 -6
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +18 -5
- data/lib/principles/data/schemas/answer-guide.schema.json +255 -68
- data/lib/principles/data/schemas/audit-record.schema.json +10 -1
- data/lib/principles/data/schemas/command-steps.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
- data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
- data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
- data/lib/principles/data/verified_head.rb +162 -0
- data/lib/principles/invocation_options.rb +3 -3
- data/lib/principles/models/acknowledgement.rb +95 -84
- data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
- data/lib/principles/models/acknowledgement_refusal.rb +90 -0
- data/lib/principles/models/answer_place.rb +4 -0
- data/lib/principles/models/assessment_answer.rb +0 -45
- data/lib/principles/models/assessment_left_as_printed.rb +81 -0
- data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
- data/lib/principles/models/audit_record.rb +12 -16
- data/lib/principles/models/audit_records.rb +52 -23
- data/lib/principles/models/candidate_files.rb +44 -10
- data/lib/principles/models/candidate_inventory.rb +69 -8
- data/lib/principles/models/candidate_outline.rb +195 -0
- data/lib/principles/models/captured_head.rb +72 -0
- data/lib/principles/models/carried_member.rb +42 -0
- data/lib/principles/models/check_since_last_audit.rb +20 -11
- data/lib/principles/models/command_steps.rb +17 -1
- data/lib/principles/models/declared_map_changes.rb +29 -12
- data/lib/principles/models/declared_member_removals.rb +75 -0
- data/lib/principles/models/disposition.rb +4 -2
- data/lib/principles/models/fix_only_fields.rb +12 -0
- data/lib/principles/models/frontmatter_fields.rb +9 -8
- data/lib/principles/models/guidance_search_path.rb +26 -0
- data/lib/principles/models/guidance_search_paths.rb +57 -0
- data/lib/principles/models/instruction_named.rb +35 -0
- data/lib/principles/models/left_as_printed.rb +39 -0
- data/lib/principles/models/line_span.rb +6 -0
- data/lib/principles/models/loaded_files.rb +1 -2
- data/lib/principles/models/loading_scope.rb +61 -0
- data/lib/principles/models/locator.rb +6 -0
- data/lib/principles/models/mapped_principles.rb +39 -37
- data/lib/principles/models/member_assessments.rb +9 -31
- data/lib/principles/models/member_file.rb +20 -47
- data/lib/principles/models/member_hashes_as_written.rb +10 -6
- data/lib/principles/models/member_history.rb +7 -5
- data/lib/principles/models/member_lines.rb +63 -15
- data/lib/principles/models/member_loading_scopes.rb +49 -0
- data/lib/principles/models/member_loads.rb +4 -0
- data/lib/principles/models/member_mapping_run.rb +30 -0
- data/lib/principles/models/member_moves.rb +4 -0
- data/lib/principles/models/member_problems.rb +63 -33
- data/lib/principles/models/member_region.rb +129 -0
- data/lib/principles/models/member_repair_moves.rb +52 -0
- data/lib/principles/models/member_snapshots.rb +14 -1
- data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
- data/lib/principles/models/meta_principle.rb +14 -0
- data/lib/principles/models/missing_files.rb +2 -2
- data/lib/principles/models/open_findings_elsewhere.rb +4 -0
- data/lib/principles/models/other_templates_placeholders.rb +81 -42
- data/lib/principles/models/outline_budget.rb +142 -0
- data/lib/principles/models/outline_group.rb +31 -0
- data/lib/principles/models/outline_section.rb +56 -0
- data/lib/principles/models/principle.rb +14 -7
- data/lib/principles/models/principle_file_revision.rb +48 -0
- data/lib/principles/models/principle_history.rb +46 -19
- data/lib/principles/models/principle_lineage.rb +118 -0
- data/lib/principles/models/principle_map_revision.rb +39 -0
- data/lib/principles/models/principle_mapping_history.rb +132 -0
- data/lib/principles/models/principle_members.rb +25 -0
- data/lib/principles/models/principle_predecessor.rb +45 -0
- data/lib/principles/models/principle_publication.rb +177 -0
- data/lib/principles/models/principle_revision.rb +104 -0
- data/lib/principles/models/prior_decision_fields.rb +3 -2
- data/lib/principles/models/prior_finding_decision.rb +14 -4
- data/lib/principles/models/problem_report.rb +17 -5
- data/lib/principles/models/project.rb +46 -39
- data/lib/principles/models/project_history.rb +45 -25
- data/lib/principles/models/quoted_change.rb +137 -0
- data/lib/principles/models/record_format.rb +12 -2
- data/lib/principles/models/recorded_entry.rb +6 -0
- data/lib/principles/models/recorded_hashes.rb +7 -3
- data/lib/principles/models/recorded_members.rb +27 -15
- data/lib/principles/models/refusal_before_shape.rb +21 -0
- data/lib/principles/models/repoint.rb +13 -0
- data/lib/principles/models/reported_check.rb +5 -14
- data/lib/principles/models/sent_answer.rb +61 -0
- data/lib/principles/models/shape_problems_beside.rb +40 -0
- data/lib/principles/models/submitted_answer.rb +34 -0
- data/lib/principles/models/survey_search_paths.rb +26 -0
- data/lib/principles/models/template_placeholders.rb +34 -4
- data/lib/principles/models/text_within.rb +55 -0
- data/lib/principles/models/unchecked_members.rb +76 -0
- data/lib/principles/models/uncommitted_files.rb +50 -0
- data/lib/principles/models/unknown_principle.rb +29 -0
- data/lib/principles/models/write_up_opening.rb +21 -4
- data/lib/principles/positional_arguments.rb +37 -0
- data/lib/principles/session_start_options.rb +2 -2
- data/lib/principles/start_audit_options.rb +19 -4
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +23 -11
- data/lib/principles/views/added_member.rb +41 -0
- data/lib/principles/views/answered_request.rb +21 -0
- data/lib/principles/views/assessed_members.rb +43 -10
- data/lib/principles/views/assessment_request.rb +91 -31
- data/lib/principles/views/audit_result.rb +40 -28
- data/lib/principles/views/candidate_files_result.rb +85 -19
- data/lib/principles/views/candidate_outlines_result.rb +25 -0
- data/lib/principles/views/check_notes.rb +44 -0
- data/lib/principles/views/check_result_template.rb +14 -23
- data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
- data/lib/principles/views/correction_request.rb +32 -1
- data/lib/principles/views/guidance_search_paths_result.rb +26 -0
- data/lib/principles/views/instruction.rb +74 -0
- data/lib/principles/views/json_with_entries_on_lines.rb +59 -0
- data/lib/principles/views/loads_to_check_result.rb +2 -2
- data/lib/principles/views/map_added_to.rb +56 -2
- data/lib/principles/views/map_result.rb +23 -43
- data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
- data/lib/principles/views/member_change_since_baseline.rb +23 -5
- data/lib/principles/views/member_repairs.rb +22 -52
- data/lib/principles/views/members_a_commit_changed.rb +16 -6
- data/lib/principles/views/new_loading_scope.rb +31 -0
- data/lib/principles/views/one_member_check_result_template.rb +47 -0
- data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
- data/lib/principles/views/open_findings_line.rb +77 -23
- data/lib/principles/views/principle_read_result.rb +24 -29
- data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
- data/lib/principles/views/prior_findings_result.rb +23 -15
- data/lib/principles/views/problem_lines.rb +3 -1
- data/lib/principles/views/problem_result.rb +8 -3
- data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
- data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -48
- data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
- data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
- data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
- data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
- data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
- data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +16 -3
- data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +11 -5
- data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
- data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +55 -7
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +9 -8
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
- data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +27 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
- data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
- data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
- data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
- data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
- data/lib/principles/views/request_part.rb +16 -8
- data/lib/principles/views/request_parts.rb +4 -0
- metadata +92 -7
- data/lib/principles/models/candidate_listing.rb +0 -32
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
- data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
- data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec72c7b217d3e48437dcdb1e8166654efe8b27fe3888d35d90eeeb31fcfa0c8c
|
|
4
|
+
data.tar.gz: b8de7786425d0a890ff2452b78b50b667e895e39fe45552c4d2e37c69a80a4c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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)
|
data/lib/principles/cli.rb
CHANGED
|
@@ -117,9 +117,11 @@ module Principles
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
# A result prints as JSON,
|
|
120
|
+
# A result prints as JSON, as JSON laid out with one entry a line, as list-candidate-files does, or as lines with
|
|
121
|
+
# their own exit status, as list-member-problems --short does.
|
|
121
122
|
#: (untyped) -> Integer
|
|
122
123
|
def printed_result(result)
|
|
124
|
+
return printed(visible(result.text)) if result.is_a?(Views::JsonWithEntriesOnLines)
|
|
123
125
|
return printed(visible(JSON.pretty_generate(result))) unless result.is_a?(Views::Lines)
|
|
124
126
|
|
|
125
127
|
@stdout.print(result.stdout)
|
|
@@ -7,11 +7,16 @@ require_relative "after_commit_hook_options"
|
|
|
7
7
|
require_relative "session_start_options"
|
|
8
8
|
require_relative "start_audit_options"
|
|
9
9
|
require_relative "models/command_steps"
|
|
10
|
+
require_relative "prose_list"
|
|
11
|
+
require_relative "positional_arguments"
|
|
10
12
|
|
|
11
13
|
module Principles
|
|
12
14
|
# One invocation's words: the command, its positional arguments and its options, refused with an
|
|
13
15
|
# OptionParser error when they do not fit what the command takes. CLI decides what to run from it.
|
|
14
16
|
class CommandLine
|
|
17
|
+
# How a refusal names each option a command requires.
|
|
18
|
+
REQUIRED_OPTION_WORDS = { "file" => "--file FILE, or --file - for stdin" }.freeze #: Hash[String, String]
|
|
19
|
+
|
|
15
20
|
# argv is parsed at once; positional names each command's positional arguments, in order; executable is the
|
|
16
21
|
# invocation a refusal tells the agent to run --help with (#562).
|
|
17
22
|
#: (Array[String], positional: Hash[String, Array[String]], executable: String) -> void
|
|
@@ -62,64 +67,65 @@ module Principles
|
|
|
62
67
|
raise OptionParser::InvalidArgument, "unknown command #{name}"
|
|
63
68
|
end
|
|
64
69
|
|
|
65
|
-
# Refuses
|
|
66
|
-
#
|
|
70
|
+
# Refuses every missing argument at once, too many arguments, an option the command does not take or given an
|
|
71
|
+
# option as its value.
|
|
67
72
|
#: () -> void
|
|
68
73
|
def check
|
|
69
74
|
name = command.to_s
|
|
75
|
+
check_missing(name)
|
|
70
76
|
check_arguments(name)
|
|
71
77
|
check_options(name)
|
|
72
78
|
check_values_are_not_options(name)
|
|
73
79
|
check_combined_options(name)
|
|
74
|
-
return unless %w[submit-answer show-answer-check].include?(name) && !@options.value("file")
|
|
75
|
-
|
|
76
|
-
raise OptionParser::MissingArgument, "#{name} needs --file FILE, or --file - for stdin"
|
|
77
80
|
end
|
|
78
81
|
|
|
79
82
|
# The principle id, for a command whose first argument is one.
|
|
80
83
|
#: () -> String?
|
|
81
84
|
def id
|
|
82
|
-
|
|
85
|
+
positionals.id
|
|
83
86
|
end
|
|
84
87
|
|
|
85
88
|
# The options, with every positional argument but the id under its name.
|
|
86
89
|
#: () -> Hash[String, untyped]
|
|
87
90
|
def command_options
|
|
88
|
-
|
|
89
|
-
all[name] = value unless %w[id id?].include?(name)
|
|
90
|
-
end
|
|
91
|
+
@options.to_h.merge(positionals.bindings)
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
private
|
|
94
95
|
|
|
95
|
-
#: () ->
|
|
96
|
-
def
|
|
97
|
-
|
|
96
|
+
#: () -> PositionalArguments
|
|
97
|
+
def positionals = PositionalArguments.new(@positional.fetch(command.to_s), @arguments.drop(1))
|
|
98
|
+
|
|
99
|
+
# Each argument the command needs and was not given, named in one refusal: an agent that met one refusal per
|
|
100
|
+
# missing argument repaired them one at a time (#1083). Each option command-steps.json says it requires is one.
|
|
101
|
+
#: (String) -> void
|
|
102
|
+
def check_missing(name)
|
|
103
|
+
missing = positionals.missing + missing_options(name)
|
|
104
|
+
return if missing.empty?
|
|
105
|
+
|
|
106
|
+
raise OptionParser::MissingArgument, "#{name} needs #{ProseList.new(missing)}"
|
|
98
107
|
end
|
|
99
108
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
# The options command name requires and was not given, as a refusal names them.
|
|
110
|
+
#: (String) -> Array[String]
|
|
111
|
+
def missing_options(name)
|
|
112
|
+
required = steps(name)&.requires || []
|
|
113
|
+
required.reject { |option| @options.value(option) }.map { |option| REQUIRED_OPTION_WORDS.fetch(option) }
|
|
103
114
|
end
|
|
104
115
|
|
|
116
|
+
# Too many arguments; check_missing has refused too few.
|
|
105
117
|
#: (String) -> void
|
|
106
118
|
def check_arguments(name)
|
|
107
|
-
return
|
|
119
|
+
return unless positionals.too_many?
|
|
108
120
|
|
|
109
|
-
takes = "#{name} takes #{
|
|
121
|
+
takes = "#{name} takes #{positionals.shown}".strip.sub(/ takes\z/, " takes no arguments")
|
|
110
122
|
raise OptionParser::InvalidArgument, takes
|
|
111
123
|
end
|
|
112
124
|
|
|
113
|
-
# The positional arguments as usage shows them; a name ending in ? is optional and shown in brackets.
|
|
114
|
-
#: () -> String
|
|
115
|
-
def shown_arguments
|
|
116
|
-
names.map { |each| each.end_with?("?") ? "[#{each.chomp("?").upcase}]" : each.upcase }.join(" ")
|
|
117
|
-
end
|
|
118
|
-
|
|
119
125
|
# An option a command does not take is refused, so a mistyped command never runs as something else.
|
|
120
126
|
#: (String) -> void
|
|
121
127
|
def check_options(name)
|
|
122
|
-
taken =
|
|
128
|
+
taken = steps(name)&.options || []
|
|
123
129
|
unknown = (@options.given - taken - ["project"]).map { |option| "--#{option}" }
|
|
124
130
|
return if unknown.empty?
|
|
125
131
|
|
|
@@ -142,10 +148,12 @@ module Principles
|
|
|
142
148
|
end
|
|
143
149
|
|
|
144
150
|
# Options checked together, each set owning what is wrong with it as given: --session-start (#717), the
|
|
145
|
-
# after-commit hook's pair (D73) and the audit start-audit begins (#760); the first fault is
|
|
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.
|
|
146
153
|
#: (String) -> void
|
|
147
154
|
def check_combined_options(name)
|
|
148
|
-
|
|
155
|
+
hook = (AfterCommitHookOptions.new(@options) if name == AfterCommitHookOptions::COMMAND)
|
|
156
|
+
sets = [SessionStartOptions.new(@options), hook, StartAuditOptions.new(@options)].compact
|
|
149
157
|
fault = sets.filter_map(&:fault).first or return
|
|
150
158
|
raise UsageRefusal.new(fault, help_repair(name))
|
|
151
159
|
end
|
|
@@ -165,6 +173,10 @@ module Principles
|
|
|
165
173
|
#: (Array[String]) -> String?
|
|
166
174
|
def named_command(argv) = argv.find { |word| @positional.key?(word) }
|
|
167
175
|
|
|
176
|
+
# What command-steps.json says of the command name, or nil for a name it does not list.
|
|
177
|
+
#: (String) -> Models::CommandSteps::Command?
|
|
178
|
+
def steps(name) = Models::CommandSteps.load.command(name)
|
|
179
|
+
|
|
168
180
|
#: (String) -> String
|
|
169
181
|
def help_repair(name) = "To see what it takes: #{@executable} #{name} --help"
|
|
170
182
|
end
|
|
@@ -2,6 +2,9 @@
|
|
|
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"
|
|
7
|
+
require_relative "controllers/member_problems_report"
|
|
5
8
|
require_relative "controllers/mapping"
|
|
6
9
|
require_relative "controllers/meta_principle_setup"
|
|
7
10
|
require_relative "controllers/member_entries"
|
|
@@ -30,14 +33,18 @@ module Principles
|
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
ROUTES = {
|
|
33
|
-
"list-candidate-files" => Route.new(Controllers::
|
|
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]),
|
|
34
40
|
"list-principles" => Route.new(Controllers::Inventory, []),
|
|
35
|
-
"list-member-problems" => Route.new(Controllers::
|
|
41
|
+
"list-member-problems" => Route.new(Controllers::MemberProblemsReport, %w[id?]),
|
|
36
42
|
"show-principle" => Route.new(Controllers::Inventory, %w[id]),
|
|
37
43
|
"show-audit" => Route.new(Controllers::Audit, %w[id]),
|
|
38
44
|
"list-open-findings" => Route.new(Controllers::Audit, %w[id?]),
|
|
39
45
|
"show-meta-principle-passage" => Route.new(Controllers::MetaPrincipleSetup, []),
|
|
40
46
|
"create-principle" => Route.new(Controllers::Mapping, %w[id]),
|
|
47
|
+
"remove-principle" => Route.new(Controllers::Mapping, %w[id]),
|
|
41
48
|
"change-description" => Route.new(Controllers::Mapping, %w[id]),
|
|
42
49
|
"change-activation" => Route.new(Controllers::Mapping, %w[id]),
|
|
43
50
|
"add-member" => Route.new(Controllers::MemberEntries, %w[id path]),
|
|
@@ -47,8 +54,8 @@ module Principles
|
|
|
47
54
|
"remove-member-check" => Route.new(Controllers::MemberEntries, %w[id member]),
|
|
48
55
|
"remove-member" => Route.new(Controllers::MemberEntries, %w[id member]),
|
|
49
56
|
"start-audit" => Route.new(Controllers::Audit, %w[id]),
|
|
50
|
-
"submit-answer" => Route.new(Controllers::Answer, %w[
|
|
51
|
-
"show-answer-check" => Route.new(Controllers::Answer, %w[
|
|
57
|
+
"submit-answer" => Route.new(Controllers::Answer, %w[request_id]),
|
|
58
|
+
"show-answer-check" => Route.new(Controllers::Answer, %w[request_id])
|
|
52
59
|
}.freeze #: Hash[String, Route]
|
|
53
60
|
|
|
54
61
|
# Each command's positional arguments, in order, as CommandLine takes them.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require "json"
|
|
4
5
|
require "time"
|
|
5
|
-
require_relative "
|
|
6
|
+
require_relative "answer_phase"
|
|
6
7
|
require_relative "../models/acknowledgement"
|
|
8
|
+
require_relative "../models/check_since_last_audit"
|
|
9
|
+
require_relative "../models/reported_check"
|
|
10
|
+
require_relative "../views/one_member_check_result_template"
|
|
7
11
|
require_relative "../views/acknowledgement_result"
|
|
8
12
|
|
|
9
13
|
module Principles
|
|
@@ -12,25 +16,36 @@ module Principles
|
|
|
12
16
|
module Controllers
|
|
13
17
|
# A one-member audit (D33): start-audit ID --member MEMBER asks whether a committed change keeps that member's
|
|
14
18
|
# meaning, and submit-answer moves its baseline in the audit record when the answer holds.
|
|
15
|
-
class Acknowledgement <
|
|
19
|
+
class Acknowledgement < AnswerPhase
|
|
16
20
|
# The request for principle id's member.
|
|
17
21
|
#: (String, String) -> Hash[String, untyped]
|
|
18
22
|
def start(id, member_id)
|
|
19
23
|
naming_the_executable(rerun: one_member_audit(id)) do
|
|
20
|
-
acknowledgement,
|
|
21
|
-
baseline, lines = since_baseline(id, acknowledgement, member)
|
|
22
|
-
change = Views::MemberChangeSinceBaseline.new(
|
|
23
|
-
member: shown(acknowledgement, member, baseline), member_lines: lines.shown,
|
|
24
|
-
commits: commits(acknowledgement, baseline, base), paths: acknowledgement.paths_since(baseline)
|
|
25
|
-
)
|
|
24
|
+
acknowledgement, change, check = asked(id, member_id)
|
|
26
25
|
view.request(request_id: acknowledgement.request_id.to_s, principle_id: id, change: change,
|
|
27
|
-
|
|
26
|
+
context: { **acknowledgement.open_findings, **instruction_for(check) },
|
|
27
|
+
placeholders: placeholders(check&.to_h, change))
|
|
28
|
+
.merge("wrote" => [])
|
|
28
29
|
end
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
# The
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
# The answer alone, as start-audit --member --as template prints it, to fill and submit under the request's id
|
|
33
|
+
# (#773).
|
|
34
|
+
#: (String, String) -> Hash[String, untyped]
|
|
35
|
+
def to_fill(id, member_id)
|
|
36
|
+
naming_the_executable(rerun: one_member_audit(id)) do
|
|
37
|
+
acknowledgement, change, check = asked(id, member_id)
|
|
38
|
+
view.answer_to_fill(request_id: acknowledgement.request_id.to_s, change: change,
|
|
39
|
+
placeholders: placeholders(check&.to_h, change))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The result of answering, and the record it changes, not yet written.
|
|
44
|
+
# @override
|
|
45
|
+
#: (Models::SubmittedAnswer) -> [Views::AnsweredRequest, Array[Models::AuditRecord]]
|
|
46
|
+
def answered(submitted)
|
|
47
|
+
request_id = submitted.request_id
|
|
48
|
+
response = submitted.response
|
|
34
49
|
id = request_id.principle_id
|
|
35
50
|
acknowledgement, member, = prepared(id, response.fetch("basis").fetch("member_id"))
|
|
36
51
|
stale(id, member.id) unless acknowledgement.request_id.to_s == request_id.to_s
|
|
@@ -38,8 +53,69 @@ module Principles
|
|
|
38
53
|
[accepted(id, acknowledgement, member, response)]]
|
|
39
54
|
end
|
|
40
55
|
|
|
56
|
+
# The refusals an answer meets before its shape: any phase's, then a placeholder its template printed left in,
|
|
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).
|
|
59
|
+
#: (Models::RequestId) -> Array[Models::RefusalBeforeShape]
|
|
60
|
+
def before_shape(request_id) = [*super, Models::Acknowledgement::LEFT_AS_PRINTED]
|
|
61
|
+
|
|
41
62
|
private
|
|
42
63
|
|
|
64
|
+
# The placeholders a one-member audit's template prints, which its answer may leave as printed: its own, and
|
|
65
|
+
# check_result's for a check the last audit ran, the only check it acknowledges (#1112). The member is in the
|
|
66
|
+
# answer, not the request id, so this names the check's whether the member has one.
|
|
67
|
+
# @override
|
|
68
|
+
#: (Models::RequestId) -> Hash[String, untyped]?
|
|
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
|
|
73
|
+
|
|
74
|
+
# The acknowledgement of principle id's member, its change since its baseline, as the request shows it, and the
|
|
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?]
|
|
78
|
+
def asked(id, member_id)
|
|
79
|
+
acknowledgement, member, base = prepared(id, member_id)
|
|
80
|
+
baseline, lines = since_baseline(id, acknowledgement, member)
|
|
81
|
+
check = check_template(id, member)
|
|
82
|
+
[acknowledgement,
|
|
83
|
+
Views::MemberChangeSinceBaseline.new(
|
|
84
|
+
member: shown(acknowledgement, member, baseline), member_lines: lines.shown(taken: bytes_of(check)),
|
|
85
|
+
first_changed_lines: acknowledgement.first_changed_lines(lines),
|
|
86
|
+
commits: commits(acknowledgement, baseline, base), paths: acknowledgement.paths_since(baseline)
|
|
87
|
+
), check]
|
|
88
|
+
end
|
|
89
|
+
|
|
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
|
|
98
|
+
|
|
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).
|
|
102
|
+
#: (Hash[String, untyped]?, ?Views::MemberChangeSinceBaseline?) -> Hash[String, untyped]
|
|
103
|
+
def placeholders(check_result, change = nil)
|
|
104
|
+
quotes = change&.first_changed_lines.to_h
|
|
105
|
+
{ **Models::Acknowledgement.placeholders_beside(quotes),
|
|
106
|
+
**(check_result ? { "check_result" => check_result } : {}) }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# The check_result a checked member's answer fills, for the check the last audit ran, which a one-member audit
|
|
110
|
+
# requires (D30, D63, #1071), asking for a passing run alone (#1112); nil for a member without a check.
|
|
111
|
+
#: (String, Models::Member) -> Views::OneMemberCheckResultTemplate?
|
|
112
|
+
def check_template(id, member)
|
|
113
|
+
checks = Models::CheckSinceLastAudit.new(principle_history: principle_history(id),
|
|
114
|
+
record: @audit_records.find(id))
|
|
115
|
+
Views::OneMemberCheckResultTemplate.for(checks.entry(member),
|
|
116
|
+
exit_status: Models::Acknowledgement::EXIT_STATUS_PLACEHOLDER)
|
|
117
|
+
end
|
|
118
|
+
|
|
43
119
|
# The one-member audit of principle id's member, as a refusal naming a near miss leads its repair with (D56).
|
|
44
120
|
#: (String) -> ^(String) -> String
|
|
45
121
|
def one_member_audit(id)
|
|
@@ -50,14 +126,15 @@ module Principles
|
|
|
50
126
|
#: (String, Models::Acknowledgement, Models::Member, untyped) -> Models::AuditRecord
|
|
51
127
|
def accepted(id, acknowledgement, member, response)
|
|
52
128
|
_baseline, lines = since_baseline(id, acknowledgement, member)
|
|
53
|
-
acknowledgement.accepted(response,
|
|
129
|
+
acknowledgement.accepted(response, lines, at: Time.now.utc.iso8601)
|
|
54
130
|
end
|
|
55
131
|
|
|
56
132
|
# The member as the request shows it, with where it was at its baseline when it has moved since (#547).
|
|
57
133
|
#: (Models::Acknowledgement, Models::Member, Models::Placement) -> Hash[String, untyped]
|
|
58
134
|
def shown(acknowledgement, member, baseline)
|
|
59
135
|
moved_from = acknowledgement.moved_from(baseline)
|
|
60
|
-
{ "id" => member.id, "role" => member.role, "
|
|
136
|
+
{ "id" => member.id, "role" => member.role, **(member.check ? { "check" => member.check } : {}),
|
|
137
|
+
"evidence" => [member.reference],
|
|
61
138
|
**(moved_from ? { "evidence_at_baseline" => [moved_from] } : {}) }
|
|
62
139
|
end
|
|
63
140
|
|
|
@@ -72,9 +149,8 @@ module Principles
|
|
|
72
149
|
# record vouches for, placed as that commit's map placed it or as it is placed now (#547, #550), and its own
|
|
73
150
|
# lines there and now, which the answer's quotes are checked against (#379).
|
|
74
151
|
#: (String, Models::Acknowledgement, Models::Member) -> [Models::Placement, Models::MemberLines]
|
|
75
|
-
def since_baseline(
|
|
76
|
-
placements =
|
|
77
|
-
@principles.find(id).member(member.id))
|
|
152
|
+
def since_baseline(_id, acknowledgement, member)
|
|
153
|
+
placements = acknowledgement.placements_in(@project)
|
|
78
154
|
baseline = acknowledgement.baseline(placements)
|
|
79
155
|
lines = @project.member_lines(member.locator, since: baseline.commit, then_locator: baseline.locator)
|
|
80
156
|
[baseline, acknowledgement.compared(lines)]
|
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative "command"
|
|
5
5
|
require_relative "../models/finding_write_ups"
|
|
6
|
-
require_relative "../models/audit"
|
|
7
6
|
require_relative "../models/request_id"
|
|
7
|
+
require_relative "../models/submitted_answer"
|
|
8
8
|
require_relative "acknowledgement"
|
|
9
9
|
require_relative "correction"
|
|
10
10
|
require_relative "repoint"
|
|
11
11
|
require_relative "assessment"
|
|
12
|
-
require_relative "full_audit_request"
|
|
13
|
-
require_relative "../models/other_templates_placeholders"
|
|
14
12
|
|
|
15
13
|
module Principles
|
|
16
14
|
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
@@ -20,13 +18,18 @@ module Principles
|
|
|
20
18
|
# audit completes, writes the committed audit record. Nothing else is stored: each request id is a
|
|
21
19
|
# digest of what the request depends on, so an answer is checked against the project as it is now (D25).
|
|
22
20
|
class Answer < Command
|
|
21
|
+
# The controller that answers for each phase a request id may name.
|
|
22
|
+
PHASE_CONTROLLERS = {
|
|
23
|
+
"assessment" => Assessment, "correction" => Correction, "acknowledgement" => Acknowledgement,
|
|
24
|
+
"repointing" => Repoint
|
|
25
|
+
}.freeze #: Hash[String, Class[AnswerPhase]]
|
|
26
|
+
|
|
23
27
|
#: (String, String?, Hash[String, untyped]) -> untyped
|
|
24
|
-
def call(command,
|
|
28
|
+
def call(command, _id, options)
|
|
25
29
|
naming_the_executable do
|
|
26
30
|
case command
|
|
27
|
-
when "submit-answer" then submit_answer(
|
|
28
|
-
when "show-answer-check"
|
|
29
|
-
check_answer(required_id(id), *submitted(required_id(id), options), options.fetch("file"))
|
|
31
|
+
when "submit-answer" then submit_answer(submitted(options), options.fetch("file"))
|
|
32
|
+
when "show-answer-check" then check_answer(submitted(options), options.fetch("file"))
|
|
30
33
|
else unknown(command)
|
|
31
34
|
end
|
|
32
35
|
end
|
|
@@ -34,103 +37,69 @@ module Principles
|
|
|
34
37
|
|
|
35
38
|
private
|
|
36
39
|
|
|
37
|
-
# The answer from --file, where - means it was read from stdin,
|
|
38
|
-
# the
|
|
39
|
-
# findings a full audit's request listed, which checking its head found (#1052).
|
|
40
|
-
#: (
|
|
41
|
-
def submitted(
|
|
42
|
-
request_id = Models::RequestId.parse(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
printed_placeholders(request_id)
|
|
47
|
-
end
|
|
48
|
-
[response, prior]
|
|
40
|
+
# The answer from --file, where - means it was read from stdin, to the request REQUEST_ID names, checked against
|
|
41
|
+
# the schema for the phase that id names once its head says it answers a request that still matches the project,
|
|
42
|
+
# with the prior findings a full audit's request listed, which checking its head found (#1052).
|
|
43
|
+
#: (Hash[String, untyped]) -> Models::SubmittedAnswer
|
|
44
|
+
def submitted(options)
|
|
45
|
+
request_id = Models::RequestId.parse(options.fetch("request_id"))
|
|
46
|
+
sent = @project.answer(options.fetch("file"), stdin: options["stdin"], phase: request_id.phase)
|
|
47
|
+
prior = checked_head(request_id, sent.head)
|
|
48
|
+
Models::SubmittedAnswer.new(request_id, sent.checked(phase(request_id).before_shape(request_id)), prior)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Refuses an answer from its head alone: a record a later copy wrote is refused first, read afresh as
|
|
52
52
|
# start-audit reads it, so nothing is written over one that landed mid-audit (D85), then an answer to another
|
|
53
|
-
# request
|
|
54
|
-
# placeholders this release's schema could otherwise refuse first; it gives the prior findings it listed (#1052).
|
|
53
|
+
# request, then whatever the phase checks of its request from the head alone (#1052).
|
|
55
54
|
#: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings?
|
|
56
55
|
def checked_head(request_id, head)
|
|
57
56
|
@audit_records.refuse_newer(request_id.principle_id, version: @tool.version)
|
|
58
57
|
request_id.check_answer(head)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
handed(Assessment).checked_request(request_id, head, audit(request_id.principle_id))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# The placeholders the template of the request request_id names printed, which its answer may leave as
|
|
65
|
-
# printed: a full audit's as start-audit --as template prints it now, a correction's from its dispositions'
|
|
66
|
-
# placeholders; any other phase's template prints none (#1084).
|
|
67
|
-
#: (Models::RequestId) -> Models::OtherTemplatesPlaceholders
|
|
68
|
-
def printed_placeholders(request_id)
|
|
69
|
-
Models::OtherTemplatesPlaceholders.besides(
|
|
70
|
-
case request_id.phase
|
|
71
|
-
when "assessment" then handed(FullAuditRequest, principle_id: request_id.principle_id).to_fill
|
|
72
|
-
when "correction" then Models::Disposition::TEMPLATE_PLACEHOLDERS
|
|
73
|
-
end
|
|
74
|
-
)
|
|
58
|
+
phase(request_id).checked_request(request_id, head)
|
|
75
59
|
end
|
|
76
60
|
|
|
77
61
|
# Accepts the answer and writes the record changes it makes.
|
|
78
|
-
#: (
|
|
79
|
-
def submit_answer(
|
|
80
|
-
output, changes = judged(
|
|
62
|
+
#: (Models::SubmittedAnswer, String) -> untyped
|
|
63
|
+
def submit_answer(submitted, answer_file)
|
|
64
|
+
output, changes = judged(submitted)
|
|
81
65
|
wrote = changes.map { |record| @audit_records.save(record) }
|
|
82
|
-
audit_result.present(output
|
|
66
|
+
audit_result.present(output, source_request_id: submitted.request_id.to_s,
|
|
67
|
+
answer_file: answer_file).merge("wrote" => wrote)
|
|
83
68
|
end
|
|
84
69
|
|
|
85
70
|
# Runs every check submit-answer would, and says what it would write, writing nothing; its submit command
|
|
86
71
|
# gives answer_file, the --file value it was checked from, again. An assessment with findings also gives the
|
|
87
72
|
# correction's answer it leads to, to fill (D81 step 3).
|
|
88
|
-
#: (
|
|
89
|
-
def check_answer(
|
|
90
|
-
output, changes = judged(
|
|
91
|
-
audit_result.with_correction_to_fill(acceptable(
|
|
92
|
-
|
|
73
|
+
#: (Models::SubmittedAnswer, String) -> untyped
|
|
74
|
+
def check_answer(submitted, answer_file)
|
|
75
|
+
output, changes = judged(submitted)
|
|
76
|
+
audit_result.with_correction_to_fill(acceptable(submitted, answer_file, changes), output,
|
|
77
|
+
answer_file: answer_file).merge("wrote" => [])
|
|
93
78
|
end
|
|
94
79
|
|
|
95
80
|
# The answer passed every check: what submitting it would write, and its submit command.
|
|
96
|
-
#: (
|
|
97
|
-
def acceptable(
|
|
81
|
+
#: (Models::SubmittedAnswer, String, Array[Models::AuditRecord]) -> Hash[String, untyped]
|
|
82
|
+
def acceptable(submitted, answer_file, changes)
|
|
98
83
|
written_up = Models::FindingWriteUps.of(@project, changes).written_up
|
|
99
84
|
# Only a correction's fixed dispositions claim map entries; for any other answer this is empty, read from
|
|
100
85
|
# no map, and left out.
|
|
101
|
-
audit_result.acceptable(
|
|
86
|
+
audit_result.acceptable(submitted.request_id.to_s,
|
|
87
|
+
changes.map { |record| @audit_records.file(record.principle_id) },
|
|
102
88
|
answer_file:, open_findings_will_print: (written_up unless written_up.empty?),
|
|
103
|
-
map_entry_changes: claimed_map_entry_changes(
|
|
89
|
+
map_entry_changes: claimed_map_entry_changes(submitted))
|
|
104
90
|
end
|
|
105
91
|
|
|
106
|
-
# What each map entry a
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def claimed_map_entry_changes(request_text, response)
|
|
110
|
-
handed(Correction).map_entry_changes(response) { audit(Models::RequestId.parse(request_text).principle_id) }
|
|
111
|
-
end
|
|
92
|
+
# What each map entry a fix in the answer claims changed, which only a correction's fixes claim.
|
|
93
|
+
#: (Models::SubmittedAnswer) -> Array[Hash[String, untyped]]
|
|
94
|
+
def claimed_map_entry_changes(submitted) = phase(submitted.request_id).map_entry_changes(submitted)
|
|
112
95
|
|
|
113
|
-
# The result of answering, and each record change the answer makes, not yet written
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def judged(request_text, response, prior)
|
|
117
|
-
request_id = Models::RequestId.parse(request_text)
|
|
118
|
-
case request_id.phase
|
|
119
|
-
when "acknowledgement" then handed(Acknowledgement).answered(request_id, response)
|
|
120
|
-
when "repointing" then handed(Repoint).answered(request_id, response)
|
|
121
|
-
when "assessment"
|
|
122
|
-
checked = prior or raise ArgumentError, "an assessment's prior findings come from checking its head"
|
|
123
|
-
handed(Assessment).answered(response, audit(request_id.principle_id), checked)
|
|
124
|
-
else handed(Correction).answered(request_id, response, audit(request_id.principle_id))
|
|
125
|
-
end
|
|
126
|
-
end
|
|
96
|
+
# The result of answering, and each record change the answer makes, not yet written (D85).
|
|
97
|
+
#: (Models::SubmittedAnswer) -> [untyped, Array[Models::AuditRecord]]
|
|
98
|
+
def judged(submitted) = phase(submitted.request_id).answered(submitted)
|
|
127
99
|
|
|
128
|
-
# The
|
|
129
|
-
#: (
|
|
130
|
-
def
|
|
131
|
-
map = @principles.find(id)
|
|
132
|
-
Models::Audit.new(map: map, now: @project.snapshots(map).hashes)
|
|
133
|
-
end
|
|
100
|
+
# The controller of the phase request_id names, which answers for it.
|
|
101
|
+
#: (Models::RequestId) -> AnswerPhase
|
|
102
|
+
def phase(request_id) = handed(PHASE_CONTROLLERS.fetch(request_id.phase))
|
|
134
103
|
end
|
|
135
104
|
end
|
|
136
105
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "command"
|
|
5
|
+
require_relative "../models/audit"
|
|
6
|
+
require_relative "../models/other_templates_placeholders"
|
|
7
|
+
require_relative "../models/refusal_before_shape"
|
|
8
|
+
require_relative "../models/submitted_answer"
|
|
9
|
+
|
|
10
|
+
module Principles
|
|
11
|
+
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
12
|
+
# controllers/CLAUDE.md owns the boundary.
|
|
13
|
+
module Controllers
|
|
14
|
+
# What every phase of an audit shares in answering its request, which submit-answer and show-answer-check hand
|
|
15
|
+
# over: each phase's controller answers for itself, so Answer never asks which phase it holds.
|
|
16
|
+
# @abstract
|
|
17
|
+
class AnswerPhase < Command
|
|
18
|
+
# The result of answering, and each record change the answer makes, not yet written; every phase changes only
|
|
19
|
+
# the request's own principle's record (D85). Sorbet refuses a phase that does not define it, and takes an
|
|
20
|
+
# abstract method only with a forwarding super for its body, which RuboCop would otherwise call useless.
|
|
21
|
+
# @abstract
|
|
22
|
+
#: (Models::SubmittedAnswer) -> [untyped, Array[Models::AuditRecord]]
|
|
23
|
+
def answered(submitted) = super # rubocop:disable Lint/UselessMethodDefinition
|
|
24
|
+
|
|
25
|
+
# The prior findings the request an answer's head names listed, once the phase has checked that request from
|
|
26
|
+
# the head alone: none, unless the phase lists some.
|
|
27
|
+
#: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings?
|
|
28
|
+
def checked_request(_request_id, _head) = nil
|
|
29
|
+
|
|
30
|
+
# What each map entry a fix in the answer claims changed, which only a correction's fixes claim.
|
|
31
|
+
#: (Models::SubmittedAnswer) -> Array[Hash[String, untyped]]
|
|
32
|
+
def map_entry_changes(_submitted) = []
|
|
33
|
+
|
|
34
|
+
# The refusals an answer to the request request_id names meets before its shape, in order; any phase's is a
|
|
35
|
+
# placeholder its template did not print (#1084).
|
|
36
|
+
#: (Models::RequestId) -> Array[Models::RefusalBeforeShape]
|
|
37
|
+
def before_shape(request_id) = [Models::OtherTemplatesPlaceholders.besides(printed_placeholders(request_id))]
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# The placeholders the template of the request request_id names printed, which its answer may leave as
|
|
42
|
+
# printed: none, unless the phase's template prints some.
|
|
43
|
+
#: (Models::RequestId) -> Hash[String, untyped]?
|
|
44
|
+
def printed_placeholders(_request_id) = nil
|
|
45
|
+
|
|
46
|
+
# The audit of principle id, against its members' hashes now.
|
|
47
|
+
#: (String) -> Models::Audit
|
|
48
|
+
def audit_now(id)
|
|
49
|
+
map = @principles.find(id)
|
|
50
|
+
Models::Audit.new(map: map, now: @project.snapshots(map).hashes)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|