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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +7 -1
  3. data/lib/principles/command_line.rb +12 -29
  4. data/lib/principles/controllers/acknowledgement.rb +4 -4
  5. data/lib/principles/controllers/answer.rb +64 -100
  6. data/lib/principles/controllers/assessment.rb +108 -0
  7. data/lib/principles/controllers/audit.rb +29 -135
  8. data/lib/principles/controllers/audit_completion.rb +2 -4
  9. data/lib/principles/controllers/command.rb +27 -13
  10. data/lib/principles/controllers/correction.rb +4 -4
  11. data/lib/principles/controllers/full_audit_request.rb +180 -0
  12. data/lib/principles/controllers/inventory.rb +32 -70
  13. data/lib/principles/controllers/mapping.rb +3 -3
  14. data/lib/principles/controllers/member_entries.rb +24 -12
  15. data/lib/principles/controllers/member_problems_report.rb +72 -0
  16. data/lib/principles/controllers/members_a_commit_changed.rb +10 -2
  17. data/lib/principles/controllers/members_to_assess.rb +16 -9
  18. data/lib/principles/controllers/meta_principle_setup.rb +5 -5
  19. data/lib/principles/controllers/repoint.rb +1 -1
  20. data/lib/principles/controllers/running_tool.rb +1 -1
  21. data/lib/principles/data/audit_files.rb +11 -7
  22. data/lib/principles/data/bounded_file.rb +11 -0
  23. data/lib/principles/data/command-steps.json +7 -6
  24. data/lib/principles/data/map_files.rb +2 -2
  25. data/lib/principles/data/principles_subfolder.rb +8 -1
  26. data/lib/principles/data/project_files.rb +1 -7
  27. data/lib/principles/data/project_root.rb +48 -0
  28. data/lib/principles/data/schema_check.rb +23 -5
  29. data/lib/principles/data/schemas/assessment-answer.schema.json +18 -9
  30. data/lib/principles/data/schemas/audit-record.schema.json +3 -0
  31. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  32. data/lib/principles/data/schemas/correction-answer.schema.json +2 -3
  33. data/lib/principles/invocation_options.rb +1 -1
  34. data/lib/principles/models/assessment_answer.rb +64 -17
  35. data/lib/principles/models/audit.rb +24 -15
  36. data/lib/principles/models/audit_record.rb +10 -3
  37. data/lib/principles/models/audit_records.rb +74 -4
  38. data/lib/principles/models/audit_start.rb +3 -3
  39. data/lib/principles/models/carried_assessments.rb +1 -1
  40. data/lib/principles/models/check_since_last_audit.rb +6 -6
  41. data/lib/principles/models/correction_basis.rb +1 -1
  42. data/lib/principles/models/decided_prior_findings.rb +9 -19
  43. data/lib/principles/models/declared_map_changes.rb +8 -8
  44. data/lib/principles/models/disposition.rb +28 -24
  45. data/lib/principles/models/evidence_replacements.rb +8 -1
  46. data/lib/principles/models/fix_only_fields.rb +67 -0
  47. data/lib/principles/models/kept_prior_finding.rb +12 -7
  48. data/lib/principles/models/loaded_files.rb +5 -3
  49. data/lib/principles/models/loading_decision.rb +9 -2
  50. data/lib/principles/models/{member_maps.rb → mapped_principles.rb} +15 -15
  51. data/lib/principles/models/member.rb +1 -1
  52. data/lib/principles/models/member_assessments.rb +48 -3
  53. data/lib/principles/models/member_grounds.rb +2 -2
  54. data/lib/principles/models/member_hashes_as_written.rb +40 -0
  55. data/lib/principles/models/member_moves.rb +3 -3
  56. data/lib/principles/models/member_problems.rb +38 -18
  57. data/lib/principles/models/members_sharing_lines.rb +3 -3
  58. data/lib/principles/models/new_findings.rb +55 -0
  59. data/lib/principles/models/open_finding.rb +23 -13
  60. data/lib/principles/models/other_principles.rb +1 -1
  61. data/lib/principles/models/other_templates_placeholders.rb +74 -0
  62. data/lib/principles/models/{member_map.rb → principle.rb} +45 -40
  63. data/lib/principles/models/{member_map_history.rb → principle_history.rb} +38 -15
  64. data/lib/principles/models/{map_members.rb → principle_members.rb} +4 -4
  65. data/lib/principles/models/prior_decision_fields.rb +46 -0
  66. data/lib/principles/models/prior_finding_decision.rb +24 -3
  67. data/lib/principles/models/prior_finding_outcomes.rb +10 -3
  68. data/lib/principles/models/prior_findings.rb +1 -1
  69. data/lib/principles/models/problem_report.rb +7 -3
  70. data/lib/principles/models/project.rb +27 -13
  71. data/lib/principles/models/project_history.rb +2 -2
  72. data/lib/principles/models/recent_decision.rb +90 -0
  73. data/lib/principles/models/record_format.rb +105 -0
  74. data/lib/principles/models/recorded_finding.rb +4 -0
  75. data/lib/principles/models/recorded_hashes.rb +39 -0
  76. data/lib/principles/models/recorded_members.rb +17 -12
  77. data/lib/principles/models/reported_check.rb +63 -11
  78. data/lib/principles/models/request_id.rb +24 -4
  79. data/lib/principles/models/sent_prior_decisions.rb +31 -0
  80. data/lib/principles/models/still_holds_restatement.rb +7 -10
  81. data/lib/principles/models/template_placeholders.rb +41 -0
  82. data/lib/principles/session_start_options.rb +29 -0
  83. data/lib/principles/start_audit_options.rb +37 -0
  84. data/lib/principles/version.rb +2 -2
  85. data/lib/principles/views/answer_head.rb +29 -0
  86. data/lib/principles/views/assessed_members.rb +96 -0
  87. data/lib/principles/views/assessment_request.rb +51 -49
  88. data/lib/principles/views/audit_result.rb +38 -42
  89. data/lib/principles/views/check_result_template.rb +31 -10
  90. data/lib/principles/views/correction_request.rb +64 -0
  91. data/lib/principles/views/first_audit.rb +71 -0
  92. data/lib/principles/views/help.rb +3 -2
  93. data/lib/principles/views/loads_to_check_result.rb +11 -4
  94. data/lib/principles/views/map_added_to.rb +31 -0
  95. data/lib/principles/views/map_result.rb +37 -22
  96. data/lib/principles/views/members_a_commit_changed.rb +30 -10
  97. data/lib/principles/views/meta_principle_result.rb +3 -14
  98. data/lib/principles/views/principle_read_result.rb +27 -10
  99. data/lib/principles/views/prior_finding_decisions_result.rb +13 -14
  100. data/lib/principles/views/prior_findings_result.rb +7 -3
  101. data/lib/principles/views/problem_lines.rb +14 -11
  102. data/lib/principles/views/problem_result.rb +30 -16
  103. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +3 -2
  104. data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +2 -2
  105. data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
  106. data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
  107. data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +3 -6
  108. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +1 -1
  109. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +4 -1
  110. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +7 -2
  111. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +22 -20
  112. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +8 -5
  113. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +3 -0
  114. data/lib/principles/views/prompts/learn-what-a-command-does/select-the-project-root.md +1 -0
  115. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +6 -0
  116. data/lib/principles/views/prompts/learn-what-a-command-does/show-audit.md +3 -1
  117. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +2 -1
  118. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +12 -12
  119. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  120. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +37 -37
  121. data/lib/principles/views/prompts/report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade.md +2 -0
  122. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +1 -0
  123. data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +4 -0
  124. data/lib/principles/views/prompts/set-principles-up/first-keeping-audit-after-own-principle.md +10 -0
  125. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +2 -1
  126. data/lib/principles/views/record_waiting_on_an_upgrade.rb +54 -0
  127. data/lib/principles/views/request_part.rb +14 -2
  128. data/lib/principles/views/request_parts.rb +4 -0
  129. metadata +33 -7
@@ -0,0 +1,31 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "prior_decision_fields"
5
+
6
+ module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
+ module Models
9
+ # An assessment answer's prior_finding_decisions as sent, before each is checked against the finding it decides:
10
+ # a decision still the placeholder start-audit --as template printed is no decision, so the answer's one refusal
11
+ # names it with every other judgement left so (#1040).
12
+ class SentPriorDecisions
13
+ # decisions is the answer's prior_finding_decisions as sent, a list.
14
+ #: (Array[untyped]) -> void
15
+ def initialize(decisions)
16
+ @decisions = decisions
17
+ freeze
18
+ end
19
+
20
+ # Each decision left as printed, named by the finding it decides, with its pointer.
21
+ #: () -> Hash[String, String]
22
+ def left_as_printed
23
+ @decisions.each_with_index.filter_map do |decision, index|
24
+ next unless decision.is_a?(Hash) && decision["decision"] == PriorDecisionFields::DECISION
25
+
26
+ ["Prior finding #{decision["finding_id"]} decision", "/prior_finding_decisions/#{index}/decision"]
27
+ end.to_h
28
+ end
29
+ end
30
+ end
31
+ end
@@ -10,9 +10,9 @@ require_relative "open_finding"
10
10
  module Principles
11
11
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
12
12
  module Models
13
- # What a decision on a prior finding restates of that finding, which only a still_holds decision may: the
14
- # problem its record lacks, a new pointer to its write-up (D35), the evidence its record lacks (D64) and a new
15
- # place for each kept evidence item no longer found (D70).
13
+ # What a decision on a prior finding restates of that finding, which only a still_holds decision may: its
14
+ # problem, which its record may lack (#706), a new pointer to its write-up (D35), the evidence its record lacks
15
+ # (D64) and a new place for each kept evidence item no longer found (D70).
16
16
  # PriorFindingDecision checks the rest of the decision, and refuses for this through refuse.
17
17
  class StillHoldsRestatement
18
18
  # finding is the prior finding as its record left it open; place is the decision's place in the answer; refuse
@@ -27,9 +27,8 @@ module Principles
27
27
  freeze
28
28
  end
29
29
 
30
- # Refuses a restatement on any decision but still_holds, a problem the finding already states or that is not
31
- # one line, kept evidence it replaces but that is still found or named by no replaces, and a pointer locate
32
- # cannot resolve.
30
+ # Refuses a restatement on any decision but still_holds, a problem that is not one line, kept evidence it
31
+ # replaces but that is still found or named by no replaces, and a pointer locate cannot resolve.
33
32
  #: (^(Locator) -> void) -> void
34
33
  def check(locate)
35
34
  evidence(locate) if @decision.key?("problem_evidence")
@@ -74,12 +73,10 @@ module Principles
74
73
  AnswerFields.new(locate).evidence(given, place)
75
74
  end
76
75
 
76
+ # The problem its record lacks, or a restatement of the one it states when a term in it was renamed or a fact it
77
+ # names moved, which keeps the finding's id and first_raised_at (#706).
77
78
  #: () -> void
78
79
  def problem
79
- if @finding.states_problem?
80
- @refuse.call("it already states its problem",
81
- "Drop problem from #{@id}'s decision, or raise it again as a new finding to restate it.")
82
- end
83
80
  @refuse.call("problem must be one line", nil) unless AnswerText.new(@decision["problem"]).one_line?
84
81
  end
85
82
  end
@@ -0,0 +1,41 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
6
+ module Models
7
+ # The text an answer's template prints in each field an agent may leave as printed to give none, so the agent
8
+ # fills the fields that apply and never reshapes the answer (#993, #994). The model that owns a part of the answer
9
+ # holds one, which a controller hands to the view that prints it.
10
+ class TemplatePlaceholders
11
+ # placeholders is the text printed in each field, by field name, or for a field that takes pointers, one pointer
12
+ # whose fields hold that text, so the template shows their shape (#1042); empty_lists names the fields a template
13
+ # may instead start as an empty list, which is not given either (#838).
14
+ #: (Hash[String, untyped], ?empty_lists: Array[String]) -> void
15
+ def initialize(placeholders, empty_lists: [])
16
+ @placeholders = placeholders.freeze #: Hash[String, untyped]
17
+ @empty_lists = empty_lists.freeze #: Array[String]
18
+ freeze
19
+ end
20
+
21
+ # The text printed in each field, for the view that prints it.
22
+ #: () -> Hash[String, untyped]
23
+ def to_h = @placeholders
24
+
25
+ # The text printed in field.
26
+ #: (String) -> untyped
27
+ def fetch(field) = @placeholders.fetch(field)
28
+
29
+ # fields, without each one left as its placeholder, which is not given.
30
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
31
+ def given(fields) = fields.reject { |field, value| left?(field, value) }
32
+
33
+ # Whether value is field's placeholder, or the empty list it may start as, as printed; a field with neither
34
+ # never is.
35
+ #: (String, untyped) -> bool
36
+ def left?(field, value)
37
+ (@placeholders.key?(field) && @placeholders[field] == value) || (@empty_lists.include?(field) && value == [])
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The option list-open-findings --short takes from Claude Code's SessionStart hook, --session-start (#717), and what
8
+ # is wrong with it as given, which CommandLine refuses as a usage error.
9
+ class SessionStartOptions
10
+ # The sources Claude Code's SessionStart hook names.
11
+ SOURCES = %w[startup clear compact].freeze #: Array[String]
12
+
13
+ #: (InvocationOptions) -> void
14
+ def initialize(options)
15
+ @start = options.value("session_start") #: String?
16
+ @short = !options.value("short").nil? #: bool
17
+ freeze
18
+ end
19
+
20
+ # What is wrong with the option as given, or nil when it fits or is not given; it words only the --short line.
21
+ #: () -> String?
22
+ def fault
23
+ start = @start or return
24
+ return "--session-start takes startup, clear or compact, not #{start}" unless SOURCES.include?(start)
25
+
26
+ "--session-start words only the --short line" unless @short
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation_options"
5
+
6
+ module Principles
7
+ # The options that choose which audit start-audit begins, --member and --write-ups (#760), and the form --as prints
8
+ # it in (D81), and what is wrong with them as given, which CommandLine refuses as a usage error.
9
+ class StartAuditOptions
10
+ #: (InvocationOptions) -> void
11
+ def initialize(options)
12
+ @member = !options.value("member").nil? #: bool
13
+ @write_ups = !options.value("write_ups").nil? #: bool
14
+ @form = options.value("as") #: String?
15
+ freeze
16
+ end
17
+
18
+ # What is wrong with the options as given, or nil when they fit.
19
+ #: () -> String?
20
+ def fault
21
+ return "--member and --write-ups each start a different audit; give one" if @member && @write_ups
22
+
23
+ form_fault
24
+ end
25
+
26
+ private
27
+
28
+ # --as template prints a full audit's answer alone, the one form built so far (D81 step 1); nil when it fits.
29
+ #: () -> String?
30
+ def form_fault
31
+ form = @form or return
32
+ return "--as takes template, the full audit's answer alone, not #{form}" unless form == "template"
33
+
34
+ "--as template prints a full audit's answer, not one --member or --write-ups starts" if @member || @write_ups
35
+ end
36
+ end
37
+ end
@@ -3,9 +3,9 @@
3
3
 
4
4
  module Principles
5
5
  # The next production release, as major.minor.patch. A production build is versioned with this alone.
6
- RELEASE = "0.0.1"
6
+ RELEASE = "0.0.4"
7
7
  # The version a built gem prints. `rake build[production]` stamps RELEASE here, in the copy of lib/ it
8
8
  # packages, and `rake build[development]` stamps RELEASE.g<short sha>. A checkout leaves it nil, and
9
9
  # Data::RunningVersion reads the commit this tool runs from instead.
10
- BUILT_VERSION = "0.0.1" #: String?
10
+ BUILT_VERSION = "0.0.4" #: String?
11
11
  end
@@ -0,0 +1,29 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
6
+ module Views
7
+ # What an answer hands back unchanged, at its head: the id of the request it answers and that request's basis,
8
+ # which the agent never copies by hand.
9
+ class AnswerHead
10
+ #: String
11
+ attr_reader :request_id
12
+
13
+ #: (request_id: String, basis: Hash[String, untyped]) -> void
14
+ def initialize(request_id:, basis:)
15
+ @request_id = request_id
16
+ @basis = basis
17
+ freeze
18
+ end
19
+
20
+ # Whether the basis names a base commit, as in git; outside git it names none.
21
+ #: () -> bool
22
+ def based_on_a_commit? = !@basis["base_commit"].nil?
23
+
24
+ # The answer's fields, after its request id and basis.
25
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
26
+ def leading(fields) = { "request_id" => @request_id, "basis" => @basis }.merge(fields)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,96 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "check_result_template"
5
+
6
+ module Principles
7
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
+ module Views
9
+ # The members an assessment request lists, each a plain entry of id, role, first_line, last_line, the evidence
10
+ # that locates it and, for a member with a check, the check whose result the template asks for (D30): what the
11
+ # request shows of each, the template entry each starts with, and what they carry that the request explains.
12
+ class AssessedMembers
13
+ # What the request shows of each member.
14
+ SHOWN = %w[id role first_line last_line check check_since_last_audit check_hidden_characters
15
+ acknowledged_since_last_audit carried_forward judge_because moved_from read_the_change
16
+ mapped_elsewhere].freeze #: Array[String]
17
+
18
+ # reviewed_check_placeholders is the text a checked member's template prints in each field it may leave as
19
+ # printed to give none, for a check reviewed before it runs (#993); unchanged_check_placeholders, for one the
20
+ # last audit ran (#1010).
21
+ # assessment_placeholder is the text a fresh member's assessment prints, which an answer may not send back
22
+ # (#991). sighting_placeholders is the text the template printed alone gives observation and observed_at beside
23
+ # delivery, which a delivery not observed leaves as printed (#1010).
24
+ #: (Array[Hash[String, untyped]], reviewed_check_placeholders: Hash[String, String],
25
+ #| unchanged_check_placeholders: Hash[String, String], assessment_placeholder: String,
26
+ #| sighting_placeholders: Hash[String, String]) -> void
27
+ def initialize(members, reviewed_check_placeholders:, unchanged_check_placeholders:, assessment_placeholder:,
28
+ sighting_placeholders:)
29
+ @assessment_placeholder = assessment_placeholder
30
+ @sighting_placeholders = sighting_placeholders
31
+ @members = members
32
+ @reviewed_check_placeholders = reviewed_check_placeholders
33
+ @unchanged_check_placeholders = unchanged_check_placeholders
34
+ freeze
35
+ end
36
+
37
+ # Each member as the request's context shows it, its fields in SHOWN's order.
38
+ #: () -> Array[Hash[String, untyped]]
39
+ def shown = @members.map { |member| SHOWN.select { member.key?(it) }.to_h { [it, member[it]] } }
40
+
41
+ # Each member's template entry: a fresh assessment to fill in, or, for a member whose last assessment is
42
+ # carried forward, the marker that keeps it (D49); either with its check's result when it has a check.
43
+ #: () -> Array[Hash[String, untyped]]
44
+ def templates = @members.map { |member| template(member) }
45
+
46
+ # Each member's template entry as the template printed alone gives it: a fresh assessment also prints
47
+ # observation and observed_at after delivery, so reporting a sighting fills them (#1010).
48
+ #: () -> Array[Hash[String, untyped]]
49
+ def templates_to_fill
50
+ templates.map do |entry|
51
+ next entry unless entry.key?("delivery")
52
+
53
+ entry.flat_map { |field, value| [[field, value], *(@sighting_placeholders if field == "delivery")] }.to_h
54
+ end
55
+ end
56
+
57
+ # Whether any member has a check, whose result's shapes the answer guide then shows (D30).
58
+ #: () -> bool
59
+ def checked? = @members.any? { |member| member["check"] }
60
+
61
+ # Whether the request carries any member's last assessment forward (D49).
62
+ #: () -> bool
63
+ def carried_forward? = @members.any? { |member| member["carried_forward"] }
64
+
65
+ # Each reason a member is judged afresh, once (D61).
66
+ #: () -> Array[String]
67
+ def judge_because = @members.filter_map { |member| member["judge_because"] }.uniq
68
+
69
+ # Each entry naming another principle's role for a member's lines (#719).
70
+ #: () -> Array[Hash[String, untyped]]
71
+ def mapped_elsewhere = @members.flat_map { |member| member["mapped_elsewhere"] || [] }
72
+
73
+ private
74
+
75
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
76
+ def template(member)
77
+ assessed = member["carried_forward"] ? carried(member) : fresh(member)
78
+ check = member["check"] or return assessed
79
+ template = CheckResultTemplate.new(check, member["check_since_last_audit"],
80
+ member.fetch("check_hidden_characters", []),
81
+ reviewed_placeholders: @reviewed_check_placeholders,
82
+ unchanged_placeholders: @unchanged_check_placeholders)
83
+ assessed.merge("check_result" => template.to_h)
84
+ end
85
+
86
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
87
+ def carried(member) = { "member_id" => member.fetch("id"), "carried_forward" => true }
88
+
89
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
90
+ def fresh(member)
91
+ { "member_id" => member.fetch("id"), "assessment" => @assessment_placeholder,
92
+ "delivery" => "not_observed", "evidence" => member.fetch("evidence") }
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,64 +1,82 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "check_result_template"
4
+ require_relative "answer_head"
5
+ require_relative "assessed_members"
5
6
  require_relative "prompts"
6
7
  require_relative "request_parts"
7
8
 
8
9
  module Principles
9
10
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
11
  module Views
11
- # One assessment request start-audit prints: the principle and its members as the agent assesses them, and
12
- # the answer's template. Each member is an entry of id, role, first_line, last_line, the evidence that locates
13
- # it and, for a member with a check, the check whose result the template asks for (D30). Its hash travels in
14
- # the request id, not here.
12
+ # One assessment request start-audit prints: the principle and its members as the agent assesses them, as
13
+ # AssessedMembers, and the answer's template. Its hash travels in the request id, not here.
15
14
  class AssessmentRequest
15
+ # The recent_decision the request's template prints, which names the other form in the guide beside it.
16
+ IN_GUIDE = {
17
+ "unavailable_reason" => "Or use the assessed shape in answer_guide.recent_decision."
18
+ }.freeze #: Hash[String, String]
19
+
16
20
  # The question every member's assessment answers, which a completed record digests with the description (D49).
17
21
  #: () -> String
18
22
  def self.question = Prompts.text("assess-every-member/assess-each-member-and-the-set")
19
23
 
20
- # basis is what the answer hands back unchanged: the base commit and the last completed record's revision.
21
- # parts are what the agent reads beside the members before the question, such as the files outside the map
22
- # that differ from the base commit (#409), each with any slots it adds to the template (D60).
23
- #: (principle_id: String, description: untyped, members: Array[Hash[String, untyped]],
24
- #| basis: Hash[String, untyped], ?parts: Array[RequestPart]) -> void
25
- def initialize(principle_id:, description:, members:, basis:, parts: [])
26
- @principle_id = principle_id
27
- @description = description
24
+ # principle is the principle_id and description it names. head is what the answer hands back unchanged: the
25
+ # request's id and its basis, the base commit and the last completed record's revision. parts are what the
26
+ # agent reads beside the members before the question, such as the files outside the map that differ from the
27
+ # base commit (#409), each with any slots it adds to the template (D60). placeholders is what the answer's own
28
+ # fields print, by field, which their models own: collective_assessment's, which an answer may not send back
29
+ # (#991), and recent_decision's, each field of both its forms, in the template alone, which the agent fills one
30
+ # of (#994).
31
+ #: (principle: Hash[String, untyped], members: AssessedMembers, head: AnswerHead,
32
+ #| placeholders: Hash[String, untyped], ?parts: Array[RequestPart]) -> void
33
+ def initialize(principle:, members:, head:, placeholders:, parts: [])
34
+ @principle = principle
35
+ @placeholders = placeholders
28
36
  @members = members
29
- @basis = basis
37
+ @head = head
30
38
  @parts = RequestParts.new(parts) #: RequestParts
31
39
  freeze
32
40
  end
33
41
 
42
+ # The id the request is answered under.
43
+ #: () -> String
44
+ def request_id = @head.request_id
45
+
34
46
  # What the agent assesses, its other parts, the question and a guide to the answer's shapes.
35
47
  #: () -> Hash[String, untyped]
36
48
  def context
37
- listed = { "principle_id" => @principle_id, "description" => @description,
38
- "members" => @members.map do |member|
39
- member.slice("id", "role", "first_line", "last_line", "check", "check_since_last_audit",
40
- "check_hidden_characters", "acknowledged_since_last_audit", "carried_forward",
41
- "judge_because", "moved_from", "read_the_change", "mapped_elsewhere")
42
- end }
49
+ listed = @principle.merge("members" => @members.shown)
43
50
  @parts.shown_after(listed).merge(asked)
44
51
  end
45
52
 
46
53
  # The answer to fill in: one assessment per member, and the set's.
47
54
  #: () -> Hash[String, untyped]
48
55
  def template
49
- assessed = {
50
- "basis" => @basis,
51
- "member_assessments" => @members.map { |member| member_assessment_template(member) },
52
- "collective_assessment" => "How the members reinforce the principle, and any contradiction or " \
53
- "missing connection.",
54
- "recent_decision" => { "unavailable_reason" => "Or use the assessed shape in answer_guide.recent_decision." },
55
- "findings" => []
56
- }
57
- @parts.slotted_after(assessed)
56
+ @head.leading(@parts.slotted_after(assessed(IN_GUIDE, @members.templates)))
57
+ end
58
+
59
+ # The answer to fill in as printed alone, with no request beside it: each placeholder says what its field
60
+ # takes, and points at nothing left unprinted (D81 step 1), after one note saying how a field left as printed is
61
+ # read (#1043, D88).
62
+ #: () -> Hash[String, untyped]
63
+ def template_to_fill
64
+ filled = assessed(@placeholders.fetch("recent_decision"), @members.templates_to_fill)
65
+ @head.leading(@parts.filled_after({ "left_as_printed_rule" => @placeholders.fetch("left_as_printed_rule"),
66
+ **filled, "findings" => [@placeholders.fetch("new_finding")] }))
58
67
  end
59
68
 
60
69
  private
61
70
 
71
+ # The answer's fields after its head and before its parts' slots, recent_decision and the members' templates as
72
+ # given.
73
+ #: (Hash[String, String], Array[Hash[String, untyped]]) -> Hash[String, untyped]
74
+ def assessed(recent_decision, members)
75
+ { "member_assessments" => members,
76
+ "collective_assessment" => @placeholders.fetch("collective_assessment"),
77
+ "recent_decision" => recent_decision, "findings" => [] }
78
+ end
79
+
62
80
  # What the request asks of what the agent read: the question, why members are judged afresh, how to treat the
63
81
  # members it carries forward and the roles other principles give their lines, and the guide to the answer's
64
82
  # shapes.
@@ -73,7 +91,7 @@ module Principles
73
91
  # agent meets each value's meaning where it meets the value (D61); nothing when no member gives one.
74
92
  #: () -> Hash[String, untyped]
75
93
  def judge_because_instruction
76
- reasons = @members.filter_map { |member| member["judge_because"] }.uniq
94
+ reasons = @members.judge_because
77
95
  return {} if reasons.empty?
78
96
 
79
97
  intro, *meanings = Prompts.text("assess-every-member/why-each-member-is-judged-again").split("\n\n")
@@ -86,7 +104,7 @@ module Principles
86
104
  # treat them, which prints apart, before the question (#808).
87
105
  #: () -> Hash[String, untyped]
88
106
  def mapped_elsewhere_instruction
89
- entries = @members.flat_map { |member| member["mapped_elsewhere"] || [] }
107
+ entries = @members.mapped_elsewhere
90
108
  return {} if entries.empty?
91
109
 
92
110
  roles, open_findings = Prompts.text("assess-every-member/check-roles-other-principles-give-these-lines")
@@ -100,32 +118,16 @@ module Principles
100
118
  #: () -> Hash[String, untyped]
101
119
  def answer_guide
102
120
  guide = Prompts.data("assess-every-member/answer-guide")
103
- @members.any? { |member| member["check"] } ? guide : guide.except("check_result")
121
+ @members.checked? ? guide : guide.except("check_result")
104
122
  end
105
123
 
106
124
  # How to answer when the request carries some members' last assessments forward; nothing when it carries none.
107
125
  #: () -> Hash[String, untyped]
108
126
  def carried_forward_instruction
109
- return {} unless @members.any? { |member| member["carried_forward"] }
127
+ return {} unless @members.carried_forward?
110
128
 
111
129
  { "carried_forward_instruction" => Prompts.text("assess-every-member/judge-the-set-with-carried-assessments") }
112
130
  end
113
-
114
- # A member's template entry: a fresh assessment to fill in, or, for a member whose last assessment is carried
115
- # forward, the marker that keeps it (D49); either with its check's result when it has a check.
116
- #: (Hash[String, untyped]) -> Hash[String, untyped]
117
- def member_assessment_template(member)
118
- assessed = if member["carried_forward"]
119
- { "member_id" => member.fetch("id"), "carried_forward" => true }
120
- else
121
- { "member_id" => member.fetch("id"), "assessment" => "Your assessment, including its context cost",
122
- "delivery" => "not_observed", "evidence" => member.fetch("evidence") }
123
- end
124
- check = member["check"] or return assessed
125
- template = CheckResultTemplate.new(check, member["check_since_last_audit"],
126
- member.fetch("check_hidden_characters", []))
127
- assessed.merge("check_result" => template.to_h)
128
- end
129
131
  end
130
132
  end
131
133
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "assessment_request"
5
5
  require_relative "audit_changes"
6
+ require_relative "correction_request"
6
7
  require_relative "invocation"
7
8
  require_relative "prior_finding_decisions_result"
8
9
  require_relative "prompts"
@@ -22,11 +23,28 @@ module Principles
22
23
  freeze
23
24
  end
24
25
 
25
- #: (Hash[String, untyped]) -> Hash[String, untyped]
26
+ # An answer's result as submit-answer prints it: a correction request in full, with how to answer it.
27
+ #: (Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
26
28
  def present(output)
29
+ output = correction_request(output) if output.is_a?(CorrectionRequest)
27
30
  output["status"] == "agent_judgement_required" ? request(output) : output
28
31
  end
29
32
 
33
+ # show-answer-check's acceptable result, with the correction's answer an accepted assessment leads to, alone, to
34
+ # save and fill, and how to submit it after the assessment, which outside git writes the open record it is
35
+ # checked against; next_action still ends with the checked answer's submit command (#859). The result is
36
+ # unchanged for any other answer (D81 step 3).
37
+ #: (Hash[String, untyped], Hash[String, untyped] | CorrectionRequest) -> Hash[String, untyped]
38
+ def with_correction_to_fill(acceptable, output)
39
+ return acceptable unless output.is_a?(CorrectionRequest)
40
+
41
+ save = "Once this answer is submitted with the last line's command, save correction_template, the " \
42
+ "correction's answer it leads to, to a file outside the project, such as under $TMPDIR, fill only " \
43
+ "its dispositions, and submit it: #{@invocation.submit_answer(output.request_id)}"
44
+ acceptable.merge("correction_template" => output.template,
45
+ "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
46
+ end
47
+
30
48
  # show-answer-check: the answer passed every check, and what submitting it would write. open_findings_will_print
31
49
  # previews each written-up finding's write_up_opening, and is nil when the record would keep none (#411).
32
50
  # map_entry_changes gives each claimed map entry's changed role and check, left out when there is none (#462).
@@ -35,7 +53,7 @@ module Principles
35
53
  #| ?map_entry_changes: Array[Hash[String, untyped]]) -> Hash[String, untyped]
36
54
  def acceptable(request_id, would_write, answer_file:, open_findings_will_print: nil, map_entry_changes: [])
37
55
  submit = @invocation.submit_answer(request_id, file: answer_file)
38
- waits = "Submitting it writes nothing yet: the audit record is written when the audit completes.\n"
56
+ waits = "Submitting this answer writes nothing yet: the audit record is written when the audit completes.\n"
39
57
  waits = "" unless would_write.empty?
40
58
  result = { "status" => "answer_acceptable", "request_id" => request_id, "would_write" => would_write }
41
59
  result = result.merge("open_findings_will_print" => open_findings_will_print) if open_findings_will_print
@@ -43,30 +61,21 @@ module Principles
43
61
  result.merge("next_action" => "#{waits}Submit the same answer unchanged, as you gave it: #{submit}")
44
62
  end
45
63
 
46
- # start-audit: the assessment request, as a judgement to answer under request_id.
47
- #: (request_id: String, request: AssessmentRequest) -> Hash[String, untyped]
48
- def assessment_request(request_id:, request:)
49
- judgement("assessment", request_id, request.context, request.template)
64
+ # start-audit: the assessment request, as a judgement to answer under its request id.
65
+ #: (AssessmentRequest) -> Hash[String, untyped]
66
+ def assessment_request(request)
67
+ judgement("assessment", request)
50
68
  end
51
69
 
52
- # The correction request that follows an assessment with findings: one disposition for each, with a guide
53
- # to every disposition's shape (#414). It says what was stored, so an assessment submitted twice plainly
54
- # replaced nothing: in git nothing is, and outside git, where basis has no base commit, the open record
55
- # keeps what the audit began from.
56
- # placeholders is the text the template leaves in each field the agent writes (#725).
57
- #: (request_id: String, principle_id: String, findings: Array[untyped], basis: Hash[String, untyped],
58
- #| placeholders: Hash[String, String]) -> Hash[String, untyped]
59
- def correction_request(request_id:, principle_id:, findings:, basis:, placeholders:)
60
- context = { "principle_id" => principle_id, "findings" => findings,
61
- "question" => Prompts.text("dispose-of-each-finding/fix-or-record-each-finding"),
62
- "answer_guide" => Prompts.data("dispose-of-each-finding/answer-guide") }
63
- template = { "basis" => basis, "dispositions" => findings.map do |finding|
64
- { "finding_id" => finding["id"], "action" => nil, "reason" => placeholders.fetch("reason"),
65
- "changed_members" => [], "evidence" => [],
66
- "reassessment" => placeholders.fetch("reassessment"), "recorded_at" => nil,
67
- "waits_on" => nil }
68
- end }
69
- judgement("correction", request_id, context, template).merge("stored" => stored(basis["base_commit"]))
70
+ # start-audit --as template: the assessment's answer alone, to fill and submit (D81 step 1).
71
+ #: (AssessmentRequest) -> Hash[String, untyped]
72
+ def answer_to_fill(request) = request.template_to_fill
73
+
74
+ # submit-answer: the correction request that follows an assessment with findings, as a judgement to answer
75
+ # under its request id, saying what submitting the assessment stored.
76
+ #: (CorrectionRequest) -> Hash[String, untyped]
77
+ def correction_request(request)
78
+ judgement("correction", request).merge("stored" => request.stored)
70
79
  end
71
80
 
72
81
  # A completed audit: its resolved and open findings, the files to commit and, in git, each changed
@@ -96,24 +105,11 @@ module Principles
96
105
 
97
106
  private
98
107
 
99
- # What submitting the assessment stored, and what submitting it again would do: in git, where the
100
- # audit has a base commit, nothing; outside git, the open record.
101
- #: (String?) -> String
102
- def stored(base_commit)
103
- again = "Submitting the same assessment again prints this same request"
104
- unless base_commit
105
- return "This audit's open record, listed under wrote when it was first written, keeps what the audit " \
106
- "began from. #{again} and leaves that record as it is."
107
- end
108
-
109
- "Nothing is stored yet: this request was computed from your assessment and the project. #{again} and " \
110
- "replaces nothing; the audit record is written when the audit completes."
111
- end
112
-
113
- #: (String, String, Hash[String, untyped], Hash[String, untyped]) -> Hash[String, untyped]
114
- def judgement(phase, request_id, context, template)
115
- { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => phase,
116
- "context" => context, "response_template" => { "request_id" => request_id }.merge(template),
108
+ # request as a judgement to answer in phase, under its id, which its template's head also gives.
109
+ #: (String, AssessmentRequest | CorrectionRequest) -> Hash[String, untyped]
110
+ def judgement(phase, request)
111
+ { "status" => "agent_judgement_required", "request_id" => request.request_id, "phase" => phase,
112
+ "context" => request.context, "response_template" => request.template,
117
113
  "limits" => Prompts.text("answer-any-judgement-request/what-a-self-audit-cannot-show") }
118
114
  end
119
115