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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "../data/project_files"
|
|
5
|
+
require_relative "../data/project_root"
|
|
5
6
|
require_relative "../data/schema_check"
|
|
6
7
|
require_relative "../data/map_files"
|
|
7
8
|
require_relative "../data/audit_files"
|
|
@@ -16,13 +17,14 @@ require_relative "loaded_files"
|
|
|
16
17
|
require_relative "located_text"
|
|
17
18
|
require_relative "member_loads"
|
|
18
19
|
require_relative "member_lines"
|
|
19
|
-
require_relative "
|
|
20
|
+
require_relative "mapped_principles"
|
|
20
21
|
require_relative "member_snapshots"
|
|
21
22
|
require_relative "missing_files"
|
|
22
23
|
require_relative "locate_refusal"
|
|
23
24
|
require_relative "audit_records"
|
|
24
25
|
require_relative "project_history"
|
|
25
26
|
require_relative "principles_folder_move"
|
|
27
|
+
require_relative "other_templates_placeholders"
|
|
26
28
|
|
|
27
29
|
module Principles
|
|
28
30
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -32,6 +34,10 @@ module Principles
|
|
|
32
34
|
# project only through this model. It is handed its four data adapters, so a spec can hand it stand-ins
|
|
33
35
|
# that meet the same contracts (#337).
|
|
34
36
|
class Project
|
|
37
|
+
# An implicit invocation reuses its nearest established project; an explicit root uses .at directly.
|
|
38
|
+
#: (String) -> Project
|
|
39
|
+
def self.containing(directory) = at(Data::ProjectRoot.new(directory).path)
|
|
40
|
+
|
|
35
41
|
# The project at root, with its maps, audit records and history.
|
|
36
42
|
#: (String) -> Project
|
|
37
43
|
def self.at(root)
|
|
@@ -56,10 +62,10 @@ module Principles
|
|
|
56
62
|
@files.root
|
|
57
63
|
end
|
|
58
64
|
|
|
59
|
-
#: () ->
|
|
60
|
-
def
|
|
65
|
+
#: () -> MappedPrinciples
|
|
66
|
+
def principles
|
|
61
67
|
refuse_unmoved_folder
|
|
62
|
-
|
|
68
|
+
MappedPrinciples.new(@maps)
|
|
63
69
|
end
|
|
64
70
|
|
|
65
71
|
#: () -> AuditRecords
|
|
@@ -114,7 +120,7 @@ module Principles
|
|
|
114
120
|
|
|
115
121
|
# Each of map's members by id, where it is in its file now and the hash of what it says there. It is
|
|
116
122
|
# refused once, listing every member that cannot be found or read, so the agent repairs them together.
|
|
117
|
-
#: (
|
|
123
|
+
#: (Principle) -> MemberSnapshots
|
|
118
124
|
def snapshots(map)
|
|
119
125
|
broken = [] #: Array[Hash[String, untyped]]
|
|
120
126
|
found = map.members.to_h do |member|
|
|
@@ -137,7 +143,7 @@ module Principles
|
|
|
137
143
|
end
|
|
138
144
|
|
|
139
145
|
# Each member's hash now by key, or the refusal that says why its text cannot be found or read.
|
|
140
|
-
#: (
|
|
146
|
+
#: (PrincipleMembers) -> Hash[String, untyped]
|
|
141
147
|
def current_by_key(members)
|
|
142
148
|
members.to_h do |member|
|
|
143
149
|
[member.key, locate(member.locator).fetch("sha256")]
|
|
@@ -166,13 +172,13 @@ module Principles
|
|
|
166
172
|
|
|
167
173
|
# Each member's MemberLoads by id: when each host loads it into context, with the size of what loads, and
|
|
168
174
|
# the project hooks whose commands name its file, read once for them all unless the caller already read them.
|
|
169
|
-
#: (
|
|
175
|
+
#: (PrincipleMembers, ?HookCommands) -> Hash[String, MemberLoads]
|
|
170
176
|
def member_loads(members, hooks = hook_commands)
|
|
171
177
|
members.to_h { |member| [member.id, MemberLoads.read(@files, member.locator, hooks: hooks)] }
|
|
172
178
|
end
|
|
173
179
|
|
|
174
180
|
# The files members load, each read whole once, with the project's hooks as hooks read them (#483).
|
|
175
|
-
#: (
|
|
181
|
+
#: (PrincipleMembers, HookCommands) -> LoadedFiles
|
|
176
182
|
def loaded_files(members, hooks) = LoadedFiles.read(@files, members, hooks: hooks)
|
|
177
183
|
|
|
178
184
|
#: () -> HookCommands
|
|
@@ -187,13 +193,21 @@ module Principles
|
|
|
187
193
|
|
|
188
194
|
ANSWER_REPAIR = "Repair each field listed, starting from the request's response_template."
|
|
189
195
|
|
|
196
|
+
# The fields every answer hands back as its request printed them, which say whether it still answers that
|
|
197
|
+
# request (#990).
|
|
198
|
+
ANSWER_HEAD = %w[request_id basis].freeze
|
|
199
|
+
|
|
190
200
|
# An answer to a phase's request from file, where - means it was read from stdin, checked against the
|
|
191
|
-
# phase's answer schema (D29).
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
# phase's answer schema (D29). Its head is checked first, and handed to the block, which may refuse an answer
|
|
202
|
+
# to a request that no longer matches before the rest of its shape is read (#1052), and gives the placeholders
|
|
203
|
+
# that request's template printed, so every field holding another template's is refused next, whole (#1084).
|
|
204
|
+
#: (String, stdin: String?, phase: String) ?{ (Hash[String, untyped]) -> OtherTemplatesPlaceholders } -> untyped
|
|
205
|
+
def answer(file, stdin:, phase:, &)
|
|
194
206
|
parsed = file == "-" ? @files.parse_json(stdin.to_s, "-") : @files.read_json(file)
|
|
195
|
-
Data::SchemaCheck.new("#{phase}-answer")
|
|
196
|
-
|
|
207
|
+
check = Data::SchemaCheck.new("#{phase}-answer")
|
|
208
|
+
check.only(ANSWER_HEAD).checked(parsed, code: "invalid_answer", source: file, repair: ANSWER_REPAIR)
|
|
209
|
+
yield(parsed.slice(*ANSWER_HEAD)).refuse_in(parsed, file) if block_given?
|
|
210
|
+
check.checked(parsed, code: "invalid_answer", source: file, repair: ANSWER_REPAIR)
|
|
197
211
|
end
|
|
198
212
|
|
|
199
213
|
# What list-candidate-files found: the candidate files as it lists them, and which git does not track.
|
|
@@ -5,7 +5,7 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "../data/repository"
|
|
6
6
|
require_relative "../data/project_files"
|
|
7
7
|
require_relative "../data/principles_subfolder"
|
|
8
|
-
require_relative "
|
|
8
|
+
require_relative "principle_members"
|
|
9
9
|
require_relative "member"
|
|
10
10
|
require_relative "member_file"
|
|
11
11
|
require_relative "commits_brought_in"
|
|
@@ -109,7 +109,7 @@ module Principles
|
|
|
109
109
|
|
|
110
110
|
# Each member's id and the hash of its text at commit, or nil when commit lacks a member's file or the
|
|
111
111
|
# member's place in it.
|
|
112
|
-
#: (String,
|
|
112
|
+
#: (String, PrincipleMembers) -> Hash[String, String]?
|
|
113
113
|
def hashes_at(commit, members)
|
|
114
114
|
members.to_h do |member|
|
|
115
115
|
path = member.path
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "answer_fields"
|
|
6
|
+
require_relative "answer_place"
|
|
7
|
+
require_relative "template_placeholders"
|
|
8
|
+
|
|
9
|
+
module Principles
|
|
10
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
11
|
+
module Models
|
|
12
|
+
# The recent decision under a principle an assessment answer judges against its members' own words: either why
|
|
13
|
+
# none can be checked, or how one held up with pointers to where it is recorded. The record keeps none of it,
|
|
14
|
+
# but a completed audit asks to commit the files its evidence cites (#860).
|
|
15
|
+
class RecentDecision
|
|
16
|
+
# The placeholder start-audit --as template prints in each field of both forms, so the agent fills one form
|
|
17
|
+
# and leaves the other as printed, which is not giving it (#994).
|
|
18
|
+
PLACEHOLDERS = TemplatePlaceholders.new(
|
|
19
|
+
{
|
|
20
|
+
"unavailable_reason" => "Why no recent decision under this principle can be checked. Leave as printed " \
|
|
21
|
+
"to check one in assessment and evidence instead",
|
|
22
|
+
"assessment" => "To check a recent decision: how it held up against the members' own words. Leave as " \
|
|
23
|
+
"printed when unavailable_reason says why none can be checked",
|
|
24
|
+
"evidence" => "With assessment: pointers to where the decision is recorded, as [{\"path\": ..., " \
|
|
25
|
+
"\"heading\": ...}]. Leave as printed otherwise"
|
|
26
|
+
}
|
|
27
|
+
) #: TemplatePlaceholders
|
|
28
|
+
|
|
29
|
+
# decision is the answer's recent_decision as given; each field left as its placeholder is not given.
|
|
30
|
+
#: (Hash[String, untyped]) -> void
|
|
31
|
+
def initialize(decision)
|
|
32
|
+
@sent_any = !decision.empty? #: bool
|
|
33
|
+
@decision = PLACEHOLDERS.given(decision) #: Hash[String, untyped]
|
|
34
|
+
freeze
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Whether the decision as sent gives fields and leaves every one as the template printed it, so gives neither
|
|
38
|
+
# form (#1010).
|
|
39
|
+
#: () -> bool
|
|
40
|
+
def left_as_printed? = @sent_any && @decision.empty?
|
|
41
|
+
|
|
42
|
+
# Refuses the decision unless it gives a written reason none is available, or a written assessment with
|
|
43
|
+
# evidence that fields locates, and one giving neither form, or both, by naming both.
|
|
44
|
+
#: (AnswerFields) -> void
|
|
45
|
+
def check(fields)
|
|
46
|
+
one_form
|
|
47
|
+
if @decision["unavailable_reason"]
|
|
48
|
+
fields.text(@decision["unavailable_reason"], "recent_decision.unavailable_reason")
|
|
49
|
+
else
|
|
50
|
+
fields.text(@decision["assessment"], "recent_decision.assessment")
|
|
51
|
+
fields.evidence(@decision["evidence"], AnswerPlace.new("/recent_decision/evidence", "Recent decision"))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# The paths its evidence cites, each once; none when the decision was unavailable.
|
|
56
|
+
#: () -> Array[String]
|
|
57
|
+
def paths
|
|
58
|
+
return [] if @decision["unavailable_reason"]
|
|
59
|
+
|
|
60
|
+
@decision.fetch("evidence").map { |item| item.fetch("path") }.uniq
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# Refuses a decision that gives neither form, or both, whichever its fields show.
|
|
66
|
+
#: () -> void
|
|
67
|
+
def one_form
|
|
68
|
+
given = %w[unavailable_reason assessment].count { |field| @decision.key?(field) }
|
|
69
|
+
return if given == 1
|
|
70
|
+
|
|
71
|
+
given.zero? ? neither : both
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#: () -> bot
|
|
75
|
+
def both
|
|
76
|
+
raise Error.new("invalid_answer", "recent_decision gives both unavailable_reason and assessment",
|
|
77
|
+
"Keep one form: to check a decision, leave unavailable_reason as printed or remove it; when " \
|
|
78
|
+
"none can be checked, do the same with assessment and evidence.")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#: () -> bot
|
|
82
|
+
def neither
|
|
83
|
+
raise Error.new("invalid_answer", "recent_decision gives neither unavailable_reason nor assessment",
|
|
84
|
+
"Replace unavailable_reason's placeholder with why no recent decision under this principle " \
|
|
85
|
+
"can be checked, or replace assessment's and evidence's with how one held up and where it " \
|
|
86
|
+
"is recorded.")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require_relative "../error"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
9
|
+
module Models
|
|
10
|
+
# An audit record's format: the number a copy compares with the newest it writes and rewrites without losing a
|
|
11
|
+
# field, and the first release that wrote it, which a copy that does not know the format names as the update to
|
|
12
|
+
# make (D85). A record without a format is older than format 1. An open record outside git keeps the last
|
|
13
|
+
# completed one whole, so that one's format counts too.
|
|
14
|
+
class RecordFormat
|
|
15
|
+
# Raise NEWEST in the commit that adds a field an older copy would drop on a rewrite, and set FIRST_RELEASE by
|
|
16
|
+
# hand to the release that commit ships in.
|
|
17
|
+
NEWEST = 1
|
|
18
|
+
FIRST_RELEASE = "0.0.4"
|
|
19
|
+
FIELDS = %w[format format_first_release].freeze
|
|
20
|
+
|
|
21
|
+
#: (Hash[String, untyped]) -> void
|
|
22
|
+
def initialize(fields)
|
|
23
|
+
@fields = fields
|
|
24
|
+
freeze
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The record's fields as this copy writes them, its format and that format's first release ahead of the rest.
|
|
28
|
+
#: () -> Hash[String, untyped]
|
|
29
|
+
def stamped
|
|
30
|
+
{ "format" => NEWEST, "format_first_release" => FIRST_RELEASE, **@fields.except(*FIELDS) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Refuses a record whose format, or its kept last completed record's, is above NEWEST, before this copy, at
|
|
34
|
+
# version, rewrites it and drops what it does not know. file is the record's, relative to the project.
|
|
35
|
+
#: (String, version: String) -> void
|
|
36
|
+
def refuse_rewrite(file, version:)
|
|
37
|
+
format, release = newest_held
|
|
38
|
+
return unless format > NEWEST
|
|
39
|
+
|
|
40
|
+
refuse(file, "#{format}, first written by release #{release}; this copy, #{version}, rewrites up to " \
|
|
41
|
+
"format #{NEWEST}", update(release, version))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Refuses a record this copy's schema refused, when a later copy wrote it, so it is not reported as invalid.
|
|
45
|
+
# A read holds no version, so the repair names both ways to update (V3).
|
|
46
|
+
#: (String) -> void
|
|
47
|
+
def refuse_unreadable(file)
|
|
48
|
+
return unless newer?
|
|
49
|
+
|
|
50
|
+
refuse(file, "#{number}, first written by release #{first_release}; this copy reads up to format #{NEWEST}",
|
|
51
|
+
"#{update_either_way}, then run the command again.")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Whether a later copy wrote the record, at a format above NEWEST.
|
|
55
|
+
#: () -> bool
|
|
56
|
+
def newer? = number > NEWEST
|
|
57
|
+
|
|
58
|
+
# The highest format the record holds, its own or its kept last completed record's; 0 for none.
|
|
59
|
+
#: () -> Integer
|
|
60
|
+
def number = newest_held.first
|
|
61
|
+
|
|
62
|
+
# The first release that wrote that format.
|
|
63
|
+
#: () -> String
|
|
64
|
+
def first_release = newest_held.last
|
|
65
|
+
|
|
66
|
+
# How to update to read the record, whatever copy runs: what a read without the running version says (V3, V5).
|
|
67
|
+
#: () -> String
|
|
68
|
+
def update_either_way
|
|
69
|
+
"Update the principles plugin or gem to #{first_release} or later, or a checkout or archive of principles " \
|
|
70
|
+
"to a later commit"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
#: (String, String, String) -> bot
|
|
76
|
+
def refuse(file, format_stated, update)
|
|
77
|
+
raise Error.new("newer_audit_record", "#{file} is format #{format_stated}",
|
|
78
|
+
"#{update} Leave the record as it is: it is not broken.", file)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The highest format the record holds, with the release that first wrote it.
|
|
82
|
+
#: () -> [Integer, String]
|
|
83
|
+
def newest_held
|
|
84
|
+
kept = @fields["last_completed"]
|
|
85
|
+
[@fields, kept.is_a?(Hash) ? kept : {}].map do |fields|
|
|
86
|
+
[fields["format"].is_a?(Integer) ? fields["format"] : 0, fields["format_first_release"].to_s]
|
|
87
|
+
end.max_by(&:first) || [0, ""]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# What to update to read release's format: a published copy to that release, a development one, whose
|
|
91
|
+
# version is a prerelease, to a later commit; and a release above this copy's own may not be published yet.
|
|
92
|
+
#: (String, String) -> String
|
|
93
|
+
def update(release, version)
|
|
94
|
+
running = Gem::Version.new(version)
|
|
95
|
+
unpublished = Gem::Version.correct?(release) && Gem::Version.new(release) > running.release
|
|
96
|
+
how = if running.prerelease?
|
|
97
|
+
"Update this checkout or archive of principles to a later commit, then run the command again."
|
|
98
|
+
else
|
|
99
|
+
"Update the principles plugin or gem to #{release} or later, then run the command again."
|
|
100
|
+
end
|
|
101
|
+
unpublished ? "#{how} #{release} may not be published yet." : how
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -34,6 +34,10 @@ module Principles
|
|
|
34
34
|
#: () -> String?
|
|
35
35
|
def action = @fields["action"]
|
|
36
36
|
|
|
37
|
+
# Why its audit left it unfixed, or nil when it was fixed or its record predates keeping the reason (#996).
|
|
38
|
+
#: () -> String?
|
|
39
|
+
def reason = @fields["reason"]
|
|
40
|
+
|
|
37
41
|
# Where its write-up is, or nil when it was never written up.
|
|
38
42
|
#: () -> WriteUpPointer?
|
|
39
43
|
def recorded_at
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# The member hashes a principle's audit record holds, by key, which its members now are compared with, and
|
|
8
|
+
# whether a later copy wrote that record, so its audits wait on an upgrade and the comparison is read-only
|
|
9
|
+
# (D85, V8, #1066, #1067). A principle with no record holds none.
|
|
10
|
+
class RecordedHashes
|
|
11
|
+
#: (Hash[String, String], ?waiting: bool) -> void
|
|
12
|
+
def initialize(by_key, waiting: false)
|
|
13
|
+
@by_key = by_key.freeze #: Hash[String, String]
|
|
14
|
+
@waiting = waiting #: bool
|
|
15
|
+
freeze
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Each hash, by the key of the member it was recorded for.
|
|
19
|
+
#: Hash[String, String]
|
|
20
|
+
attr_reader :by_key
|
|
21
|
+
|
|
22
|
+
# Whether a later copy wrote the record these hashes come from.
|
|
23
|
+
#: () -> bool
|
|
24
|
+
def waiting? = @waiting
|
|
25
|
+
|
|
26
|
+
# Whether the member known by key, whose hash is now sha, has the text the record assessed: current or changed,
|
|
27
|
+
# and unassessed when the record holds no hash for it.
|
|
28
|
+
#: (String, String) -> String
|
|
29
|
+
def freshness(key, sha)
|
|
30
|
+
recorded = @by_key[key]
|
|
31
|
+
return "unassessed" unless recorded
|
|
32
|
+
|
|
33
|
+
recorded == sha ? "current" : "changed"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
NONE = new({}) #: RecordedHashes
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
require_relative "accepted_loading"
|
|
5
5
|
require_relative "member"
|
|
6
6
|
require_relative "recorded_entry"
|
|
7
|
+
require_relative "recorded_hashes"
|
|
7
8
|
|
|
8
9
|
module Principles
|
|
9
10
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -12,6 +13,11 @@ module Principles
|
|
|
12
13
|
# two differ, holding its hash then, the result reported for its check (D30), its accepted loading decision
|
|
13
14
|
# and the acknowledgements made for it since (D33). Callers reach them through AuditRecord#members.
|
|
14
15
|
class RecordedMembers
|
|
16
|
+
# The key a record knows the member filed under id by: the key kept beside its entry when the two differ, else
|
|
17
|
+
# that id. The one owner of that rule, which MemberHashesAsWritten reads a newer record by too (#1066).
|
|
18
|
+
#: (untyped, untyped) -> untyped
|
|
19
|
+
def self.filed_key(id, entry) = entry["key"] || id
|
|
20
|
+
|
|
15
21
|
#: (Hash[String, untyped]) -> void
|
|
16
22
|
def initialize(entries)
|
|
17
23
|
@entries = entries
|
|
@@ -40,17 +46,16 @@ module Principles
|
|
|
40
46
|
|
|
41
47
|
# Whether the text of the member known by key, whose hash is now sha, is the text the record assessed.
|
|
42
48
|
#: (String, String) -> String
|
|
43
|
-
def freshness(key, sha)
|
|
44
|
-
recorded = hash_for(key)
|
|
45
|
-
return "unassessed" unless recorded
|
|
49
|
+
def freshness(key, sha) = hashes.freshness(key, sha)
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
# The hashes the record assessed, which a member now is compared with.
|
|
52
|
+
#: () -> RecordedHashes
|
|
53
|
+
def hashes = RecordedHashes.new(hashes_by_key)
|
|
49
54
|
|
|
50
55
|
# Each hash the record assessed, by the key of the member it belongs to.
|
|
51
56
|
#: () -> Hash[String, String]
|
|
52
57
|
def hashes_by_key
|
|
53
|
-
@entries.to_h { |id, entry| [
|
|
58
|
+
@entries.to_h { |id, entry| [RecordedMembers.filed_key(id, entry), entry.fetch("sha256")] }
|
|
54
59
|
end
|
|
55
60
|
|
|
56
61
|
# The hash the record assessed for the member known by key, or nil when it assessed no such member.
|
|
@@ -77,7 +82,7 @@ module Principles
|
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
# Each member's accepted loading decision, by its id now, found by the key it keeps through moves (#502).
|
|
80
|
-
#: (
|
|
85
|
+
#: (PrincipleMembers) -> Hash[String, AcceptedLoading]
|
|
81
86
|
def loading_accepted(members)
|
|
82
87
|
members.to_h do |member|
|
|
83
88
|
entry = entry_for(member.key)
|
|
@@ -105,7 +110,7 @@ module Principles
|
|
|
105
110
|
#: (String, Hash[String, untyped]) -> RecordedMembers
|
|
106
111
|
def acknowledged(key, change)
|
|
107
112
|
RecordedMembers.new(@entries.to_h do |id, entry|
|
|
108
|
-
next [id, entry] unless (entry
|
|
113
|
+
next [id, entry] unless RecordedMembers.filed_key(id, entry) == key
|
|
109
114
|
|
|
110
115
|
[id, entry.merge("sha256" => change.fetch("to_sha256"),
|
|
111
116
|
"acknowledgements" => [*entry["acknowledgements"], change])]
|
|
@@ -115,13 +120,13 @@ module Principles
|
|
|
115
120
|
# The key of the member filed under id: its stored key when it had moved, or else id.
|
|
116
121
|
#: (String) -> String
|
|
117
122
|
def key_of(id)
|
|
118
|
-
@entries.
|
|
123
|
+
RecordedMembers.filed_key(id, @entries.fetch(id, {}))
|
|
119
124
|
end
|
|
120
125
|
|
|
121
126
|
# The entry of the member known by key, under the id it was filed under, or nil when the record has none.
|
|
122
127
|
#: (String) -> RecordedEntry?
|
|
123
128
|
def recorded(key)
|
|
124
|
-
id, entry = @entries.find { |filed, each| (each
|
|
129
|
+
id, entry = @entries.find { |filed, each| RecordedMembers.filed_key(filed, each) == key }
|
|
125
130
|
RecordedEntry.new(id, entry) if id && entry
|
|
126
131
|
end
|
|
127
132
|
|
|
@@ -132,7 +137,7 @@ module Principles
|
|
|
132
137
|
RecordedMembers.new(@entries.to_h do |id, entry|
|
|
133
138
|
next [id, entry] unless entry.dig("assessment", "carried_forward")
|
|
134
139
|
|
|
135
|
-
[id, entry.merge("assessment" => last&.recorded(entry
|
|
140
|
+
[id, entry.merge("assessment" => last&.recorded(RecordedMembers.filed_key(id, entry))&.assessment).compact]
|
|
136
141
|
end)
|
|
137
142
|
end
|
|
138
143
|
|
|
@@ -142,7 +147,7 @@ module Principles
|
|
|
142
147
|
# two differ.
|
|
143
148
|
#: (String) -> Hash[String, untyped]?
|
|
144
149
|
def entry_for(key)
|
|
145
|
-
@entries.find { |id, entry| (entry
|
|
150
|
+
@entries.find { |id, entry| RecordedMembers.filed_key(id, entry) == key }&.last
|
|
146
151
|
end
|
|
147
152
|
end
|
|
148
153
|
end
|
|
@@ -5,6 +5,7 @@ require_relative "../error"
|
|
|
5
5
|
require_relative "answer_place"
|
|
6
6
|
require_relative "answer_text"
|
|
7
7
|
require_relative "dated_line"
|
|
8
|
+
require_relative "template_placeholders"
|
|
8
9
|
|
|
9
10
|
module Principles
|
|
10
11
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
@@ -13,11 +14,37 @@ module Principles
|
|
|
13
14
|
# refuses a report that cannot be about the member's own check, and cannot confirm the run happened.
|
|
14
15
|
class ReportedCheck
|
|
15
16
|
SHAPES = "Give check_result as answer_guide.check_result shows."
|
|
17
|
+
# How review_basis records a review the agent made itself, which the placeholder and the repair both give.
|
|
18
|
+
SELF_REVIEWED = "\"Self-reviewed by the agent: <what you checked it against>\"" #: String
|
|
19
|
+
# The not_run_reason a template prints beside exit_status's placeholder, which an answer that leaves it as
|
|
20
|
+
# printed has not given, so filling exit_status alone reports a run (#993).
|
|
21
|
+
NOT_RUN_PLACEHOLDER = "Only if the command could not be run here: why, such as a missing tool or a sandbox. " \
|
|
22
|
+
"Leave this as printed once exit_status gives the run's status" #: String
|
|
23
|
+
# The review_basis a template prints for a check no audit ran, or one changed since, which an exit_status needs
|
|
24
|
+
# beside it, and which beside not_run_reason left as printed is not given (D63, #993).
|
|
25
|
+
REVIEW_BASIS_PLACEHOLDER = "One line saying what the review before the run rested on, such as who reviewed " \
|
|
26
|
+
"it or the document that confirms it; for your own review, #{SELF_REVIEWED}. " \
|
|
27
|
+
"Leave this as printed only beside not_run_reason".freeze #: String
|
|
28
|
+
# Why an exit status for a check no audit ran is refused without review_basis, and when given its placeholder.
|
|
29
|
+
NEEDS_BASIS = "check_result needs review_basis beside exit_status, since no audit ran this command" #: String
|
|
30
|
+
LEFT_BASIS = "check_result.review_basis is the template's placeholder, unchanged, and an exit_status for a " \
|
|
31
|
+
"command no audit ran needs it" #: String
|
|
32
|
+
# The placeholder a template prints in each field an answer may leave as printed to give none.
|
|
33
|
+
PLACEHOLDERS = TemplatePlaceholders.new({ "not_run_reason" => NOT_RUN_PLACEHOLDER,
|
|
34
|
+
"review_basis" => REVIEW_BASIS_PLACEHOLDER }) #: TemplatePlaceholders
|
|
35
|
+
# The review_basis a template prints for a check the last audit ran, which left as printed keeps the line that
|
|
36
|
+
# audit kept, and replaced gives a new one (#1010).
|
|
37
|
+
KEPT_BASIS_PLACEHOLDER = "Only to give a new line for what this run's review rested on; leave this as " \
|
|
38
|
+
"printed to keep the line the last audit kept, if any" #: String
|
|
39
|
+
# The placeholders a template prints for a check the last audit ran.
|
|
40
|
+
UNCHANGED_PLACEHOLDERS = TemplatePlaceholders.new(
|
|
41
|
+
{ "not_run_reason" => NOT_RUN_PLACEHOLDER, "review_basis" => KEPT_BASIS_PLACEHOLDER }
|
|
42
|
+
) #: TemplatePlaceholders
|
|
16
43
|
BASIS = "Say in review_basis, in one line, what the review before the run rested on, such as " \
|
|
17
44
|
"\"The owner reviewed the command in this session.\" or the document that confirms it. If you did " \
|
|
18
45
|
"the review yourself, such as confirming against the documentation a check you changed, say so: " \
|
|
19
|
-
"
|
|
20
|
-
"kept, say so, such as \"Reviewed in an earlier session; basis not kept.\"" #: String
|
|
46
|
+
"#{SELF_REVIEWED}. If no record of the review was " \
|
|
47
|
+
"kept, say so, such as \"Reviewed in an earlier session; basis not kept.\"".freeze #: String
|
|
21
48
|
|
|
22
49
|
# assessment is the place of the member's assessment in the answer, whose check_result each refusal points
|
|
23
50
|
# into (#817). ran is the command the principle's stored record was given an exit status for, nil when it ran
|
|
@@ -39,14 +66,28 @@ module Principles
|
|
|
39
66
|
return no_check(reported) unless @check
|
|
40
67
|
|
|
41
68
|
missing_result unless reported
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
given = filled(reported)
|
|
70
|
+
same_command(given.fetch("command"))
|
|
71
|
+
unfilled_status(reported, given)
|
|
72
|
+
status_or_reason(given)
|
|
73
|
+
review_basis(given, left: placeholders.left?("review_basis", reported["review_basis"]))
|
|
74
|
+
carrying_review(given)
|
|
46
75
|
end
|
|
47
76
|
|
|
48
77
|
private
|
|
49
78
|
|
|
79
|
+
# The fields reported gives, leaving out those the template left as printed: an exit_status still the
|
|
80
|
+
# placeholder string that says how to run the check, and each field as its placeholder (#993).
|
|
81
|
+
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
82
|
+
def filled(reported)
|
|
83
|
+
placeholders.given(reported).reject { |field, value| field == "exit_status" && value.is_a?(String) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The placeholders the template printed for this check: for one the stored record ran, a review_basis that
|
|
87
|
+
# left as printed keeps its line; for any other, one an exit_status needs replaced (#1010).
|
|
88
|
+
#: () -> TemplatePlaceholders
|
|
89
|
+
def placeholders = @ran == @check ? UNCHANGED_PLACEHOLDERS : PLACEHOLDERS
|
|
90
|
+
|
|
50
91
|
# The place of the reported check_result, or of one of its fields.
|
|
51
92
|
#: (?String?) -> AnswerPlace
|
|
52
93
|
def reported_at(field = nil)
|
|
@@ -81,6 +122,17 @@ module Principles
|
|
|
81
122
|
"answer_guide.check_result.limits asks for one.")
|
|
82
123
|
end
|
|
83
124
|
|
|
125
|
+
# Refuses a result that gives neither field but text in exit_status: the template's placeholder, or other text
|
|
126
|
+
# written where only the status goes, so the repair says what replaces it (#993).
|
|
127
|
+
#: (Hash[String, untyped], Hash[String, untyped]) -> void
|
|
128
|
+
def unfilled_status(reported, given)
|
|
129
|
+
return if given.key?("exit_status") || given.key?("not_run_reason") || !reported["exit_status"].is_a?(String)
|
|
130
|
+
|
|
131
|
+
refuse(reported_at("exit_status"), "check_result.exit_status is text, not the command's exit status",
|
|
132
|
+
"Replace exit_status, which the template prints as text to replace, with the exit status as an " \
|
|
133
|
+
"integer once the command has run, or write why it could not run in not_run_reason.")
|
|
134
|
+
end
|
|
135
|
+
|
|
84
136
|
#: (Hash[String, untyped]) -> void
|
|
85
137
|
def status_or_reason(reported)
|
|
86
138
|
unless reported.key?("exit_status") ^ reported.key?("not_run_reason")
|
|
@@ -96,9 +148,10 @@ module Principles
|
|
|
96
148
|
|
|
97
149
|
# Refuses an exit status for a check the stored record did not run unless review_basis says what its review
|
|
98
150
|
# rested on, and any review_basis that is not one written line. What the line says is the agent's: this tool
|
|
99
|
-
# keeps it and cannot verify it.
|
|
100
|
-
|
|
101
|
-
|
|
151
|
+
# keeps it and cannot verify it. left says the template's placeholder was sent back in it, which the refusal
|
|
152
|
+
# names (#993).
|
|
153
|
+
#: (Hash[String, untyped], left: bool) -> void
|
|
154
|
+
def review_basis(reported, left:)
|
|
102
155
|
if reported.key?("review_basis")
|
|
103
156
|
return if AnswerText.new(reported["review_basis"]).one_line?
|
|
104
157
|
|
|
@@ -106,8 +159,7 @@ module Principles
|
|
|
106
159
|
end
|
|
107
160
|
return unless reported.key?("exit_status") && @ran != @check
|
|
108
161
|
|
|
109
|
-
refuse(reported_at("review_basis"),
|
|
110
|
-
"check_result needs review_basis beside exit_status, since no audit ran this command", BASIS)
|
|
162
|
+
refuse(reported_at("review_basis"), left ? LEFT_BASIS : NEEDS_BASIS, BASIS)
|
|
111
163
|
end
|
|
112
164
|
|
|
113
165
|
# The result as the record keeps it: an unchanged check's exit status with the kept line and its date when the
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require "digest"
|
|
5
|
-
require "json"
|
|
6
4
|
require_relative "../error"
|
|
5
|
+
require_relative "json_digest"
|
|
7
6
|
|
|
8
7
|
module Principles
|
|
9
8
|
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
@@ -21,10 +20,20 @@ module Principles
|
|
|
21
20
|
#: String
|
|
22
21
|
attr_reader :phase
|
|
23
22
|
|
|
24
|
-
# The id of a request in phase for principle_id, which depends on parts
|
|
23
|
+
# The id of a request in phase for principle_id, which depends on parts, digested by what they say, so an answer
|
|
24
|
+
# whose keys are reordered, as `jq -S` does, still matches (#1045).
|
|
25
25
|
#: (principle_id: String, phase: String, parts: Array[untyped]) -> RequestId
|
|
26
26
|
def self.for(principle_id:, phase:, parts:)
|
|
27
|
-
new(principle_id, phase,
|
|
27
|
+
new(principle_id, phase, JsonDigest.new([principle_id, phase, *parts]).to_s[0, 12].to_s)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The id of a request whose answer hands part of it back: its digest's first half digests what is handed back
|
|
31
|
+
# alone and its second the parts this tool recomputes, so an answer that edited what it hands back is told apart
|
|
32
|
+
# from a project that changed (#1045).
|
|
33
|
+
#: (principle_id: String, phase: String, handed: untyped, parts: Array[untyped]) -> RequestId
|
|
34
|
+
def self.handing_back(principle_id:, phase:, handed:, parts:)
|
|
35
|
+
half = ->(digested) { JsonDigest.new([principle_id, phase, digested]).to_s[0, 6].to_s }
|
|
36
|
+
new(principle_id, phase, half.call(handed) + half.call(parts))
|
|
28
37
|
end
|
|
29
38
|
|
|
30
39
|
# An id as an agent passed it, refused unless it has the shape this tool prints.
|
|
@@ -56,6 +65,17 @@ module Principles
|
|
|
56
65
|
"Start from the response_template of this request.")
|
|
57
66
|
end
|
|
58
67
|
|
|
68
|
+
# What of a handing_back id differs in other: :handed, what the answer hands back, before :parts, what this tool
|
|
69
|
+
# recomputes, or nil when neither does.
|
|
70
|
+
#: (RequestId) -> Symbol?
|
|
71
|
+
def differs_from(other)
|
|
72
|
+
mine = to_s
|
|
73
|
+
theirs = other.to_s
|
|
74
|
+
return :handed unless mine[0...-6] == theirs[0...-6]
|
|
75
|
+
|
|
76
|
+
:parts unless mine == theirs
|
|
77
|
+
end
|
|
78
|
+
|
|
59
79
|
#: () -> String
|
|
60
80
|
def to_s
|
|
61
81
|
"#{@principle_id}.#{@phase}.#{@digest}"
|