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
@@ -6,21 +6,31 @@ require_relative "prompts"
6
6
  module Principles
7
7
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
8
8
  module Views
9
- # The check_result a checked member's assessment template starts with: its command, and a not_run_reason
10
- # that says what to do before replacing it. A check no audit has run, or one changed since, is reviewed
11
- # before it runs (#227), and any hidden character it holds is named where that decision is made (#260).
9
+ # The check_result a checked member's assessment template starts with: its command, an exit_status placeholder
10
+ # that says what to do before replacing it with the run's status, and not_run_reason, the alternative, as a
11
+ # placeholder an answer leaves as printed when it reports a run (#993). A check no audit has run, or one changed
12
+ # since, is reviewed before it runs (#227), so it also gives review_basis to fill (D63), and any hidden character
13
+ # it holds is named where that decision is made (#260).
12
14
  class CheckResultTemplate
13
- #: (String, Hash[String, untyped]?, ?Array[String]) -> void
14
- def initialize(check, since_last_audit, hidden_characters = [])
15
+ # reviewed_placeholders gives the text of not_run_reason and review_basis, which an answer leaves as printed to
16
+ # give neither, for a check reviewed before it runs; unchanged_placeholders gives it for one the last audit ran,
17
+ # whose review_basis left as printed keeps the line that audit kept (#1010).
18
+ #: (String, Hash[String, untyped]?, ?Array[String], reviewed_placeholders: Hash[String, String],
19
+ #| unchanged_placeholders: Hash[String, String]) -> void
20
+ def initialize(check, since_last_audit, hidden_characters = [], reviewed_placeholders:, unchanged_placeholders:)
15
21
  @check = check
16
22
  @since_last_audit = since_last_audit
17
23
  @hidden_characters = hidden_characters
24
+ unchanged = since_last_audit&.fetch("status") == "unchanged"
25
+ @placeholders = unchanged ? unchanged_placeholders : reviewed_placeholders #: Hash[String, String]
18
26
  freeze
19
27
  end
20
28
 
21
29
  #: () -> Hash[String, untyped]
22
30
  def to_h
23
- { "command" => @check, "not_run_reason" => [hidden_characters, not_run_reason].compact.join(" ") }
31
+ { "command" => @check, "exit_status" => [hidden_characters, run_and_report].compact.join(" "),
32
+ "not_run_reason" => @placeholders.fetch("not_run_reason"),
33
+ "review_basis" => @placeholders.fetch("review_basis") }
24
34
  end
25
35
 
26
36
  private
@@ -33,10 +43,10 @@ module Principles
33
43
  characters: @hidden_characters.join("; "))
34
44
  end
35
45
 
36
- # What to do before replacing the field, then that a named check runs at every full audit, which holds for
46
+ # What to do before replacing exit_status, then that a named check runs at every full audit, which holds for
37
47
  # each status.
38
48
  #: () -> String
39
- def not_run_reason
49
+ def run_and_report
40
50
  [*steps, Prompts.text("assess-every-member/run-a-named-check-at-every-full-audit")].join(" ")
41
51
  end
42
52
 
@@ -48,11 +58,22 @@ module Principles
48
58
  case @since_last_audit&.fetch("status")
49
59
  when "unchanged" then [Prompts.text("assess-every-member/run-the-check-then-report-it"), *kept_review]
50
60
  when "changed"
51
- [Prompts.text("assess-every-member/have-a-changed-check-reviewed-before-running-it"), run_reviewed]
52
- else [Prompts.text("assess-every-member/have-a-new-check-reviewed-before-running-it"), run_reviewed]
61
+ [Prompts.text("assess-every-member/have-a-changed-check-reviewed-before-running-it",
62
+ changed_in: commit_clause(": commit %s changed it")), run_reviewed]
63
+ else
64
+ [Prompts.text("assess-every-member/have-a-new-check-reviewed-before-running-it",
65
+ set_in: commit_clause("; commit %s set it")), run_reviewed]
53
66
  end
54
67
  end
55
68
 
69
+ # The commit that made the check what it is now, stated in the placeholder itself, since the template printed
70
+ # alone has no context beside it (#1024); nothing outside git, or when no commit holds it.
71
+ #: (String) -> String
72
+ def commit_clause(format)
73
+ commit = @since_last_audit&.fetch("changed_in", nil)
74
+ commit ? format(format, commit) : ""
75
+ end
76
+
56
77
  # That a run keeps the line the last audit's review rested on, quoted with since when, unless a new one is
57
78
  # given, so whether it still holds can be judged from the template (#849); a record from before D63 kept none,
58
79
  # so there is nothing to say (#826).
@@ -0,0 +1,64 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answer_head"
5
+ require_relative "prompts"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # The correction request that follows an assessment with findings: one disposition for each, with a guide to
11
+ # every disposition's shape (#414), and what submitting the assessment stored.
12
+ class CorrectionRequest
13
+ # head is what the answer hands back unchanged, the request's id and the basis the correction depends on;
14
+ # placeholders is the text the template leaves in each field the agent writes (#725).
15
+ #: (head: AnswerHead, principle_id: String, findings: Array[untyped], placeholders: Hash[String, String]) -> void
16
+ def initialize(head:, principle_id:, findings:, placeholders:)
17
+ @head = head
18
+ @principle_id = principle_id
19
+ @findings = findings
20
+ @placeholders = placeholders
21
+ freeze
22
+ end
23
+
24
+ # The id the request is answered under.
25
+ #: () -> String
26
+ def request_id = @head.request_id
27
+
28
+ # The findings to dispose of, the question and a guide to every disposition's shape.
29
+ #: () -> Hash[String, untyped]
30
+ def context
31
+ { "principle_id" => @principle_id, "findings" => @findings,
32
+ "question" => Prompts.text("dispose-of-each-finding/fix-or-record-each-finding"),
33
+ "answer_guide" => Prompts.data("dispose-of-each-finding/answer-guide") }
34
+ end
35
+
36
+ # The answer to fill in, as submit-answer prints it and show-answer-check prints it alone: one disposition for
37
+ # each finding, each action the placeholder that says what it may be and what each adds, so both print one
38
+ # template (D81 step 3, #1011).
39
+ #: () -> Hash[String, untyped]
40
+ def template
41
+ @head.leading("dispositions" => @findings.map do |finding|
42
+ { "finding_id" => finding["id"], "action" => @placeholders.fetch("action"),
43
+ "reason" => @placeholders.fetch("reason"), "changed_members" => [], "evidence" => [],
44
+ "reassessment" => @placeholders.fetch("reassessment"), "recorded_at" => nil, "waits_on" => nil }
45
+ end)
46
+ end
47
+
48
+ # What submitting the assessment stored, and what submitting it again would do, so an assessment submitted
49
+ # twice plainly replaced nothing: in git, where the audit has a base commit, nothing; outside git, the open
50
+ # record, which keeps what the audit began from.
51
+ #: () -> String
52
+ def stored
53
+ again = "Submitting the same assessment again prints this same request"
54
+ unless @head.based_on_a_commit?
55
+ return "This audit's open record, listed under wrote when it was first written, keeps what the audit " \
56
+ "began from. #{again} and leaves that record as it is."
57
+ end
58
+
59
+ "Nothing is stored yet: this request was computed from your assessment and the project. #{again} and " \
60
+ "replaces nothing; the audit record is written when the audit completes."
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,71 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "invocation"
5
+ require_relative "prompts"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # The first full audit's place after mapping: a commit can supply the members' baseline in git, while the
11
+ # keeping principle also needs an own principle whose keeping it can judge.
12
+ class FirstAudit
13
+ #: (Invocation, in_git: bool) -> void
14
+ def initialize(invocation, in_git:)
15
+ @invocation = invocation
16
+ @in_git = in_git
17
+ freeze
18
+ end
19
+
20
+ # The step after adding members, since the next add-member remains the command to answer with.
21
+ #: (String, ?keeps_others_held: bool) -> String
22
+ def after_mapping(id, keeps_others_held: false)
23
+ return after_keeping_mapping(id) if keeps_others_held
24
+
25
+ if @in_git
26
+ return "When the map lists every member, commit it: list-member-problems then reports any change to a " \
27
+ "member since that commit. Only a full audit judges whether they reinforce the principle.\n" \
28
+ "To start it when you choose: #{start_audit(id)}"
29
+ end
30
+
31
+ "When the map lists every member, start the audit. It judges whether they reinforce the principle, and " \
32
+ "gives each member the baseline list-member-problems compares it with.\nTo start it: #{start_audit(id)}"
33
+ end
34
+
35
+ # The keeping audit waits until there is a project's own principle for it to keep held.
36
+ #: (String, existing_principles: Array[Hash[String, untyped]]) -> String
37
+ def keeping(id, existing_principles:)
38
+ if existing_principles.empty?
39
+ return "This principle's first full audit judges whether the keeping works, so leave it until one of the " \
40
+ "project's own principles is mapped.\n" \
41
+ "To find the first of them: #{@invocation.in_project("list-candidate-files")}"
42
+ end
43
+
44
+ "This principle's first full audit judges whether the keeping works for the principles under " \
45
+ "existing_principles.\n" \
46
+ "To start it: #{@invocation.in_project("start-audit", id)}"
47
+ end
48
+
49
+ private
50
+
51
+ # Adding the keeping passage retains setup's first-own-principle prerequisite.
52
+ #: (String) -> String
53
+ def after_keeping_mapping(id)
54
+ baseline = if @in_git
55
+ "When the map lists every member, commit it: that commit is the members' baseline until an audit."
56
+ else
57
+ "Outside git, the first full audit gives each member its baseline."
58
+ end
59
+ Prompts.text("set-principles-up/first-keeping-audit-after-own-principle",
60
+ baseline: baseline,
61
+ find: @invocation.in_project("list-candidate-files"),
62
+ audit: start_audit(id))
63
+ end
64
+
65
+ #: (String) -> String
66
+ def start_audit(id)
67
+ @invocation.in_project("start-audit", id)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -79,7 +79,8 @@ module Principles
79
79
  "## #{heading}\n\n#{entries.map { |usage, summary| "- `#{usage}`: #{summary}" }.join("\n")}"
80
80
  end
81
81
  Prompts.markdown("learn-what-a-command-does/every-command-and-how-they-chain",
82
- version: @version, commands: commands.join("\n\n"), executable: @executable)
82
+ version: @version, commands: commands.join("\n\n"), executable: @executable,
83
+ project_selection: Prompts.text("learn-what-a-command-does/select-the-project-root"))
83
84
  end
84
85
  end
85
86
 
@@ -101,7 +102,7 @@ module Principles
101
102
  numbered = @steps.each_with_index.map { |step, index| "#{index + 1}. #{step_text(step)}" }
102
103
  ["# #{@executable} #{@usage}", Prompts.markdown(@prompt, executable: @executable), @writes, "## Steps",
103
104
  numbered.join("\n"), "A step that fails prints a refusal with its code and a repair.",
104
- "`--project PATH` is optional: it defaults to the current directory."].join("\n\n")
105
+ Prompts.text("learn-what-a-command-does/select-the-project-root")].join("\n\n")
105
106
  end
106
107
 
107
108
  private
@@ -10,9 +10,15 @@ module Principles
10
10
  module Views
11
11
  # How a full audit's request shows the members to check against the principle's activation (#355 slice 3).
12
12
  class LoadsToCheckResult
13
- # listed is the members to check, nil when there are none, and id the principle they belong to.
14
- #: (Invocation, Hash[String, untyped]?, String) -> void
15
- def initialize(invocation, listed, id)
13
+ # What a decision may be, as the answer printed alone says where it is written (#746).
14
+ DECISION = "accepted, with reason saying why the member loads as it does; if the activation is wrong " \
15
+ "instead, change it and start the audit again" #: String
16
+
17
+ # listed is the members to check, nil when there are none, and id the principle they belong to; placeholders
18
+ # is the text the template alone prints in each field of a decision beside it, which left is not given (#994).
19
+ #: (Invocation, Hash[String, untyped]?, String, placeholders: Hash[String, String]) -> void
20
+ def initialize(invocation, listed, id, placeholders:)
21
+ @placeholders = placeholders
16
22
  @invocation = invocation
17
23
  @listed = listed
18
24
  @id = id
@@ -28,7 +34,8 @@ module Principles
28
34
  decisions = listed.fetch("rows").map { |row| { "member_id" => row.fetch("member_id"), "decision" => nil } }
29
35
  RequestPart.new(shown: { "loads_to_check_against_activation" => listed,
30
36
  "loads_to_check_instruction" => instruction },
31
- slots: { "loading_decisions" => decisions })
37
+ slots: { "loading_decisions" => decisions },
38
+ help: { "loading_decisions" => { "decision" => DECISION, **@placeholders } })
32
39
  end
33
40
 
34
41
  private
@@ -0,0 +1,31 @@
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 add-member's result needs to know of the map a member joined, beyond the map itself: whether its
8
+ # principle keeps the others held, which changes the step after mapping (D71), and whether a full audit's
9
+ # correction may be open on it, so that the member may fix one of its findings (D72, #1023), and whether to repeat
10
+ # what to do after mapping: with a principle's first member, or in git the first since the map's last commit, so
11
+ # members mapped in one sitting do not each repeat it (#1025).
12
+ class MapAddedTo
13
+ #: bool
14
+ attr_reader :keeps_others_held
15
+
16
+ #: bool
17
+ attr_reader :correction_may_be_open
18
+
19
+ #: bool
20
+ attr_reader :reminded
21
+
22
+ #: (?keeps_others_held: bool, ?correction_may_be_open: bool, ?reminded: bool) -> void
23
+ def initialize(keeps_others_held: false, correction_may_be_open: false, reminded: true)
24
+ @keeps_others_held = keeps_others_held
25
+ @correction_may_be_open = correction_may_be_open
26
+ @reminded = reminded
27
+ freeze
28
+ end
29
+ end
30
+ end
31
+ end
@@ -4,7 +4,9 @@
4
4
  require_relative "invocation"
5
5
  require_relative "printed_principle"
6
6
  require_relative "lines_shared_with_member"
7
+ require_relative "map_added_to"
7
8
  require_relative "activation_in_hand"
9
+ require_relative "first_audit"
8
10
  require_relative "prompts"
9
11
 
10
12
  module Principles
@@ -60,15 +62,13 @@ module Principles
60
62
  end
61
63
 
62
64
  # shared says which members share a line with the new one; added lists them only when there are some, as it
63
- # carries a check only when one is named.
64
- #: (PrintedPrinciple, added: Hash[String, untyped], ?shared: LinesSharedWithMember) -> Hash[String, untyped]
65
- def member_added(principle, added:, shared: LinesSharedWithMember.new)
65
+ # carries a check only when one is named. joined is what the result says of the map the member joined.
66
+ #: (PrintedPrinciple, added: Hash[String, untyped], ?shared: LinesSharedWithMember, ?joined: MapAddedTo)
67
+ #| -> Hash[String, untyped]
68
+ def member_added(principle, added:, shared: LinesSharedWithMember.new, joined: MapAddedTo.new)
66
69
  added = added.merge(shared.to_h)
67
- shown = @invocation.in_project("show-principle", principle.id)
68
- question(principle, "#{span(added)}#{shared.note}Add the next member the same way. Commit " \
69
- "#{principle.file} as it changes, so the project's history shows each change; in git, " \
70
- "start-audit refuses a map that is not committed.\n" \
71
- "To see the map so far: #{shown}\n#{start_when_mapped(principle.id)}",
70
+ question(principle, "#{span(added)}#{shared.note}Add the next member the same way. " \
71
+ "#{after_the_member(principle, added.fetch("id"), joined)}".rstrip,
72
72
  add_member_command(principle.id), shown: { "member_count" => principle.members.length })
73
73
  .merge("added" => added)
74
74
  end
@@ -121,12 +121,40 @@ module Principles
121
121
  #: (PrintedPrinciple, removed: String) -> Hash[String, untyped]
122
122
  def member_removed(principle, removed:)
123
123
  question(principle, "Removed #{removed}. Add or remove members until the map is right.\n" \
124
- "#{start_when_mapped(principle.id)}",
124
+ "#{FirstAudit.new(@invocation, in_git: @in_git).after_mapping(principle.id)}",
125
125
  add_member_command(principle.id))
126
126
  end
127
127
 
128
128
  private
129
129
 
130
+ # What add-member's question says after the member it added, id, as joined says of the map: how a fix claims
131
+ # it while a correction may be open, then what to do after mapping, each only when joined says to remind, once
132
+ # per sitting (#1025, #1057).
133
+ #: (PrintedPrinciple, String, MapAddedTo) -> String
134
+ def after_the_member(principle, id, joined)
135
+ "#{claimed_by_a_fix(id) if joined.correction_may_be_open && joined.reminded}" \
136
+ "#{after_adding(principle, keeps_others_held: joined.keeps_others_held) if joined.reminded}"
137
+ end
138
+
139
+ # How a member added while a correction is open joins it: a fix claims it, and the next full audit assesses it
140
+ # (D72). It ends its own line, since it ends with a command.
141
+ #: (String) -> String
142
+ def claimed_by_a_fix(member)
143
+ "If you hold a correction request from submit-answer (phase correction) and this member fixes one of its " \
144
+ "findings, name #{member} in the changed_members of the fixed disposition; the next full audit assesses " \
145
+ "it.\nTo submit the correction instead: #{@invocation.submit_answer("REQUEST")}\n"
146
+ end
147
+
148
+ # What add-member says after the member it added: to commit the map as it changes, how to see it, and the full
149
+ # audit's place once it lists every member.
150
+ #: (PrintedPrinciple, keeps_others_held: bool) -> String
151
+ def after_adding(principle, keeps_others_held:)
152
+ "Commit #{principle.file} as it changes, so the project's history shows each change; in git, start-audit " \
153
+ "refuses a map that is not committed.\n" \
154
+ "To see the map so far: #{@invocation.in_project("show-principle", principle.id)}\n" \
155
+ "#{FirstAudit.new(@invocation, in_git: @in_git).after_mapping(principle.id, keeps_others_held:)}"
156
+ end
157
+
130
158
  # The lines a member spans, said so that a passage cut short shows; it ends with a space.
131
159
  #: (Hash[String, untyped]) -> String
132
160
  def span(member)
@@ -147,19 +175,6 @@ module Principles
147
175
  @invocation.in_project("start-audit", id)
148
176
  end
149
177
 
150
- # The step after adding members, as the question's last line, since answer_with is the next add-member.
151
- #: (String) -> String
152
- def start_when_mapped(id)
153
- if @in_git
154
- return "When the map lists every member, commit it: list-member-problems then reports any change to a " \
155
- "member since that commit. Only a full audit judges whether they reinforce the principle.\n" \
156
- "To start it when you choose: #{start_audit(id)}"
157
- end
158
-
159
- "When the map lists every member, start the audit. It judges whether they reinforce the principle, and " \
160
- "gives each member the baseline list-member-problems compares it with.\nTo start it: #{start_audit(id)}"
161
- end
162
-
163
178
  #: (String) -> String
164
179
  def add_member_command(id)
165
180
  @invocation.in_project("add-member", id, usage: ADD_MEMBER_USAGE)
@@ -5,6 +5,7 @@ require "json"
5
5
  require_relative "invocation"
6
6
  require_relative "problem_lines"
7
7
  require_relative "prompts"
8
+ require_relative "record_waiting_on_an_upgrade"
8
9
  require_relative "visible_text"
9
10
 
10
11
  module Principles
@@ -12,8 +13,9 @@ module Principles
12
13
  module Views
13
14
  # list-member-problems --commits-after COMMIT --hook-event EVENT: the whole JSON the plugin's after-commit hook
14
15
  # prints for Claude Code, which puts its additionalContext beside the Bash call's result (D73), or nothing at all.
15
- # Claude Code asks for that text to state facts, not to give orders, so it says what the commits changed and
16
- # which command shows more.
16
+ # Claude Code asks for that text to state facts, not to give orders, so it says what the commits changed,
17
+ # which command shows more and which skill says how to audit them (#986). It names that skill as Claude Code
18
+ # lists a plugin's skill, principles:map-and-audit, which holds since only that host's hook prints this JSON.
17
19
  class MembersACommitChanged
18
20
  NOTHING = Lines.new(stdout: "", stderr: "", status: 0).freeze #: Lines
19
21
 
@@ -23,14 +25,14 @@ module Principles
23
25
  freeze
24
26
  end
25
27
 
26
- # changed is each member the commits changed, as list-member-problems lists it; others is how many other
27
- # changed members it still lists.
28
- #: (String, Array[Hash[String, untyped]], others: Integer) -> Lines
29
- def changed(event, changed, others:)
30
- rows = changed.map { |member| ProblemLines.new(@invocation).row(member) }
31
- reported(event, [Prompts.text("report-after-a-commit/the-commits-changed-these-members"), *rows,
32
- *still_listed(others), Prompts.text("report-after-a-commit/this-command-shows-each-one"),
33
- command])
28
+ # changed is each member the commits changed, as list-member-problems lists it; others is how many other changed
29
+ # members it still lists. Those it marks waiting_on_an_upgrade are named apart, with the waits that say why, and
30
+ # no audit to run (D85 V8, #1066).
31
+ #: (String, Array[Hash[String, untyped]], others: Integer, ?waits: Array[RecordWaitingOnAnUpgrade]) -> Lines
32
+ def changed(event, changed, others:, waits: [])
33
+ waiting, auditable = changed.partition { |member| member["waiting_on_an_upgrade"] }
34
+ reported(event, [*(to_audit(auditable, others) unless auditable.empty?),
35
+ *(waiting_lines(waiting, waits) unless waiting.empty?)])
34
36
  end
35
37
 
36
38
  # A refusal with code, which the commits could have caused.
@@ -42,6 +44,24 @@ module Principles
42
44
 
43
45
  private
44
46
 
47
+ # The members to audit, as rows, then what shows more and the skill that says how to audit them.
48
+ #: (Array[Hash[String, untyped]], Integer) -> Array[String]
49
+ def to_audit(changed, others)
50
+ [Prompts.text("report-after-a-commit/the-commits-changed-these-members"), *rows(changed),
51
+ *still_listed(others), Prompts.text("report-after-a-commit/this-command-shows-each-one"), command,
52
+ Prompts.text("report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members")]
53
+ end
54
+
55
+ # The members whose audits wait on an upgrade, as rows, then each wait's line, which says how to update.
56
+ #: (Array[Hash[String, untyped]], Array[RecordWaitingOnAnUpgrade]) -> Array[String]
57
+ def waiting_lines(waiting, waits)
58
+ [Prompts.text("report-after-a-commit/the-commits-changed-these-members-waiting-on-an-upgrade"),
59
+ *rows(waiting), *waits.map(&:to_s)]
60
+ end
61
+
62
+ #: (Array[Hash[String, untyped]]) -> Array[String]
63
+ def rows(members) = members.map { |member| ProblemLines.new(@invocation).row(member) }
64
+
45
65
  # The line saying how many other changed members list-member-problems still lists, or none when it lists none.
46
66
  #: (Integer) -> Array[String]
47
67
  def still_listed(others)
@@ -4,6 +4,7 @@
4
4
  require_relative "invocation"
5
5
  require_relative "meta_principle_passage"
6
6
  require_relative "printed_principle"
7
+ require_relative "first_audit"
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.
@@ -150,20 +151,8 @@ module Principles
150
151
  "This principle's first full audit gives the passage's member its baseline, since this project " \
151
152
  "is not in git."
152
153
  end
153
- [baseline, first_audit(id, existing_principles)].join(" ")
154
- end
155
-
156
- #: (String, Array[Hash[String, untyped]]) -> String
157
- def first_audit(id, existing_principles)
158
- if existing_principles.empty?
159
- return "This principle's first full audit judges whether the keeping works, so leave it until one of the " \
160
- "project's own principles is mapped.\n" \
161
- "To find the first of them: #{@invocation.in_project("list-candidate-files")}"
162
- end
163
-
164
- "This principle's first full audit judges whether the keeping works for the principles under " \
165
- "existing_principles.\n" \
166
- "To start it: #{@invocation.in_project("start-audit", id)}"
154
+ [baseline, FirstAudit.new(@invocation, in_git: @in_git)
155
+ .keeping(id, existing_principles: existing_principles)].join(" ")
167
156
  end
168
157
  end
169
158
  end
@@ -5,6 +5,8 @@ require_relative "invocation"
5
5
  require_relative "printed_principle"
6
6
  require_relative "member_repairs"
7
7
  require_relative "prompts"
8
+ require_relative "record_waiting_on_an_upgrade"
9
+ require_relative "../prose_list"
8
10
 
9
11
  module Principles
10
12
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -32,17 +34,14 @@ module Principles
32
34
  end
33
35
 
34
36
  # list-principles: each entry is { "id", "description", "members_by_freshness" }. Until principles is set_up,
35
- # its next_action puts setting it up first.
36
- #: (Array[Hash[String, untyped]], set_up: bool) -> Hash[String, untyped]
37
- def listing(entries, set_up:)
38
- next_action = if entries.empty?
39
- "To map one, start with: #{@invocation.in_project("list-candidate-files")}"
40
- else
41
- "To see a principle's members: #{@invocation.in_project("show-principle", usage: "ID")}\n" \
42
- "To audit it: #{@invocation.in_project("start-audit", usage: "ID")}"
43
- end
37
+ # its next_action puts setting it up first. waiting is each principle whose audits wait on an upgrade, which it
38
+ # names, with how to update said once, and an audit is offered only when one is left to audit (#1067, #1081).
39
+ #: (Array[Hash[String, untyped]], set_up: bool, ?waiting: Array[RecordWaitingOnAnUpgrade],
40
+ #| ?one_to_audit: bool) -> Hash[String, untyped]
41
+ def listing(entries, set_up:, waiting: [], one_to_audit: true)
44
42
  first = set_up ? [] : [set_up_first]
45
- { "principles" => entries, "next_action" => [*first, next_action].join("\n") }
43
+ next_action = [*first, *listed_next_action(entries, waiting, one_to_audit)]
44
+ { "principles" => entries, "next_action" => next_action.join("\n") }
46
45
  end
47
46
 
48
47
  # list-principles' note on the meta-principle's map, kept in file, when it has no members, with the two ways on
@@ -57,6 +56,24 @@ module Principles
57
56
 
58
57
  private
59
58
 
59
+ # What list-principles' next_action offers after setting up: mapping one when none is listed, else showing one,
60
+ # auditing one when one is left to audit, and the principles whose audits wait on an upgrade.
61
+ #: (Array[Hash[String, untyped]], Array[RecordWaitingOnAnUpgrade], bool) -> Array[String]
62
+ def listed_next_action(entries, waiting, one_to_audit)
63
+ return ["To map one, start with: #{@invocation.in_project("list-candidate-files")}"] if entries.empty?
64
+
65
+ audit = "To audit it: #{@invocation.in_project("start-audit", usage: "ID")}" if one_to_audit
66
+ waits = waited_on(waiting) unless waiting.empty?
67
+ ["To see a principle's members: #{@invocation.in_project("show-principle", usage: "ID")}", audit, waits].compact
68
+ end
69
+
70
+ # The principles whose audits wait on an upgrade, and how to update, once for each way the records name.
71
+ #: (Array[RecordWaitingOnAnUpgrade]) -> String
72
+ def waited_on(waiting)
73
+ ["The audits of #{ProseList.new(waiting.map(&:principle))} wait on an upgrade.", *waiting.map(&:update).uniq]
74
+ .join(" ")
75
+ end
76
+
60
77
  # The line that puts setting principles up first, ending in its command.
61
78
  #: () -> String
62
79
  def set_up_first
@@ -6,29 +6,28 @@ module Principles
6
6
  module Views
7
7
  # How a completed full audit's result says what it decided about each prior finding (D35).
8
8
  class PriorFindingDecisionsResult
9
- # kept_ids are the prior findings it kept and closed those it closed; dropped is any pointer a kept one's
10
- # decision dropped (#374), waits_on_dropped any waits_on it dropped, with null or by accepting it (D52), and
11
- # evidence_replaced each kept evidence item a decision gave a new place, as it was and is now (D70).
12
- #: (kept_ids: Array[String], closed: Array[Hash[String, untyped]], dropped: Array[Hash[String, untyped]],
13
- #| waits_on_dropped: Array[Hash[String, untyped]], evidence_replaced: Array[Hash[String, untyped]]) -> void
14
- def initialize(kept_ids:, closed:, dropped:, waits_on_dropped:, evidence_replaced:)
9
+ # kept_ids are the prior findings it kept and closed those it closed; changed is what the decisions changed of
10
+ # the findings kept, each list by the name the result gives it after prior_findings_: pointers_dropped, any
11
+ # pointer a decision dropped (#374), waits_on_dropped, any waits_on it dropped, with null or by accepting it
12
+ # (D52), evidence_replaced, each kept evidence item a decision gave a new place, as it was and is now (D70), and
13
+ # problems_restated, each problem a decision restated, as it was and is now (D82).
14
+ #: (kept_ids: Array[String], closed: Array[Hash[String, untyped]],
15
+ #| changed: Hash[String, Array[Hash[String, untyped]]]) -> void
16
+ def initialize(kept_ids:, closed:, changed:)
15
17
  @kept_ids = kept_ids
16
18
  @closed = closed
17
- @dropped = dropped
18
- @waits_on_dropped = waits_on_dropped
19
- @evidence_replaced = evidence_replaced
19
+ @changed = changed
20
20
  freeze
21
21
  end
22
22
 
23
- # output, with these decisions added; unchanged when there were no prior findings to decide.
23
+ # output, with these decisions added, and each list of changes that is not empty; unchanged when there were no
24
+ # prior findings to decide.
24
25
  #: (Hash[String, untyped]) -> Hash[String, untyped]
25
26
  def added_to(output)
26
27
  return output if @kept_ids.empty? && @closed.empty?
27
28
 
28
- decided = output.merge("prior_findings_kept" => @kept_ids, "prior_findings_closed" => @closed)
29
- decided = decided.merge("prior_findings_pointers_dropped" => @dropped) unless @dropped.empty?
30
- decided = decided.merge("prior_findings_waits_on_dropped" => @waits_on_dropped) unless @waits_on_dropped.empty?
31
- @evidence_replaced.empty? ? decided : decided.merge("prior_findings_evidence_replaced" => @evidence_replaced)
29
+ changes = @changed.reject { |_, list| list.empty? }.transform_keys { |name| "prior_findings_#{name}" }
30
+ output.merge("prior_findings_kept" => @kept_ids, "prior_findings_closed" => @closed, **changes)
32
31
  end
33
32
  end
34
33
  end
@@ -11,9 +11,12 @@ module Principles
11
11
  class PriorFindingsResult
12
12
  # prior is each finding the last audit deferred or accepted, as the request lists it; last_audited_commit is the
13
13
  # commit each evidence item's changed_since_last_audit compares against, or nil when none says (#858).
14
- #: (Array[Hash[String, untyped]], ?last_audited_commit: String?) -> void
15
- def initialize(prior, last_audited_commit: nil)
14
+ # placeholders is the text the answer printed alone gives the decision, naming what it may be (#746), and each
15
+ # field a decision may give, which an answer leaves as printed to give none (#994).
16
+ #: (Array[Hash[String, untyped]], placeholders: Hash[String, untyped], ?last_audited_commit: String?) -> void
17
+ def initialize(prior, placeholders:, last_audited_commit: nil)
16
18
  @prior = prior
19
+ @placeholders = placeholders
17
20
  @last_audited_commit = last_audited_commit
18
21
  freeze
19
22
  end
@@ -26,7 +29,8 @@ module Principles
26
29
 
27
30
  RequestPart.new(shown: { "prior_findings" => @prior.map { |finding| shown(finding) },
28
31
  "prior_findings_instruction" => instruction },
29
- slots: { "prior_finding_decisions" => @prior.map { |finding| decision(finding) } })
32
+ slots: { "prior_finding_decisions" => @prior.map { |finding| decision(finding) } },
33
+ help: { "prior_finding_decisions" => @placeholders })
30
34
  end
31
35
 
32
36
  private