principles 0.0.1 → 0.0.4
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/cli.rb +7 -1
- data/lib/principles/command_line.rb +12 -29
- data/lib/principles/controllers/acknowledgement.rb +4 -4
- data/lib/principles/controllers/answer.rb +64 -100
- data/lib/principles/controllers/assessment.rb +108 -0
- data/lib/principles/controllers/audit.rb +29 -135
- data/lib/principles/controllers/audit_completion.rb +2 -4
- data/lib/principles/controllers/command.rb +27 -13
- data/lib/principles/controllers/correction.rb +4 -4
- data/lib/principles/controllers/full_audit_request.rb +180 -0
- data/lib/principles/controllers/inventory.rb +32 -70
- data/lib/principles/controllers/mapping.rb +3 -3
- data/lib/principles/controllers/member_entries.rb +24 -12
- data/lib/principles/controllers/member_problems_report.rb +72 -0
- data/lib/principles/controllers/members_a_commit_changed.rb +10 -2
- data/lib/principles/controllers/members_to_assess.rb +16 -9
- data/lib/principles/controllers/meta_principle_setup.rb +5 -5
- data/lib/principles/controllers/repoint.rb +1 -1
- data/lib/principles/controllers/running_tool.rb +1 -1
- data/lib/principles/data/audit_files.rb +11 -7
- data/lib/principles/data/bounded_file.rb +11 -0
- data/lib/principles/data/command-steps.json +7 -6
- data/lib/principles/data/map_files.rb +2 -2
- data/lib/principles/data/principles_subfolder.rb +8 -1
- data/lib/principles/data/project_files.rb +1 -7
- data/lib/principles/data/project_root.rb +48 -0
- data/lib/principles/data/schema_check.rb +23 -5
- data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
- data/lib/principles/data/schemas/audit-record.schema.json +3 -0
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
- data/lib/principles/invocation_options.rb +1 -1
- data/lib/principles/models/assessment_answer.rb +64 -17
- data/lib/principles/models/audit.rb +24 -15
- data/lib/principles/models/audit_record.rb +10 -3
- data/lib/principles/models/audit_records.rb +74 -4
- data/lib/principles/models/audit_start.rb +3 -3
- data/lib/principles/models/carried_assessments.rb +1 -1
- data/lib/principles/models/check_since_last_audit.rb +6 -6
- data/lib/principles/models/correction_basis.rb +1 -1
- data/lib/principles/models/decided_prior_findings.rb +9 -19
- data/lib/principles/models/declared_map_changes.rb +8 -8
- data/lib/principles/models/disposition.rb +28 -24
- data/lib/principles/models/evidence_replacements.rb +8 -1
- data/lib/principles/models/fix_only_fields.rb +67 -0
- data/lib/principles/models/kept_prior_finding.rb +12 -7
- data/lib/principles/models/loaded_files.rb +5 -3
- data/lib/principles/models/loading_decision.rb +9 -2
- data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
- data/lib/principles/models/member.rb +1 -1
- data/lib/principles/models/member_assessments.rb +48 -3
- data/lib/principles/models/member_grounds.rb +2 -2
- data/lib/principles/models/member_hashes_as_written.rb +40 -0
- data/lib/principles/models/member_moves.rb +3 -3
- data/lib/principles/models/member_problems.rb +38 -18
- data/lib/principles/models/members_sharing_lines.rb +3 -3
- data/lib/principles/models/new_findings.rb +55 -0
- data/lib/principles/models/open_finding.rb +23 -13
- data/lib/principles/models/other_principles.rb +1 -1
- data/lib/principles/models/other_templates_placeholders.rb +74 -0
- data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
- data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
- data/lib/principles/models/{map_members.rb → principle_members.rb} +4 -4
- data/lib/principles/models/prior_decision_fields.rb +46 -0
- data/lib/principles/models/prior_finding_decision.rb +24 -3
- data/lib/principles/models/prior_finding_outcomes.rb +10 -3
- data/lib/principles/models/prior_findings.rb +1 -1
- data/lib/principles/models/problem_report.rb +7 -3
- data/lib/principles/models/project.rb +27 -13
- data/lib/principles/models/project_history.rb +2 -2
- data/lib/principles/models/recent_decision.rb +90 -0
- data/lib/principles/models/record_format.rb +105 -0
- data/lib/principles/models/recorded_finding.rb +4 -0
- data/lib/principles/models/recorded_hashes.rb +39 -0
- data/lib/principles/models/recorded_members.rb +17 -12
- data/lib/principles/models/reported_check.rb +63 -11
- data/lib/principles/models/request_id.rb +24 -4
- data/lib/principles/models/sent_prior_decisions.rb +31 -0
- data/lib/principles/models/still_holds_restatement.rb +7 -10
- data/lib/principles/models/template_placeholders.rb +41 -0
- data/lib/principles/session_start_options.rb +29 -0
- data/lib/principles/start_audit_options.rb +37 -0
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/answer_head.rb +29 -0
- data/lib/principles/views/assessed_members.rb +96 -0
- data/lib/principles/views/assessment_request.rb +51 -49
- data/lib/principles/views/audit_result.rb +38 -42
- data/lib/principles/views/check_result_template.rb +31 -10
- data/lib/principles/views/correction_request.rb +64 -0
- data/lib/principles/views/first_audit.rb +71 -0
- data/lib/principles/views/help.rb +3 -2
- data/lib/principles/views/loads_to_check_result.rb +11 -4
- data/lib/principles/views/map_added_to.rb +31 -0
- data/lib/principles/views/map_result.rb +37 -22
- data/lib/principles/views/members_a_commit_changed.rb +30 -10
- data/lib/principles/views/meta_principle_result.rb +3 -14
- data/lib/principles/views/principle_read_result.rb +27 -10
- data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
- data/lib/principles/views/prior_findings_result.rb +7 -3
- data/lib/principles/views/problem_lines.rb +14 -11
- data/lib/principles/views/problem_result.rb +30 -16
- data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +3 -2
- data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
- data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
- data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +22 -20
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +8 -5
- data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +3 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +6 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +2 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +37 -37
- data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
- data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +1 -0
- data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
- data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +2 -1
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
- data/lib/principles/views/request_part.rb +14 -2
- data/lib/principles/views/request_parts.rb +4 -0
- metadata +33 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96ca8d7922a17170882557d15e04abea9f3bea70aab25a22f50bdd9c9125011e
|
|
4
|
+
data.tar.gz: cf55a17d354871a0db2753cce1073594e934438b6f8d1927580490923f29219e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc665678840f9e2623292feec10931656a3408e493cce68832e7d68cdbffebdae9fe227191bac8a439b0dd1f9df68da62cc0b7106e498d3f3a54faf6471a2f3e
|
|
7
|
+
data.tar.gz: 3bf529373932b7ef4230d417d9b6bb10fe78f7fff3152c1648b5f291f94312dfcc9776d08567424e7cbe49602d390c105cc9a19056b74f776adf4d25742582ab
|
data/lib/principles/cli.rb
CHANGED
|
@@ -64,11 +64,17 @@ module Principles
|
|
|
64
64
|
options = line.command_options
|
|
65
65
|
# One byte past the limit is enough for the answer's own check to refuse it as too large.
|
|
66
66
|
options["stdin"] = @stdin.read(Data::BoundedFile::LIMIT + 1).to_s if options["file"] == "-"
|
|
67
|
-
project =
|
|
67
|
+
project = selected_project(line)
|
|
68
68
|
CommandRoutes::CONTROLLERS.fetch(command).new(project, tool: running_tool)
|
|
69
69
|
.call(command, line.id, options)
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
#: (CommandLine) -> Models::Project
|
|
73
|
+
def selected_project(line)
|
|
74
|
+
root = line.option("project")
|
|
75
|
+
line.project_given? ? Models::Project.at(root) : Models::Project.containing(root)
|
|
76
|
+
end
|
|
77
|
+
|
|
72
78
|
# The JSON object an agent reads for a failure that is not one of this tool's refusals.
|
|
73
79
|
#: (StandardError) -> Hash[untyped, untyped]
|
|
74
80
|
def refusal(error)
|
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
require "optparse"
|
|
5
5
|
require_relative "invocation_options"
|
|
6
6
|
require_relative "after_commit_hook_options"
|
|
7
|
+
require_relative "session_start_options"
|
|
8
|
+
require_relative "start_audit_options"
|
|
7
9
|
require_relative "models/command_steps"
|
|
8
10
|
|
|
9
11
|
module Principles
|
|
10
12
|
# One invocation's words: the command, its positional arguments and its options, refused with an
|
|
11
13
|
# OptionParser error when they do not fit what the command takes. CLI decides what to run from it.
|
|
12
14
|
class CommandLine
|
|
13
|
-
# The sources Claude Code's SessionStart hook names, which list-open-findings --short --session-start takes (#717).
|
|
14
|
-
SESSION_STARTS = %w[startup clear compact].freeze #: Array[String]
|
|
15
|
-
|
|
16
15
|
# argv is parsed at once; positional names each command's positional arguments, in order; executable is the
|
|
17
16
|
# invocation a refusal tells the agent to run --help with (#562).
|
|
18
17
|
#: (Array[String], positional: Hash[String, Array[String]], executable: String) -> void
|
|
@@ -50,6 +49,10 @@ module Principles
|
|
|
50
49
|
@options.value(name)
|
|
51
50
|
end
|
|
52
51
|
|
|
52
|
+
# Explicit selection defines a project even when it names the current directory.
|
|
53
|
+
#: () -> bool
|
|
54
|
+
def project_given? = @options.given.include?("project")
|
|
55
|
+
|
|
53
56
|
# The command named first; nil when none is, and refused when this tool has no such command.
|
|
54
57
|
#: () -> String?
|
|
55
58
|
def command
|
|
@@ -67,9 +70,7 @@ module Principles
|
|
|
67
70
|
check_arguments(name)
|
|
68
71
|
check_options(name)
|
|
69
72
|
check_values_are_not_options(name)
|
|
70
|
-
|
|
71
|
-
check_hook_report(name)
|
|
72
|
-
check_audit_kind(name)
|
|
73
|
+
check_combined_options(name)
|
|
73
74
|
return unless %w[submit-answer show-answer-check].include?(name) && !@options.value("file")
|
|
74
75
|
|
|
75
76
|
raise OptionParser::MissingArgument, "#{name} needs --file FILE, or --file - for stdin"
|
|
@@ -140,33 +141,15 @@ module Principles
|
|
|
140
141
|
end
|
|
141
142
|
end
|
|
142
143
|
|
|
143
|
-
#
|
|
144
|
+
# 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 refused.
|
|
144
146
|
#: (String) -> void
|
|
145
|
-
def
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
raise UsageRefusal.new("--session-start takes startup, clear or compact, not #{start}", help_repair(name))
|
|
149
|
-
end
|
|
150
|
-
return if @options.value("short")
|
|
151
|
-
|
|
152
|
-
raise UsageRefusal.new("--session-start words only the --short line", help_repair(name))
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
# --commits-after and --hook-event ask together for the after-commit hook's JSON, which --short's lines are not.
|
|
156
|
-
#: (String) -> void
|
|
157
|
-
def check_hook_report(name)
|
|
158
|
-
fault = AfterCommitHookOptions.new(@options).fault or return
|
|
147
|
+
def check_combined_options(name)
|
|
148
|
+
sets = [SessionStartOptions.new(@options), AfterCommitHookOptions.new(@options), StartAuditOptions.new(@options)]
|
|
149
|
+
fault = sets.filter_map(&:fault).first or return
|
|
159
150
|
raise UsageRefusal.new(fault, help_repair(name))
|
|
160
151
|
end
|
|
161
152
|
|
|
162
|
-
# --member and --write-ups each ask start-audit for a different audit, so only one may be given (#760).
|
|
163
|
-
#: (String) -> void
|
|
164
|
-
def check_audit_kind(name)
|
|
165
|
-
return unless @options.value("member") && @options.value("write_ups")
|
|
166
|
-
|
|
167
|
-
raise UsageRefusal.new("--member and --write-ups each start a different audit; give one", help_repair(name))
|
|
168
|
-
end
|
|
169
|
-
|
|
170
153
|
# Parses argv's options; an option no command defines fails here, before the command is checked, and is
|
|
171
154
|
# repaired with the help of the command argv names, or left to CLI's general advice when it names none.
|
|
172
155
|
#: (Array[String]) -> void
|
|
@@ -73,8 +73,8 @@ module Principles
|
|
|
73
73
|
# lines there and now, which the answer's quotes are checked against (#379).
|
|
74
74
|
#: (String, Models::Acknowledgement, Models::Member) -> [Models::Placement, Models::MemberLines]
|
|
75
75
|
def since_baseline(id, acknowledgement, member)
|
|
76
|
-
placements =
|
|
77
|
-
|
|
76
|
+
placements = principle_history(id).placements_since(acknowledgement.last_judged_commit, member.key,
|
|
77
|
+
@principles.find(id).member(member.id))
|
|
78
78
|
baseline = acknowledgement.baseline(placements)
|
|
79
79
|
lines = @project.member_lines(member.locator, since: baseline.commit, then_locator: baseline.locator)
|
|
80
80
|
[baseline, acknowledgement.compared(lines)]
|
|
@@ -82,8 +82,8 @@ module Principles
|
|
|
82
82
|
|
|
83
83
|
#: (String, String) -> [Models::Acknowledgement, Models::Member, String?]
|
|
84
84
|
def prepared(id, member_id)
|
|
85
|
-
member = Models::Member.new(@
|
|
86
|
-
base = @history.base_commit(id, [@
|
|
85
|
+
member = Models::Member.new(@principles.find(id).member(member_id))
|
|
86
|
+
base = @history.base_commit(id, [@principles.file(id), member.path])
|
|
87
87
|
now = @project.locate(member.locator).fetch("sha256")
|
|
88
88
|
[Models::Acknowledgement.new(principle_id: id, member: member, record: @audit_records.find(id), base: base,
|
|
89
89
|
now_sha256: now), member, base]
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require "time"
|
|
5
4
|
require_relative "command"
|
|
6
5
|
require_relative "../models/finding_write_ups"
|
|
7
6
|
require_relative "../models/audit"
|
|
@@ -9,7 +8,9 @@ require_relative "../models/request_id"
|
|
|
9
8
|
require_relative "acknowledgement"
|
|
10
9
|
require_relative "correction"
|
|
11
10
|
require_relative "repoint"
|
|
12
|
-
require_relative "
|
|
11
|
+
require_relative "assessment"
|
|
12
|
+
require_relative "full_audit_request"
|
|
13
|
+
require_relative "../models/other_templates_placeholders"
|
|
13
14
|
|
|
14
15
|
module Principles
|
|
15
16
|
# Each runs one command: reads models, applies their rules and prints through a view.
|
|
@@ -23,9 +24,9 @@ module Principles
|
|
|
23
24
|
def call(command, id, options)
|
|
24
25
|
naming_the_executable do
|
|
25
26
|
case command
|
|
26
|
-
when "submit-answer" then submit_answer(required_id(id), submitted(required_id(id), options))
|
|
27
|
+
when "submit-answer" then submit_answer(required_id(id), *submitted(required_id(id), options))
|
|
27
28
|
when "show-answer-check"
|
|
28
|
-
check_answer(required_id(id), submitted(required_id(id), options), options.fetch("file"))
|
|
29
|
+
check_answer(required_id(id), *submitted(required_id(id), options), options.fetch("file"))
|
|
29
30
|
else unknown(command)
|
|
30
31
|
end
|
|
31
32
|
end
|
|
@@ -34,32 +35,72 @@ module Principles
|
|
|
34
35
|
private
|
|
35
36
|
|
|
36
37
|
# The answer from --file, where - means it was read from stdin, checked against the schema for the phase
|
|
37
|
-
# the request id names
|
|
38
|
-
|
|
38
|
+
# the request id names once its head says it answers a request that still matches the project, with the prior
|
|
39
|
+
# findings a full audit's request listed, which checking its head found (#1052).
|
|
40
|
+
#: (String, Hash[String, untyped]) -> [untyped, Models::PriorFindings?]
|
|
39
41
|
def submitted(request_text, options)
|
|
40
|
-
|
|
42
|
+
request_id = Models::RequestId.parse(request_text)
|
|
43
|
+
prior = nil #: Models::PriorFindings?
|
|
44
|
+
response = @project.answer(options.fetch("file"), stdin: options["stdin"], phase: request_id.phase) do |head|
|
|
45
|
+
prior = checked_head(request_id, head)
|
|
46
|
+
printed_placeholders(request_id)
|
|
47
|
+
end
|
|
48
|
+
[response, prior]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Refuses an answer from its head alone: a record a later copy wrote is refused first, read afresh as
|
|
52
|
+
# start-audit reads it, so nothing is written over one that landed mid-audit (D85), then an answer to another
|
|
53
|
+
# request. Only an assessment's request is checked against the project here, since its template prints
|
|
54
|
+
# placeholders this release's schema could otherwise refuse first; it gives the prior findings it listed (#1052).
|
|
55
|
+
#: (Models::RequestId, Hash[String, untyped]) -> Models::PriorFindings?
|
|
56
|
+
def checked_head(request_id, head)
|
|
57
|
+
@audit_records.refuse_newer(request_id.principle_id, version: @tool.version)
|
|
58
|
+
request_id.check_answer(head)
|
|
59
|
+
return unless request_id.phase == "assessment"
|
|
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
|
+
)
|
|
41
75
|
end
|
|
42
76
|
|
|
43
77
|
# Accepts the answer and writes the record changes it makes.
|
|
44
|
-
#: (String, untyped) -> untyped
|
|
45
|
-
def submit_answer(request_text, response)
|
|
46
|
-
output, changes = judged(request_text, response)
|
|
78
|
+
#: (String, untyped, Models::PriorFindings?) -> untyped
|
|
79
|
+
def submit_answer(request_text, response, prior)
|
|
80
|
+
output, changes = judged(request_text, response, prior)
|
|
47
81
|
wrote = changes.map { |record| @audit_records.save(record) }
|
|
48
82
|
audit_result.present(output).merge("wrote" => wrote)
|
|
49
83
|
end
|
|
50
84
|
|
|
51
85
|
# Runs every check submit-answer would, and says what it would write, writing nothing; its submit command
|
|
52
|
-
# gives answer_file, the --file value it was checked from, again.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
86
|
+
# gives answer_file, the --file value it was checked from, again. An assessment with findings also gives the
|
|
87
|
+
# correction's answer it leads to, to fill (D81 step 3).
|
|
88
|
+
#: (String, untyped, Models::PriorFindings?, String) -> untyped
|
|
89
|
+
def check_answer(request_text, response, prior, answer_file)
|
|
90
|
+
output, changes = judged(request_text, response, prior)
|
|
91
|
+
audit_result.with_correction_to_fill(acceptable(request_text, response, answer_file, changes), output)
|
|
92
|
+
.merge("wrote" => [])
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The answer passed every check: what submitting it would write, and its submit command.
|
|
96
|
+
#: (String, untyped, String, Array[Models::AuditRecord]) -> Hash[String, untyped]
|
|
97
|
+
def acceptable(request_text, response, answer_file, changes)
|
|
56
98
|
written_up = Models::FindingWriteUps.of(@project, changes).written_up
|
|
57
99
|
# Only a correction's fixed dispositions claim map entries; for any other answer this is empty, read from
|
|
58
100
|
# no map, and left out.
|
|
59
101
|
audit_result.acceptable(request_text, changes.map { |record| @audit_records.file(record.principle_id) },
|
|
60
102
|
answer_file:, open_findings_will_print: (written_up unless written_up.empty?),
|
|
61
103
|
map_entry_changes: claimed_map_entry_changes(request_text, response))
|
|
62
|
-
.merge("wrote" => [])
|
|
63
104
|
end
|
|
64
105
|
|
|
65
106
|
# What each map entry a correction's fix claims changed, from the map its audit started from; its audit is
|
|
@@ -69,15 +110,17 @@ module Principles
|
|
|
69
110
|
handed(Correction).map_entry_changes(response) { audit(Models::RequestId.parse(request_text).principle_id) }
|
|
70
111
|
end
|
|
71
112
|
|
|
72
|
-
# The result of answering, and each record change the answer makes, not yet written
|
|
73
|
-
|
|
74
|
-
|
|
113
|
+
# The result of answering, and each record change the answer makes, not yet written; every phase changes only
|
|
114
|
+
# the request's own principle's record (D85). prior is what checking a full audit's assessment request found.
|
|
115
|
+
#: (String, untyped, Models::PriorFindings?) -> [untyped, Array[Models::AuditRecord]]
|
|
116
|
+
def judged(request_text, response, prior)
|
|
75
117
|
request_id = Models::RequestId.parse(request_text)
|
|
76
|
-
request_id.check_answer(response)
|
|
77
118
|
case request_id.phase
|
|
78
119
|
when "acknowledgement" then handed(Acknowledgement).answered(request_id, response)
|
|
79
120
|
when "repointing" then handed(Repoint).answered(request_id, response)
|
|
80
|
-
when "assessment"
|
|
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)
|
|
81
124
|
else handed(Correction).answered(request_id, response, audit(request_id.principle_id))
|
|
82
125
|
end
|
|
83
126
|
end
|
|
@@ -85,88 +128,9 @@ module Principles
|
|
|
85
128
|
# The audit of principle id, against its members' hashes now.
|
|
86
129
|
#: (String) -> Models::Audit
|
|
87
130
|
def audit(id)
|
|
88
|
-
map = @
|
|
131
|
+
map = @principles.find(id)
|
|
89
132
|
Models::Audit.new(map: map, now: @project.snapshots(map).hashes)
|
|
90
133
|
end
|
|
91
|
-
|
|
92
|
-
#: (Models::RequestId, untyped, Models::Audit) -> [untyped, Array[Models::AuditRecord]]
|
|
93
|
-
def answer_assessment(request_id, response, audit)
|
|
94
|
-
basis = Models::AssessmentBasis.new(response.fetch("basis"))
|
|
95
|
-
judged_against = record_judged_against(audit)
|
|
96
|
-
prior = checked_request(request_id, basis, audit, judged_against.loads)
|
|
97
|
-
basis.printed_after.refusing_stale_first(audit.id, @audit_records.find(audit.id)) do
|
|
98
|
-
judged_assessment(response, audit, prior, judged_against, basis)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# The assessment's fields and its decisions on the prior findings checked, then the audit completed or its
|
|
103
|
-
# correction asked for.
|
|
104
|
-
#: (untyped, Models::Audit, Models::PriorFindings, Models::RecordJudgedAgainst, Models::AssessmentBasis)
|
|
105
|
-
#| -> [untyped, Array[Models::AuditRecord]]
|
|
106
|
-
def judged_assessment(response, audit, prior, judged_against, basis)
|
|
107
|
-
assessed = audit.assessment(response, judged_against, Time.now.utc.iso8601) do |locator|
|
|
108
|
-
snapshot(locator)
|
|
109
|
-
end
|
|
110
|
-
findings = assessed.findings
|
|
111
|
-
decided = prior.decided(response["prior_finding_decisions"], findings, records: @audit_records) do |locator|
|
|
112
|
-
snapshot(locator)
|
|
113
|
-
end
|
|
114
|
-
correction(audit.assessed_start(basis.base, assessed, grounds(audit)), audit, findings, decided, basis)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# The request an assessment answers, checked against the project now, with the prior findings it listed.
|
|
118
|
-
#: (Models::RequestId, Models::AssessmentBasis, Models::Audit, Models::LoadsToCheck) -> Models::PriorFindings
|
|
119
|
-
def checked_request(request_id, basis, audit, loads)
|
|
120
|
-
audit.check_assessment_request(request_id, basis: basis, committed: committed(basis.base, audit.map),
|
|
121
|
-
record: @audit_records.find(audit.id), loads: loads)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Completes an audit with no findings. Otherwise asks the agent to correct them. Each is refused once the last
|
|
125
|
-
# completed record changed after the assessment's request was printed, the completion unless it writes
|
|
126
|
-
# nothing (D50).
|
|
127
|
-
#: (Models::AuditStart, Models::Audit, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
|
|
128
|
-
#| -> [untyped, Array[Models::AuditRecord]]
|
|
129
|
-
def correction(start, audit, findings, decided, assessed)
|
|
130
|
-
if findings.empty?
|
|
131
|
-
return handed(AuditCompletion, replacing: assessed.printed_after).completed(start, audit, [], [], decided)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
correction_request(start, audit, findings, decided, assessed)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# The correction request for findings, and outside git the open record that keeps what the audit began from.
|
|
138
|
-
# It is refused before it is printed once the last completed record changed, so no fix is made for an audit
|
|
139
|
-
# that cannot complete (D50). The check results travel in the basis, so the completed record keeps them (D30).
|
|
140
|
-
#: (Models::AuditStart, Models::Audit, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
|
|
141
|
-
#| -> [untyped, Array[Models::AuditRecord]]
|
|
142
|
-
def correction_request(start, audit, findings, decided, assessed)
|
|
143
|
-
assessed.printed_after.confirm_unchanged(audit.id, @audit_records.find(audit.id))
|
|
144
|
-
basis = printed_basis(start, findings, decided, assessed)
|
|
145
|
-
[audit_result.correction_request(request_id: basis.request_id(audit.id, audit.now).to_s,
|
|
146
|
-
principle_id: audit.id, findings: findings, basis: basis.to_h,
|
|
147
|
-
placeholders: Models::Disposition::PLACEHOLDERS),
|
|
148
|
-
open_record_changes(start, audit, basis.to_h)]
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# The basis a correction request prints, for the agent to hand back with its answer.
|
|
152
|
-
# Its revision is the one the assessment was printed after, carried forward, so the correction is refused once
|
|
153
|
-
# that record changes (#646, D50).
|
|
154
|
-
#: (Models::AuditStart, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
|
|
155
|
-
#| -> Models::CorrectionBasis
|
|
156
|
-
def printed_basis(start, findings, decided, assessed)
|
|
157
|
-
Models::CorrectionBasis.printed(start, findings: findings, prior: decided, revision: assessed.revision)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# Outside git, the open record that keeps what the audit began from, and the last completed record, so a
|
|
161
|
-
# restarted audit still lists its prior findings (D35); in git, nothing.
|
|
162
|
-
#: (Models::AuditStart, Models::Audit, Hash[String, untyped]) -> Array[Models::AuditRecord]
|
|
163
|
-
def open_record_changes(start, audit, basis)
|
|
164
|
-
return [] if start.base
|
|
165
|
-
|
|
166
|
-
last = @audit_records.find(audit.id)&.last_completed
|
|
167
|
-
record = handed(AuditCompletion).record(start, basis.fetch("findings"), "open", audit.now, last)
|
|
168
|
-
@audit_records.changes(record)
|
|
169
|
-
end
|
|
170
134
|
end
|
|
171
135
|
end
|
|
172
136
|
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "time"
|
|
5
|
+
require_relative "command"
|
|
6
|
+
require_relative "../models/audit"
|
|
7
|
+
require_relative "../models/request_id"
|
|
8
|
+
require_relative "audit_completion"
|
|
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
|
+
# A full audit's assessment, which submit-answer and show-answer-check hand over: this tool checks the request
|
|
15
|
+
# it answers and each member's assessment, then completes an audit with no findings or asks for the correction
|
|
16
|
+
# of its findings (D35, D50).
|
|
17
|
+
class Assessment < Command
|
|
18
|
+
# The result of answering an assessment request whose request checked_request found unchanged, with the prior
|
|
19
|
+
# findings it listed, and the record change it makes, not yet written.
|
|
20
|
+
#: (untyped, Models::Audit, Models::PriorFindings) -> [untyped, Array[Models::AuditRecord]]
|
|
21
|
+
def answered(response, audit, prior)
|
|
22
|
+
basis = Models::AssessmentBasis.new(response.fetch("basis"))
|
|
23
|
+
judged_against = record_judged_against(audit)
|
|
24
|
+
basis.printed_after.refusing_stale_first(audit.id, @audit_records.find(audit.id)) do
|
|
25
|
+
judged_assessment(response, audit, prior, judged_against, basis)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# The prior findings the request an answer's head names listed, refused when that request, given the head's
|
|
30
|
+
# basis, no longer matches the project, before the rest of the answer's shape is read (#1052).
|
|
31
|
+
#: (Models::RequestId, Hash[String, untyped], Models::Audit) -> Models::PriorFindings
|
|
32
|
+
def checked_request(request_id, head, audit)
|
|
33
|
+
basis = Models::AssessmentBasis.new(head.fetch("basis"))
|
|
34
|
+
audit.check_assessment_request(request_id, basis: basis, committed: committed(basis.base, audit.map),
|
|
35
|
+
record: @audit_records.find(audit.id), loads: loads_to_check(audit))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
# The assessment's fields and its decisions on the prior findings checked, then the audit completed or its
|
|
41
|
+
# correction asked for.
|
|
42
|
+
#: (untyped, Models::Audit, Models::PriorFindings, Models::RecordJudgedAgainst, Models::AssessmentBasis)
|
|
43
|
+
#| -> [untyped, Array[Models::AuditRecord]]
|
|
44
|
+
def judged_assessment(response, audit, prior, judged_against, basis)
|
|
45
|
+
assessed = audit.assessment(response, judged_against, Time.now.utc.iso8601) do |locator|
|
|
46
|
+
snapshot(locator)
|
|
47
|
+
end
|
|
48
|
+
findings = assessed.findings
|
|
49
|
+
decided = prior.decided(response["prior_finding_decisions"], findings, records: @audit_records) do |locator|
|
|
50
|
+
snapshot(locator)
|
|
51
|
+
end
|
|
52
|
+
correction(audit.assessed_start(basis.base, assessed, grounds(audit)), audit, findings, decided, basis)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Completes an audit with no findings. Otherwise asks the agent to correct them. Each is refused once the last
|
|
56
|
+
# completed record changed after the assessment's request was printed, the completion unless it writes
|
|
57
|
+
# nothing (D50).
|
|
58
|
+
#: (Models::AuditStart, Models::Audit, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
|
|
59
|
+
#| -> [untyped, Array[Models::AuditRecord]]
|
|
60
|
+
def correction(start, audit, findings, decided, assessed)
|
|
61
|
+
if findings.empty?
|
|
62
|
+
return handed(AuditCompletion, replacing: assessed.printed_after).completed(start, audit, [], [], decided)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
correction_request(start, audit, findings, decided, assessed)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# The correction request for findings, and outside git the open record that keeps what the audit began from.
|
|
69
|
+
# It is refused before it is printed once the last completed record changed, so no fix is made for an audit
|
|
70
|
+
# that cannot complete (D50). The check results travel in the basis, so the completed record keeps them (D30).
|
|
71
|
+
#: (Models::AuditStart, Models::Audit, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
|
|
72
|
+
#| -> [untyped, Array[Models::AuditRecord]]
|
|
73
|
+
def correction_request(start, audit, findings, decided, assessed)
|
|
74
|
+
assessed.printed_after.confirm_unchanged(audit.id, @audit_records.find(audit.id))
|
|
75
|
+
basis = printed_basis(start, findings, decided, assessed)
|
|
76
|
+
[request_to_correct(basis, audit, findings), open_record_changes(start, audit, basis.to_h)]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# The correction request for findings, answered under an id that digests its basis and the members now.
|
|
80
|
+
#: (Models::CorrectionBasis, Models::Audit, Array[untyped]) -> Views::CorrectionRequest
|
|
81
|
+
def request_to_correct(basis, audit, findings)
|
|
82
|
+
head = Views::AnswerHead.new(request_id: basis.request_id(audit.id, audit.now).to_s, basis: basis.to_h)
|
|
83
|
+
Views::CorrectionRequest.new(head: head, principle_id: audit.id, findings: findings,
|
|
84
|
+
placeholders: Models::Disposition::TEMPLATE_PLACEHOLDERS)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# The basis a correction request prints, for the agent to hand back with its answer.
|
|
88
|
+
# Its revision is the one the assessment was printed after, carried forward, so the correction is refused once
|
|
89
|
+
# that record changes (#646, D50).
|
|
90
|
+
#: (Models::AuditStart, Array[untyped], Models::DecidedPriorFindings, Models::AssessmentBasis)
|
|
91
|
+
#| -> Models::CorrectionBasis
|
|
92
|
+
def printed_basis(start, findings, decided, assessed)
|
|
93
|
+
Models::CorrectionBasis.printed(start, findings: findings, prior: decided, revision: assessed.revision)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Outside git, the open record that keeps what the audit began from, and the last completed record, so a
|
|
97
|
+
# restarted audit still lists its prior findings (D35); in git, nothing.
|
|
98
|
+
#: (Models::AuditStart, Models::Audit, Hash[String, untyped]) -> Array[Models::AuditRecord]
|
|
99
|
+
def open_record_changes(start, audit, basis)
|
|
100
|
+
return [] if start.base
|
|
101
|
+
|
|
102
|
+
last = @audit_records.find(audit.id)&.last_completed
|
|
103
|
+
record = handed(AuditCompletion).record(start, basis.fetch("findings"), "open", audit.now, last)
|
|
104
|
+
@audit_records.changes(record)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|