principles 0.0.4 → 0.0.5

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/cli.rb +3 -1
  3. data/lib/principles/command_line.rb +35 -7
  4. data/lib/principles/command_routes.rb +4 -3
  5. data/lib/principles/controllers/acknowledgement.rb +80 -14
  6. data/lib/principles/controllers/answer.rb +42 -75
  7. data/lib/principles/controllers/answer_phase.rb +54 -0
  8. data/lib/principles/controllers/assessment.rb +33 -9
  9. data/lib/principles/controllers/audit.rb +17 -6
  10. data/lib/principles/controllers/audit_completion.rb +6 -4
  11. data/lib/principles/controllers/command.rb +3 -2
  12. data/lib/principles/controllers/correction.rb +19 -9
  13. data/lib/principles/controllers/full_audit_request.rb +10 -0
  14. data/lib/principles/controllers/inventory.rb +25 -20
  15. data/lib/principles/controllers/member_problems_report.rb +11 -4
  16. data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
  17. data/lib/principles/controllers/members_to_assess.rb +20 -12
  18. data/lib/principles/controllers/repoint.rb +18 -22
  19. data/lib/principles/data/bounded_file.rb +9 -4
  20. data/lib/principles/data/command-steps.json +9 -9
  21. data/lib/principles/data/project_files.rb +11 -8
  22. data/lib/principles/data/schema_check.rb +16 -6
  23. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
  24. data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
  25. data/lib/principles/data/schemas/audit-record.schema.json +10 -1
  26. data/lib/principles/data/schemas/command-steps.schema.json +2 -1
  27. data/lib/principles/invocation_options.rb +1 -1
  28. data/lib/principles/models/acknowledgement.rb +73 -84
  29. data/lib/principles/models/acknowledgement_refusal.rb +90 -0
  30. data/lib/principles/models/answer_place.rb +4 -0
  31. data/lib/principles/models/assessment_answer.rb +0 -45
  32. data/lib/principles/models/assessment_left_as_printed.rb +81 -0
  33. data/lib/principles/models/audit_record.rb +9 -17
  34. data/lib/principles/models/audit_records.rb +19 -16
  35. data/lib/principles/models/candidate_files.rb +30 -7
  36. data/lib/principles/models/candidate_inventory.rb +23 -6
  37. data/lib/principles/models/candidate_listing.rb +12 -3
  38. data/lib/principles/models/candidate_outline.rb +195 -0
  39. data/lib/principles/models/carried_member.rb +42 -0
  40. data/lib/principles/models/check_since_last_audit.rb +16 -3
  41. data/lib/principles/models/command_steps.rb +17 -1
  42. data/lib/principles/models/declared_map_changes.rb +5 -4
  43. data/lib/principles/models/frontmatter_fields.rb +9 -8
  44. data/lib/principles/models/instruction_named.rb +35 -0
  45. data/lib/principles/models/left_as_printed.rb +39 -0
  46. data/lib/principles/models/member_assessments.rb +9 -31
  47. data/lib/principles/models/member_file.rb +35 -11
  48. data/lib/principles/models/member_hashes_as_written.rb +10 -6
  49. data/lib/principles/models/member_lines.rb +63 -15
  50. data/lib/principles/models/member_problems.rb +24 -18
  51. data/lib/principles/models/member_repair_moves.rb +54 -0
  52. data/lib/principles/models/missing_files.rb +2 -2
  53. data/lib/principles/models/open_findings_elsewhere.rb +4 -0
  54. data/lib/principles/models/other_templates_placeholders.rb +81 -42
  55. data/lib/principles/models/outline_budget.rb +127 -0
  56. data/lib/principles/models/outline_group.rb +31 -0
  57. data/lib/principles/models/outline_section.rb +56 -0
  58. data/lib/principles/models/principle_members.rb +11 -0
  59. data/lib/principles/models/prior_decision_fields.rb +3 -2
  60. data/lib/principles/models/prior_finding_decision.rb +14 -4
  61. data/lib/principles/models/project.rb +10 -19
  62. data/lib/principles/models/quoted_change.rb +137 -0
  63. data/lib/principles/models/record_format.rb +6 -2
  64. data/lib/principles/models/recorded_entry.rb +6 -0
  65. data/lib/principles/models/recorded_hashes.rb +7 -3
  66. data/lib/principles/models/recorded_members.rb +27 -15
  67. data/lib/principles/models/refusal_before_shape.rb +21 -0
  68. data/lib/principles/models/repoint.rb +13 -0
  69. data/lib/principles/models/reported_check.rb +3 -13
  70. data/lib/principles/models/sent_answer.rb +51 -0
  71. data/lib/principles/models/shape_problems_beside.rb +40 -0
  72. data/lib/principles/models/submitted_answer.rb +34 -0
  73. data/lib/principles/models/template_placeholders.rb +34 -4
  74. data/lib/principles/models/text_within.rb +55 -0
  75. data/lib/principles/models/unchecked_members.rb +76 -0
  76. data/lib/principles/models/write_up_opening.rb +21 -4
  77. data/lib/principles/session_start_options.rb +2 -2
  78. data/lib/principles/start_audit_options.rb +19 -4
  79. data/lib/principles/version.rb +2 -2
  80. data/lib/principles/views/acknowledgement_result.rb +15 -7
  81. data/lib/principles/views/assessed_members.rb +43 -10
  82. data/lib/principles/views/assessment_request.rb +89 -30
  83. data/lib/principles/views/audit_result.rb +19 -2
  84. data/lib/principles/views/candidate_files_result.rb +41 -19
  85. data/lib/principles/views/check_notes.rb +44 -0
  86. data/lib/principles/views/check_result_template.rb +14 -23
  87. data/lib/principles/views/instruction.rb +74 -0
  88. data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
  89. data/lib/principles/views/loads_to_check_result.rb +2 -2
  90. data/lib/principles/views/map_result.rb +2 -2
  91. data/lib/principles/views/member_change_since_baseline.rb +22 -5
  92. data/lib/principles/views/member_repairs.rb +21 -52
  93. data/lib/principles/views/members_a_commit_changed.rb +16 -6
  94. data/lib/principles/views/one_member_check_result_template.rb +43 -0
  95. data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
  96. data/lib/principles/views/open_findings_line.rb +77 -23
  97. data/lib/principles/views/principle_read_result.rb +20 -28
  98. data/lib/principles/views/prior_findings_result.rb +23 -15
  99. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
  100. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
  101. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
  102. data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
  103. data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
  104. data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
  105. data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
  106. data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
  107. data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
  108. data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
  109. data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
  110. data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
  111. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +4 -3
  112. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
  113. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
  114. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
  115. data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
  116. data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
  117. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
  118. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +21 -6
  119. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +4 -4
  120. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
  121. data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
  122. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +1 -1
  123. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
  124. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
  125. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +3 -3
  126. data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
  127. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
  128. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
  129. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
  130. data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
  131. data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
  132. data/lib/principles/views/request_part.rb +16 -8
  133. data/lib/principles/views/request_parts.rb +4 -0
  134. metadata +39 -5
  135. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
  136. data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
  137. data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
@@ -0,0 +1,74 @@
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
+ # One instruction a judgement request prints under its own field: its paragraphs, each printed only when the
8
+ # request holds the case it explains, and every one when the agent reads the field whole (D81 step 2, #983).
9
+ class Instruction
10
+ #: String
11
+ attr_reader :field
12
+
13
+ # An instruction of a prompt's paragraphs, each held when the block, given the paragraph, says the request
14
+ # holds its case; key a case by what the paragraph says, never by its position, which an edit moves.
15
+ #: (String, String) { (String) -> bool } -> Instruction
16
+ def self.of_paragraphs(field, text, &held)
17
+ new(field, text.split("\n\n").map { |paragraph| [paragraph, held.call(paragraph)] })
18
+ end
19
+
20
+ # paragraphs are each paragraph, in order, with whether the request holds its case.
21
+ #: (String, Array[[String, bool]]) -> void
22
+ def initialize(field, paragraphs)
23
+ @field = field
24
+ @paragraphs = paragraphs
25
+ freeze
26
+ end
27
+
28
+ # The field as the request prints it, with the paragraphs whose case it holds; nothing when it holds none.
29
+ #: () -> Hash[String, String]
30
+ def printed
31
+ held = @paragraphs.select { |_, case_held| case_held }.map(&:first)
32
+ held.empty? ? {} : { @field => held.join("\n\n") }
33
+ end
34
+
35
+ # Every paragraph, whether or not the request holds its case.
36
+ #: () -> String
37
+ def whole = @paragraphs.map(&:first).join("\n\n")
38
+
39
+ # Whether the request prints some paragraphs and leaves others out, so the field read as printed is not whole.
40
+ #: () -> bool
41
+ def trimmed? = @paragraphs.any? { |_, held| held } && @paragraphs.any? { |_, held| !held }
42
+ end
43
+
44
+ # The guide to an answer's shapes a judgement request prints under its own field: its entries, each printed only
45
+ # when the request holds the case it shows, and every one when the agent reads the field whole (D81 step 2).
46
+ class GuideInstruction
47
+ #: String
48
+ attr_reader :field
49
+
50
+ # guide is every entry; held says, by entry name, whether the request holds its case. narrowed is, by name, an
51
+ # entry as the request prints it when it holds the entry's case but not every case within it (#983).
52
+ #: (String, Hash[String, untyped], ?narrowed: Hash[String, untyped]) { (String) -> bool } -> void
53
+ def initialize(field, guide, narrowed: {}, &held)
54
+ @field = field
55
+ @guide = guide
56
+ @held = guide.filter_map { |name, entry| [name, narrowed.fetch(name, entry)] if held.call(name) }
57
+ .to_h #: Hash[String, untyped]
58
+ freeze
59
+ end
60
+
61
+ # The field as the request prints it, with the entries whose case it holds; nothing when it holds none.
62
+ #: () -> Hash[String, untyped]
63
+ def printed = @held.empty? ? {} : { @field => @held }
64
+
65
+ # Every entry, whether or not the request holds its case.
66
+ #: () -> Hash[String, untyped]
67
+ def whole = @guide
68
+
69
+ # Whether the request prints some entries and leaves others out, so the field read as printed is not whole.
70
+ #: () -> bool
71
+ def trimmed? = !@held.empty? && @held != @guide
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,51 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
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
+ # A JSON result printed pretty, but for one array whose entries each print compact on a line of their own.
10
+ # list-candidate-files' file entries are that array: pretty-printing cost 17% of a 66 KB result, and one compact
11
+ # line of 36 KB is the worst shape to read by lines (#1155). It is the first case of ticket 007's decision on the
12
+ # output format; every other result prints pretty.
13
+ class JsonWithEntriesOnLines
14
+ # Stands in for the array while the rest prints pretty. Only its first place is replaced, so text from a project
15
+ # file that holds it, which prints after the array, is left as it is.
16
+ MARKER = "\u0000entries on lines of their own\u0000"
17
+
18
+ # The array is result[under][key].
19
+ #: (Hash[String, untyped], under: String, key: String) -> void
20
+ def initialize(result, under:, key:)
21
+ @result = result
22
+ @under = under
23
+ @key = key
24
+ freeze
25
+ end
26
+
27
+ # The result as JSON generates it, so a reader of the values need not know the layout.
28
+ #: (?untyped, *untyped) -> String
29
+ def to_json(state = nil, *) = @result.to_json(state)
30
+
31
+ # The result as printed.
32
+ #: () -> String
33
+ def text
34
+ marked = JSON.pretty_generate(@result.merge(@under => @result.fetch(@under).merge(@key => MARKER)))
35
+ place = /^( *)(.*)#{Regexp.escape(JSON.generate(MARKER))}/
36
+ marked.sub(place) { "#{Regexp.last_match(1)}#{Regexp.last_match(2)}#{lines(Regexp.last_match(1).to_s)}" }
37
+ end
38
+
39
+ private
40
+
41
+ # The array's entries, each compact on its own line, one step in from indent.
42
+ #: (String) -> String
43
+ def lines(indent)
44
+ entries = @result.fetch(@under).fetch(@key)
45
+ return "[]" if entries.empty?
46
+
47
+ "[\n#{entries.map { |entry| "#{indent} #{JSON.generate(entry)}" }.join(",\n")}\n#{indent}]"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -32,8 +32,8 @@ module Principles
32
32
  listed = @listed or return
33
33
 
34
34
  decisions = listed.fetch("rows").map { |row| { "member_id" => row.fetch("member_id"), "decision" => nil } }
35
- RequestPart.new(shown: { "loads_to_check_against_activation" => listed,
36
- "loads_to_check_instruction" => instruction },
35
+ RequestPart.new(shown: { "loads_to_check_against_activation" => listed },
36
+ instructions: [Instruction.of_paragraphs("loads_to_check_instruction", instruction) { true }],
37
37
  slots: { "loading_decisions" => decisions },
38
38
  help: { "loading_decisions" => { "decision" => DECISION, **@placeholders } })
39
39
  end
@@ -114,7 +114,7 @@ module Principles
114
114
  question(principle, "#{done} Check the other members, then start the audit.\nIf you hold a correction " \
115
115
  "request from submit-answer (phase correction), list #{member} in the " \
116
116
  "changed_map_entries of the fixed disposition this change fixes, and submit it instead: " \
117
- "#{@invocation.submit_answer("REQUEST")}",
117
+ "#{@invocation.submit_answer("REQUEST_ID")}",
118
118
  start_audit(principle.id))
119
119
  end
120
120
 
@@ -142,7 +142,7 @@ module Principles
142
142
  def claimed_by_a_fix(member)
143
143
  "If you hold a correction request from submit-answer (phase correction) and this member fixes one of its " \
144
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"
145
+ "it.\nTo submit the correction instead: #{@invocation.submit_answer("REQUEST_ID")}\n"
146
146
  end
147
147
 
148
148
  # What add-member says after the member it added: to commit the map as it changes, how to see it, and the full
@@ -13,17 +13,22 @@ module Principles
13
13
  # member holds the member's id, role and evidence; commits holds "base", HEAD, and "baseline", the commit
14
14
  # the member's baseline text is at, and "audit_base" when the baseline is later than the audit's base;
15
15
  # member_lines holds its own lines at each, or their counts when too long; paths holds the paths the change
16
- # spans, its path at the baseline first.
16
+ # spans, its path at the baseline first; first_changed_lines the first line on each side the other lacks.
17
17
  #: (member: Hash[String, untyped], commits: Hash[String, String], member_lines: Hash[String, untyped],
18
- #| paths: Array[String]) -> void
19
- def initialize(member:, commits:, member_lines:, paths:)
18
+ #| first_changed_lines: Hash[String, String], paths: Array[String]) -> void
19
+ def initialize(member:, commits:, member_lines:, first_changed_lines:, paths:)
20
20
  @member = member
21
21
  @commits = commits
22
22
  @member_lines = member_lines
23
+ @first_changed_lines = first_changed_lines
23
24
  @paths = paths
24
25
  freeze
25
26
  end
26
27
 
28
+ # The first line on each side the other lacks, which the template's quotes print (#1111).
29
+ #: Hash[String, String]
30
+ attr_reader :first_changed_lines
31
+
27
32
  #: () -> String
28
33
  def member_id
29
34
  @member.fetch("id")
@@ -39,14 +44,26 @@ module Principles
39
44
  #: () -> Hash[String, untyped]
40
45
  def to_h
41
46
  read = read_the_change
42
- lines = @member_lines.key?("omitted") ? @member_lines.merge("read_instead" => read) : @member_lines
47
+ lines = @member_lines.key?("omitted") ? @member_lines.merge("read_instead" => read) : with_read_instead(read)
43
48
  { "member" => @member, "baseline_commit" => @commits.fetch("baseline"), "base_commit" => base_commit,
44
49
  **@commits.slice("audit_base").transform_keys { "audit_base_commit" },
45
- "member_lines" => lines, "read_the_change" => read }
50
+ "member_lines" => lines, "first_changed_lines" => @first_changed_lines, "read_the_change" => read }
46
51
  end
47
52
 
48
53
  private
49
54
 
55
+ # The member's lines, each side of their changed region left out pointing at read, as the whole lines do (#1103).
56
+ #: (String) -> Hash[String, untyped]
57
+ def with_read_instead(read)
58
+ region = @member_lines["changed_region"]
59
+ return @member_lines unless region
60
+
61
+ sides = region.transform_values do |side|
62
+ side.is_a?(Hash) && side.key?("omitted") ? side.merge("read_instead" => read) : side
63
+ end
64
+ @member_lines.merge("changed_region" => sides)
65
+ end
66
+
50
67
  # Each word quoted for the shell, and every path read by git as written, not as a pattern (#558).
51
68
  #: () -> String
52
69
  def read_the_change
@@ -6,15 +6,15 @@ require_relative "invocation"
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 commands that repair a member this tool cannot find: move it, or remove it. A member whose file is
10
- # gone is moved to the path the agent finds, keeping its own section, passage or query, so a rename keeps
11
- # its audit (#268). A member whose place in its file is gone is moved within it, or to another file its text
12
- # moved into (#378); a passage keeps its anchors, so a move cannot silently widen it to its whole new
13
- # section (#251). Which fits is the agent's to judge.
9
+ # The commands that repair a member this tool cannot find: each move Models::MemberRepairMoves gives, then
10
+ # remove it. Which fits is the agent's to judge.
14
11
  class MemberRepairs
15
12
  # The flag that names each locator field in a printed command.
16
13
  FLAGS = { "section" => "--section", "starting_at" => "--starting-at", "ending_at" => "--ending-at",
17
- "query" => "--query" }.freeze #: Hash[String, String]
14
+ "query" => "--query", "path" => "--path" }.freeze #: Hash[String, String]
15
+ # The placeholder the agent fills in for each field a move leaves to it.
16
+ PLACEHOLDERS = { "section" => "HEADING", "starting_at" => "NEW_OPENING_TEXT", "query" => "QUERY",
17
+ "path" => "NEW_PATH" }.freeze #: Hash[String, String]
18
18
 
19
19
  #: (Invocation) -> void
20
20
  def initialize(invocation)
@@ -22,60 +22,29 @@ module Principles
22
22
  freeze
23
23
  end
24
24
 
25
- # The repairs for member, a printed member with its "id", its locator fields and the code of the refusal
26
- # that says why it cannot be found, as "code" or show-principle's "error", of principle id. Each is
27
- # copyable as it is: move-member, with NEW_PATH, HEADING or QUERY to fill in, then, for a section or
28
- # passage lost from a file that is still there, the same move into another file, then remove-member.
29
- #: (String, Hash[String, untyped]) -> Array[String]
30
- def commands(id, member)
31
- member_id = member.fetch("id")
32
- [move(id, member_id, member), *move_elsewhere(id, member_id, member),
33
- @invocation.in_project("remove-member", id, member_id)]
25
+ # The repairs for member_id of principle id: each of moves, as Models::MemberRepairMoves gives them, the locator
26
+ # fields it keeps and those to fill in, as a copyable move-member, then remove-member.
27
+ #: (String, String, Array[Hash[String, untyped]]) -> Array[String]
28
+ def commands(id, member_id, moves)
29
+ [*moves.map { move(id, member_id, it) }, @invocation.in_project("remove-member", id, member_id)]
34
30
  end
35
31
 
36
- # member, as show-principle prints it, with its repairs as repair_with when broken, which the controller says
37
- # of a member an audit would refuse (#272).
38
- #: (String, Hash[String, untyped], broken: bool) -> Hash[String, untyped]
39
- def beside(id, member, broken:)
40
- return member unless broken
32
+ # member, as show-principle prints it, with its repairs as repair_with when moves, its moves, are given, as the
33
+ # controller gives them for a member an audit would refuse (#272).
34
+ #: (String, Hash[String, untyped], Array[Hash[String, untyped]]?) -> Hash[String, untyped]
35
+ def beside(id, member, moves)
36
+ return member unless moves
41
37
 
42
- member.merge("repair_with" => commands(id, member))
38
+ member.merge("repair_with" => commands(id, member.fetch("id"), moves))
43
39
  end
44
40
 
45
41
  private
46
42
 
47
43
  #: (String, String, Hash[String, untyped]) -> String
48
- def move(id, member_id, member)
49
- if file_unreadable?(member)
50
- kept = flags(member, FLAGS.keys)
51
- return @invocation.in_project("move-member", id, member_id, options: kept, usage: "--path NEW_PATH")
52
- end
53
- return @invocation.in_project("move-member", id, member_id, usage: "--query QUERY") if member["query"]
54
-
55
- @invocation.in_project("move-member", id, member_id, options: flags(member, %w[starting_at ending_at]),
56
- usage: "--section HEADING")
57
- end
58
-
59
- # A section or passage lost from a file that is still there may have moved into another file (#378).
60
- #: (String, String, Hash[String, untyped]) -> Array[String]
61
- def move_elsewhere(id, member_id, member)
62
- return [] if member["query"] || file_unreadable?(member)
63
-
64
- anchors = flags(member, %w[starting_at ending_at])
65
- [@invocation.in_project("move-member", id, member_id, options: anchors,
66
- usage: "--path NEW_PATH --section HEADING")]
67
- end
68
-
69
- # Whether member's file cannot be read, by the refusal it carries.
70
- #: (Hash[String, untyped]) -> bool
71
- def file_unreadable?(member)
72
- (member["code"] || member.dig("error", "code")) == "unreadable_file"
73
- end
74
-
75
- # The flags, with their values, of the locator fields named in keys that member has.
76
- #: (Hash[String, untyped], Array[String]) -> Array[String]
77
- def flags(member, keys)
78
- keys.select { |key| member[key] }.flat_map { |key| [FLAGS.fetch(key), member.fetch(key)] }
44
+ def move(id, member_id, move)
45
+ kept = move.fetch("keep").flat_map { |field, value| [FLAGS.fetch(field), value] }
46
+ usage = move.fetch("fill").map { "#{FLAGS.fetch(it)} #{PLACEHOLDERS.fetch(it)}" }.join(" ")
47
+ @invocation.in_project("move-member", id, member_id, options: kept, usage: usage)
79
48
  end
80
49
  end
81
50
  end
@@ -14,8 +14,8 @@ module Principles
14
14
  # list-member-problems --commits-after COMMIT --hook-event EVENT: the whole JSON the plugin's after-commit hook
15
15
  # prints for Claude Code, which puts its additionalContext beside the Bash call's result (D73), or nothing at all.
16
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
+ # which command shows more and which skill to start from (#986). It names that skill as a user invokes it,
18
+ # /principles, in Claude Code, the only host whose hook prints this JSON.
19
19
  class MembersACommitChanged
20
20
  NOTHING = Lines.new(stdout: "", stderr: "", status: 0).freeze #: Lines
21
21
 
@@ -27,12 +27,14 @@ module Principles
27
27
 
28
28
  # changed is each member the commits changed, as list-member-problems lists it; others is how many other changed
29
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).
30
+ # no audit to run (D85 V8, #1066); the others still listed are counted beside them too, since this copy may
31
+ # audit those (#1077).
31
32
  #: (String, Array[Hash[String, untyped]], others: Integer, ?waits: Array[RecordWaitingOnAnUpgrade]) -> Lines
32
33
  def changed(event, changed, others:, waits: [])
33
34
  waiting, auditable = changed.partition { |member| member["waiting_on_an_upgrade"] }
34
35
  reported(event, [*(to_audit(auditable, others) unless auditable.empty?),
35
- *(waiting_lines(waiting, waits) unless waiting.empty?)])
36
+ *(waiting_lines(waiting, waits) unless waiting.empty?),
37
+ *(listed_beside_the_waiting(others) if auditable.empty?)])
36
38
  end
37
39
 
38
40
  # A refusal with code, which the commits could have caused.
@@ -44,12 +46,20 @@ module Principles
44
46
 
45
47
  private
46
48
 
47
- # The members to audit, as rows, then what shows more and the skill that says how to audit them.
49
+ # The members to audit, as rows, then what shows more and the skill to start from.
48
50
  #: (Array[Hash[String, untyped]], Integer) -> Array[String]
49
51
  def to_audit(changed, others)
50
52
  [Prompts.text("report-after-a-commit/the-commits-changed-these-members"), *rows(changed),
51
53
  *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")]
54
+ Prompts.text("report-after-a-commit/the-principles-skill-is-where-to-start")]
55
+ end
56
+
57
+ # The other changed members still listed, and the command that shows each, or nothing when none is.
58
+ #: (Integer) -> Array[String]
59
+ def listed_beside_the_waiting(others)
60
+ return [] if others.zero?
61
+
62
+ [*still_listed(others), Prompts.text("report-after-a-commit/this-command-shows-each-one"), command]
53
63
  end
54
64
 
55
65
  # The members whose audits wait on an upgrade, as rows, then each wait's line, which says how to update.
@@ -0,0 +1,43 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "check_notes"
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 check_result a one-member audit's template starts with for a checked member, whose check is the one the last
11
+ # audit ran, since any other is refused at its start (#1071). It asks for a passing run alone, since one that fails
12
+ # or cannot run is refused as a full audit's to judge, so it prints no not_run_reason and says nothing of how often
13
+ # full audits run it (#1112).
14
+ class OneMemberCheckResultTemplate
15
+ # The template for the checked member a request lists as entry, with its check, how that stands to the last
16
+ # audit's and any hidden characters in it; nil for a member without a check. review_basis is the text it prints
17
+ # there, which an answer leaves as printed to keep the line the last audit kept (#1010).
18
+ #: (Hash[String, untyped], review_basis: String) -> Hash[String, untyped]?
19
+ def self.for(entry, review_basis:)
20
+ check = entry["check"] or return
21
+ new(check, CheckNotes.new(entry["check_since_last_audit"], entry.fetch("check_hidden_characters", [])),
22
+ review_basis:).to_h
23
+ end
24
+
25
+ #: (String, CheckNotes, review_basis: String) -> void
26
+ def initialize(check, notes, review_basis:)
27
+ @check = check
28
+ @notes = notes
29
+ @review_basis = review_basis
30
+ freeze
31
+ end
32
+
33
+ #: () -> Hash[String, untyped]
34
+ def to_h
35
+ { "command" => @check,
36
+ "exit_status" => [@notes.hidden_characters,
37
+ Prompts.text("acknowledge-a-change/run-the-check-and-report-it-passing"),
38
+ *@notes.kept_review].compact.join(" "),
39
+ "review_basis" => @review_basis }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -23,9 +23,9 @@ module Principles
23
23
  def part
24
24
  return if @findings.empty?
25
25
 
26
- instruction = Prompts.text("assess-every-member/name-another-principles-open-finding-rather-than-raise-it")
27
- RequestPart.new(shown: { "open_findings_elsewhere" => @findings,
28
- "open_findings_elsewhere_instruction" => instruction }, slots: {})
26
+ text = Prompts.text("assess-every-member/name-another-principles-open-finding-rather-than-raise-it")
27
+ instruction = Instruction.of_paragraphs("open_findings_elsewhere_instruction", text) { true }
28
+ RequestPart.new(shown: { "open_findings_elsewhere" => @findings }, slots: {}, instructions: [instruction])
29
29
  end
30
30
  end
31
31
  end
@@ -16,6 +16,43 @@ module Principles
16
16
  # A waits_on longer than this is cut, so the line stays one short line.
17
17
  WAITS_ON_LIMIT = 80
18
18
 
19
+ # The session's start the line is worded for, as Claude Code's SessionStart hook names it: startup, resume,
20
+ # clear or compact. It says what the context holds already, and so when to raise the findings and when the
21
+ # line comes back.
22
+ class SessionStart
23
+ #: (String) -> void
24
+ def initialize(source)
25
+ @source = source
26
+ freeze
27
+ end
28
+
29
+ # A resumed conversation already holds the line printed when its context began (#1078).
30
+ #: () -> bool
31
+ def resumed? = @source == "resume"
32
+
33
+ # When to raise the findings: before the user's first task at startup, and at the next pause once the
34
+ # session is under way, after /clear or a compaction (#717).
35
+ #: () -> String
36
+ def raise_when
37
+ return Prompts.text("start-a-session/raise-them-before-the-first-task") if startup?
38
+
39
+ Prompts.text("start-a-session/raise-them-at-the-next-pause")
40
+ end
41
+
42
+ # When the line comes back: at each session start, and after each clear or compaction too (#741).
43
+ #: () -> String
44
+ def returns
45
+ return Prompts.text("start-a-session/it-returns-at-each-session-start") if startup?
46
+
47
+ Prompts.text("start-a-session/it-returns-after-each-clear-or-compaction-too")
48
+ end
49
+
50
+ private
51
+
52
+ #: () -> bool
53
+ def startup? = @source == "startup"
54
+ end
55
+
19
56
  #: (Invocation) -> void
20
57
  def initialize(invocation)
21
58
  @invocation = invocation
@@ -25,41 +62,42 @@ module Principles
25
62
  # waiting is nil when no finding is open, or the count of open findings with the oldest one's principle,
26
63
  # finding_id, days_open and, when it says, waits_on. not_found is each open finding, by principle and
27
64
  # finding_id, whose write-up can no longer be found where its recorded_at points (#694). source is the
28
- # session's start: startup, clear or compact.
65
+ # session's start: startup, resume, clear or compact.
29
66
  #: (Hash[String, untyped]?, ?Array[Hash[String, untyped]], ?source: String) -> Lines
30
67
  def short(waiting, not_found = [], source: "startup")
31
- Lines.new(stdout: waiting ? "#{line(waiting, not_found, source)}\n" : "", stderr: "", status: 0)
68
+ start = SessionStart.new(source)
69
+ Lines.new(stdout: waiting ? "#{line(waiting, not_found, start)}\n" : "", stderr: "", status: 0)
32
70
  end
33
71
 
34
72
  private
35
73
 
36
- #: (Hash[String, untyped], Array[Hash[String, untyped]], String) -> String
37
- def line(waiting, not_found, source)
74
+ #: (Hash[String, untyped], Array[Hash[String, untyped]], SessionStart) -> String
75
+ def line(waiting, not_found, start)
76
+ return resumed("#{how_long(waiting)} (#{oldest(waiting)})", not_found) if start.resumed?
77
+
78
+ whole(waiting, not_found, start)
79
+ end
80
+
81
+ # The line with what to do about the findings, for a context that does not hold it yet.
82
+ #: (Hash[String, untyped], Array[Hash[String, untyped]], SessionStart) -> String
83
+ def whole(waiting, not_found, start)
38
84
  count = waiting.fetch("count")
39
85
  them, each = pronouns(count)
40
86
  Prompts.text("start-a-session/act-on-the-open-findings",
41
- when: raise_when(source), returns: returns(source),
42
- findings: "#{counted(count)}#{waited(waiting)} (#{named(waiting)})",
87
+ when: start.raise_when, returns: start.returns,
88
+ findings: "#{how_long(waiting)} (#{named(waiting)})",
43
89
  without_waits_on: without_waits_on(count, waiting.fetch("without_waits_on", 0)),
44
90
  write_ups: write_ups(not_found),
45
91
  them: them, each: each, command: @invocation.in_project("list-open-findings"))
46
92
  end
47
93
 
48
- # When to raise the findings: before the user's first task at startup, and at the next pause once the session is
49
- # under way, after /clear or a compaction (#717).
50
- #: (String) -> String
51
- def raise_when(source)
52
- return Prompts.text("start-a-session/raise-them-before-the-first-task") if source == "startup"
53
-
54
- Prompts.text("start-a-session/raise-them-at-the-next-pause")
55
- end
56
-
57
- # When the line comes back: at each session start, and after each clear or compaction too (#741).
58
- #: (String) -> String
59
- def returns(source)
60
- return Prompts.text("start-a-session/it-returns-at-each-session-start") if source == "startup"
61
-
62
- Prompts.text("start-a-session/it-returns-after-each-clear-or-compaction-too")
94
+ # A resumed session's line: its conversation already holds the line printed when that context began, so this
95
+ # one gives the facts and where the instructions are, not the instructions again (#1078).
96
+ #: (String, Array[Hash[String, untyped]]) -> String
97
+ def resumed(findings, not_found)
98
+ Prompts.text("start-a-session/see-the-earlier-line",
99
+ findings: findings, write_ups: write_ups(not_found),
100
+ command: @invocation.in_project("list-open-findings", options: ["--short"]))
63
101
  end
64
102
 
65
103
  # How many of several open findings record no waits_on, since the line names only the oldest's (#736). One
@@ -91,6 +129,10 @@ module Principles
91
129
  "recorded_at points, and the list says why."
92
130
  end
93
131
 
132
+ # How many findings are open and how long the oldest has waited.
133
+ #: (Hash[String, untyped]) -> String
134
+ def how_long(waiting) = "#{counted(waiting.fetch("count"))}#{waited(waiting)}"
135
+
94
136
  #: (Integer) -> String
95
137
  def counted(count)
96
138
  count == 1 ? "1 audit finding is still open, " : "#{count} audit findings are still open, the oldest "
@@ -108,12 +150,24 @@ module Principles
108
150
  # text, so each is cut by characters first and then escaped, which may run past the limit to show them (#227).
109
151
  #: (Hash[String, untyped]) -> String
110
152
  def named(waiting)
111
- named = "#{waiting.fetch("principle")} #{VisibleText.new(waiting.fetch("finding_id"))}"
153
+ named = oldest(waiting)
112
154
  waits_on = waiting["waits_on"] or return named
113
- waits_on = closed("#{waits_on[0, WAITS_ON_LIMIT - 3]}...") if waits_on.length > WAITS_ON_LIMIT
155
+ waits_on = closed("#{whole_words(waits_on[0, WAITS_ON_LIMIT - 3].to_s)}...") if waits_on.length > WAITS_ON_LIMIT
114
156
  "#{named}, waits on: #{VisibleText.new(waits_on)}"
115
157
  end
116
158
 
159
+ # A cut waits_on up to its last whole word, so it never ends in part of one (#1078), or as cut when it is one
160
+ # word, which has no boundary to cut at.
161
+ #: (String) -> String
162
+ def whole_words(cut)
163
+ boundary = cut.rindex(" ") or return cut
164
+ cut[0, boundary].to_s
165
+ end
166
+
167
+ # The oldest finding's principle and id, which is free text and so escaped (#227).
168
+ #: (Hash[String, untyped]) -> String
169
+ def oldest(waiting) = "#{waiting.fetch("principle")} #{VisibleText.new(waiting.fetch("finding_id"))}"
170
+
117
171
  # A cut waits_on with a ")" for each "(" the cut left open, so the line's own parenthesis still reads as
118
172
  # closing the finding's name (#685).
119
173
  #: (String) -> String
@@ -20,28 +20,27 @@ module Principles
20
20
  freeze
21
21
  end
22
22
 
23
- # show-principle: each member with where its text is now and its freshness, and each member in broken, the ids
24
- # of those an audit would refuse, with its repair_with commands (#272).
23
+ # show-principle: each member with where its text is now and its freshness, and each member repairs names, those
24
+ # an audit would refuse, with its repair_with commands, from the moves repairs gives it (#272).
25
25
  # hook_settings_not_read names each project settings file whose hooks this tool could not read (#491).
26
26
  # loaded_files lists each file the members load once, with the total of those loading at session start (#483).
27
- #: (PrintedPrinciple, broken: Array[String], ?hook_settings_not_read: Array[Hash[String, String]],
28
- #| ?loaded_files: Hash[String, untyped]) -> Hash[String, untyped]
29
- def shown(principle, broken:, hook_settings_not_read: [], loaded_files: {})
27
+ #: (PrintedPrinciple, repairs: Hash[String, Array[Hash[String, untyped]]],
28
+ #| ?hook_settings_not_read: Array[Hash[String, String]], ?loaded_files: Hash[String, untyped])
29
+ #| -> Hash[String, untyped]
30
+ def shown(principle, repairs:, hook_settings_not_read: [], loaded_files: {})
30
31
  unread = hook_settings_not_read.empty? ? {} : { "hook_settings_not_read" => hook_settings_not_read }
31
32
  { "id" => principle.id, "map_file" => principle.file, **principle.declared,
32
- "members" => principle.members.map { |member| repaired(principle.id, member, broken) },
33
- **loaded_files, **unread, "next_action" => shown_next_action(principle, broken) }
33
+ "members" => principle.members.map { |member| repaired(principle.id, member, repairs) },
34
+ **loaded_files, **unread, "next_action" => shown_next_action(principle, repairs.keys) }
34
35
  end
35
36
 
36
- # list-principles: each entry is { "id", "description", "members_by_freshness" }. Until principles is set_up,
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)
42
- first = set_up ? [] : [set_up_first]
43
- next_action = [*first, *listed_next_action(entries, waiting, one_to_audit)]
44
- { "principles" => entries, "next_action" => next_action.join("\n") }
37
+ # list-principles: each entry is { "id", "description", "members_by_freshness" }. waiting is each principle whose
38
+ # audits wait on an upgrade, which it names, with how to update said once, and an audit is offered only when one
39
+ # is left to audit (#1067, #1081).
40
+ #: (Array[Hash[String, untyped]], ?waiting: Array[RecordWaitingOnAnUpgrade], ?one_to_audit: bool)
41
+ #| -> Hash[String, untyped]
42
+ def listing(entries, waiting: [], one_to_audit: true)
43
+ { "principles" => entries, "next_action" => listed_next_action(entries, waiting, one_to_audit).join("\n") }
45
44
  end
46
45
 
47
46
  # list-principles' note on the meta-principle's map, kept in file, when it has no members, with the two ways on
@@ -56,7 +55,7 @@ module Principles
56
55
 
57
56
  private
58
57
 
59
- # What list-principles' next_action offers after setting up: mapping one when none is listed, else showing one,
58
+ # What list-principles' next_action offers: mapping one when none is listed, else showing one,
60
59
  # auditing one when one is left to audit, and the principles whose audits wait on an upgrade.
61
60
  #: (Array[Hash[String, untyped]], Array[RecordWaitingOnAnUpgrade], bool) -> Array[String]
62
61
  def listed_next_action(entries, waiting, one_to_audit)
@@ -74,17 +73,10 @@ module Principles
74
73
  .join(" ")
75
74
  end
76
75
 
77
- # The line that puts setting principles up first, ending in its command.
78
- #: () -> String
79
- def set_up_first
80
- Prompts.text("set-principles-up/set-up-first",
81
- command: @invocation.in_project("show-meta-principle-passage"))
82
- end
83
-
84
- # member, with its repairs when broken names it.
85
- #: (String, Hash[String, untyped], Array[String]) -> Hash[String, untyped]
86
- def repaired(id, member, broken)
87
- MemberRepairs.new(@invocation).beside(id, member, broken: broken.include?(member.fetch("id")))
76
+ # member, with its repairs when repairs names it.
77
+ #: (String, Hash[String, untyped], Hash[String, Array[Hash[String, untyped]]]) -> Hash[String, untyped]
78
+ def repaired(id, member, repairs)
79
+ MemberRepairs.new(@invocation).beside(id, member, repairs[member.fetch("id")])
88
80
  end
89
81
 
90
82
  # Repair each member in broken, the ids of those an audit would refuse; otherwise audit when one changed or was