principles 0.0.10 → 0.0.11

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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +0 -2
  4. data/lib/principles/controllers/acknowledgement.rb +11 -4
  5. data/lib/principles/controllers/acknowledgements.rb +4 -4
  6. data/lib/principles/controllers/assessment.rb +1 -1
  7. data/lib/principles/controllers/audit.rb +2 -1
  8. data/lib/principles/controllers/broken_member_repairs.rb +60 -0
  9. data/lib/principles/controllers/command.rb +8 -30
  10. data/lib/principles/controllers/correction.rb +7 -5
  11. data/lib/principles/controllers/full_audit_request.rb +32 -16
  12. data/lib/principles/controllers/inventory.rb +3 -3
  13. data/lib/principles/controllers/member_acknowledgement.rb +5 -5
  14. data/lib/principles/controllers/member_addition.rb +1 -1
  15. data/lib/principles/controllers/member_entries.rb +1 -1
  16. data/lib/principles/controllers/member_problems_report.rb +4 -1
  17. data/lib/principles/controllers/members_to_assess.rb +1 -1
  18. data/lib/principles/controllers/meta_principle_setup.rb +4 -3
  19. data/lib/principles/controllers/open_correction.rb +3 -3
  20. data/lib/principles/data/command-steps.json +4 -4
  21. data/lib/principles/data/repository.rb +4 -4
  22. data/lib/principles/data/running_version.rb +1 -1
  23. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  24. data/lib/principles/invocation_options.rb +4 -4
  25. data/lib/principles/models/acknowledgement.rb +1 -27
  26. data/lib/principles/models/acknowledgement_left_as_printed.rb +2 -1
  27. data/lib/principles/models/acknowledgement_placeholders.rb +48 -0
  28. data/lib/principles/models/assessment_answer.rb +2 -2
  29. data/lib/principles/models/assessment_left_as_printed.rb +1 -1
  30. data/lib/principles/models/audit.rb +1 -1
  31. data/lib/principles/models/audit_records.rb +1 -1
  32. data/lib/principles/models/candidate_inventory.rb +1 -1
  33. data/lib/principles/models/disposition.rb +12 -76
  34. data/lib/principles/models/disposition_placeholders.rb +48 -0
  35. data/lib/principles/models/disposition_text_field.rb +41 -0
  36. data/lib/principles/models/evidence_item.rb +1 -1
  37. data/lib/principles/models/fix_only_fields.rb +4 -3
  38. data/lib/principles/models/located_text.rb +19 -11
  39. data/lib/principles/models/member_assessments.rb +11 -4
  40. data/lib/principles/models/member_file.rb +9 -12
  41. data/lib/principles/models/member_mapping_run.rb +1 -1
  42. data/lib/principles/models/member_repair_moves.rb +20 -4
  43. data/lib/principles/models/member_snapshots.rb +10 -10
  44. data/lib/principles/models/members_sharing_lines.rb +1 -1
  45. data/lib/principles/models/misspelt_member_id.rb +9 -3
  46. data/lib/principles/models/named_placeholder.rb +32 -0
  47. data/lib/principles/models/other_templates_placeholders.rb +25 -6
  48. data/lib/principles/models/principle_history.rb +4 -3
  49. data/lib/principles/models/project.rb +7 -13
  50. data/lib/principles/models/project_at_commit.rb +70 -0
  51. data/lib/principles/models/project_history.rb +10 -52
  52. data/lib/principles/models/sent_answer.rb +4 -3
  53. data/lib/principles/models/template_placeholders.rb +22 -7
  54. data/lib/principles/models/text_size.rb +11 -3
  55. data/lib/principles/models/unfinished_field.rb +34 -0
  56. data/lib/principles/start_audit_options.rb +10 -2
  57. data/lib/principles/version.rb +2 -2
  58. data/lib/principles/views/acknowledged_result.rb +59 -0
  59. data/lib/principles/views/acknowledgement_result.rb +32 -42
  60. data/lib/principles/views/answer_in_a_file.rb +53 -0
  61. data/lib/principles/views/assessed_members.rb +4 -2
  62. data/lib/principles/views/audit_result.rb +3 -1
  63. data/lib/principles/views/context_parts.rb +1 -1
  64. data/lib/principles/views/correction_request.rb +19 -13
  65. data/lib/principles/views/member_repairs.rb +21 -5
  66. data/lib/principles/views/meta_principle_result.rb +26 -5
  67. data/lib/principles/views/parts_index_result.rb +8 -6
  68. data/lib/principles/views/principle_read_result.rb +2 -2
  69. data/lib/principles/views/problem_lines.rb +8 -3
  70. data/lib/principles/views/problem_result.rb +11 -0
  71. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +6 -0
  72. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  73. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-check.md +4 -3
  74. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-role.md +4 -3
  75. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +7 -8
  76. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +4 -3
  77. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member-check.md +4 -3
  78. data/lib/principles/views/prompts/learn-what-a-command-does/remove-member.md +4 -3
  79. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +13 -12
  80. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +5 -5
  81. data/lib/principles/views/prompts/start-a-session/act-on-the-changed-principles.md +2 -0
  82. data/lib/principles/views/prompts.rb +7 -4
  83. metadata +13 -2
@@ -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.10"
6
+ RELEASE = "0.0.11"
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.10" #: String?
10
+ BUILT_VERSION = "0.0.11" #: String?
11
11
  end
@@ -0,0 +1,59 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "answered_request"
5
+ require_relative "invocation"
6
+ require_relative "../prose_list"
7
+
8
+ module Principles
9
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
+ module Views
11
+ # An acknowledgement's answer accepted: the members that now read as judged, the files that hold them to
12
+ # commit, and the command that no longer lists them.
13
+ class AcknowledgedResult
14
+ #: (Invocation) -> void
15
+ def initialize(invocation)
16
+ @invocation = invocation
17
+ freeze
18
+ end
19
+
20
+ # The acknowledgement of each of member_ids was accepted, and file holds them all.
21
+ #: (principle_id: String, member_ids: Array[String], file: String) -> AnsweredRequest
22
+ def several_acknowledged(principle_id:, member_ids:, file:)
23
+ AnsweredRequest.new(
24
+ "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => member_ids,
25
+ "files_to_commit" => [file],
26
+ "next_action" => "Commit #{file}. #{ProseList.new(member_ids)} read as judged until each is edited again.\n" \
27
+ "This no longer lists them: " \
28
+ "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
29
+ )
30
+ end
31
+
32
+ # The acknowledgement of each of member_ids was accepted for every principle that maps it, each principle's in its
33
+ # file, under its id in files.
34
+ #: (member_ids: Array[String], files: Hash[String, String]) -> AnsweredRequest
35
+ def across_acknowledged(member_ids:, files:)
36
+ AnsweredRequest.new(
37
+ "status" => "acknowledged", "principle_ids" => files.keys, "member_ids" => member_ids,
38
+ "files_to_commit" => files.values,
39
+ "next_action" => "Commit #{ProseList.new(files.values)}. #{ProseList.new(member_ids)} read as judged until " \
40
+ "each is edited again.\nThis no longer lists them: " \
41
+ "#{@invocation.in_project("list-member-problems", usage: "--short")}"
42
+ )
43
+ end
44
+
45
+ # The acknowledgement was accepted and file holds it.
46
+ #: (principle_id: String, member_id: String, file: String) -> AnsweredRequest
47
+ def acknowledged(principle_id:, member_id:, file:)
48
+ fields = {
49
+ "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => [member_id],
50
+ "files_to_commit" => [file],
51
+ "next_action" => "Commit #{file}. #{member_id} reads as judged until it is edited again.\n" \
52
+ "This no longer lists it: " \
53
+ "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
54
+ }
55
+ AnsweredRequest.new(fields)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,17 +1,19 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "answer_in_a_file"
4
5
  require_relative "invocation"
5
- require_relative "answered_request"
6
6
  require_relative "member_change_since_baseline"
7
7
  require_relative "prompts"
8
- require_relative "../prose_list"
9
8
 
10
9
  module Principles
11
10
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
12
11
  module Views
13
12
  # A one-member audit's request and its result.
14
13
  class AcknowledgementResult
14
+ # Where a placeholder names the member of the entry it prints in.
15
+ SLOT = "%<id>s" #: String
16
+
15
17
  #: (Invocation) -> void
16
18
  def initialize(invocation)
17
19
  @invocation = invocation
@@ -28,7 +30,8 @@ module Principles
28
30
  "context" => { "principle_id" => principle_id, **asked.fetch(:change).to_h, **asked.fetch(:context),
29
31
  "question" => Prompts.text("acknowledge-a-change/say-whether-the-change-keeps-the-meaning") },
30
32
  "response_template" => answer_to_fill(request_id:, asked:),
31
- "answer_with" => @invocation.submit_answer(request_id) }
33
+ "answer_with" => @invocation.submit_answer(request_id),
34
+ "next_action" => to_fill([principle_id], [asked.fetch(:change).member_id], request_id:) }
32
35
  end
33
36
 
34
37
  # The answer to the request request_id names, to fill: the request prints it as response_template, and
@@ -39,7 +42,7 @@ module Principles
39
42
  def answer_to_fill(request_id:, asked:)
40
43
  member_id = asked.fetch(:change).member_id
41
44
  { "request_id" => request_id, "basis" => { "member_ids" => [member_id] },
42
- "members" => { member_id => asked.fetch(:placeholders) } }
45
+ "members" => { member_id => named(asked.fetch(:placeholders), member_id) } }
43
46
  end
44
47
 
45
48
  # The request for several members' acknowledgements in one answer: each of members holds a member's
@@ -52,7 +55,8 @@ module Principles
52
55
  "members" => shown(members),
53
56
  "question" => Prompts.text("acknowledge-a-change/say-whether-each-change-keeps-its-meaning") },
54
57
  "response_template" => several_to_fill(request_id:, members:),
55
- "answer_with" => @invocation.submit_answer(request_id) }
58
+ "answer_with" => @invocation.submit_answer(request_id),
59
+ "next_action" => to_fill([principle_id], members.map { it.fetch(:change).member_id }, request_id:) }
56
60
  end
57
61
 
58
62
  # The answer to the request for several members request_id names, to fill: its basis names each member, and
@@ -60,7 +64,7 @@ module Principles
60
64
  #: (request_id: String, members: Array[Hash[Symbol, untyped]]) -> Hash[String, untyped]
61
65
  def several_to_fill(request_id:, members:)
62
66
  { "request_id" => request_id, "basis" => { "member_ids" => members.map { it.fetch(:change).member_id } },
63
- "members" => members.to_h { [it.fetch(:change).member_id, it.fetch(:placeholders)] } }
67
+ "members" => members.to_h { named_entry(it) } }
64
68
  end
65
69
 
66
70
  # The request for the members several principles map in one answer: under context.principles, each
@@ -74,7 +78,8 @@ module Principles
74
78
  "context" => { "principles" => shown_once(principles),
75
79
  **deferred_findings_kept(keeping_deferred), "question" => across_question },
76
80
  "response_template" => across_to_fill(request_id:, principles:),
77
- "answer_with" => @invocation.submit_answer(request_id) }
81
+ "answer_with" => @invocation.submit_answer(request_id),
82
+ "next_action" => to_fill(principles.keys.uniq.sort, across_member_ids(principles), request_id:) }
78
83
  end
79
84
 
80
85
  # The answer to the request for the members several principles map, to fill: its basis names each principle and
@@ -85,51 +90,36 @@ module Principles
85
90
  def across_to_fill(request_id:, principles:)
86
91
  entries = principles.values.flatten.each_with_object({}) do |asked, by_member|
87
92
  id = asked.fetch(:change).member_id
88
- by_member[id] = asked.fetch(:placeholders).merge(by_member.fetch(id, {}))
93
+ by_member[id] = named(asked.fetch(:placeholders), id).merge(by_member.fetch(id, {}))
89
94
  end
90
95
  { "request_id" => request_id, "basis" => { "principle_ids" => principles.keys, "member_ids" => entries.keys },
91
96
  "members" => entries }
92
97
  end
93
98
 
94
- # The acknowledgement of each of member_ids was accepted, and file holds them all.
95
- #: (principle_id: String, member_ids: Array[String], file: String) -> AnsweredRequest
96
- def several_acknowledged(principle_id:, member_ids:, file:)
97
- AnsweredRequest.new(
98
- "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => member_ids,
99
- "files_to_commit" => [file],
100
- "next_action" => "Commit #{file}. #{ProseList.new(member_ids)} read as judged until each is edited again.\n" \
101
- "This no longer lists them: " \
102
- "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
103
- )
104
- end
99
+ private
105
100
 
106
- # The acknowledgement of each of member_ids was accepted for every principle that maps it, each principle's in its
107
- # file, under its id in files.
108
- #: (member_ids: Array[String], files: Hash[String, String]) -> AnsweredRequest
109
- def across_acknowledged(member_ids:, files:)
110
- AnsweredRequest.new(
111
- "status" => "acknowledged", "principle_ids" => files.keys, "member_ids" => member_ids,
112
- "files_to_commit" => files.values,
113
- "next_action" => "Commit #{ProseList.new(files.values)}. #{ProseList.new(member_ids)} read as judged until " \
114
- "each is edited again.\nThis no longer lists them: " \
115
- "#{@invocation.in_project("list-member-problems", usage: "--short")}"
116
- )
101
+ # placeholders with each one's SLOT naming the member id, as its entry in the template prints them; any other
102
+ # text, a percent sign included, as it is.
103
+ #: (Hash[String, untyped], String) -> Hash[String, untyped]
104
+ def named(placeholders, id) = placeholders.transform_values { it.is_a?(String) ? it.gsub(SLOT, id) : it }
105
+
106
+ # The template's entry for the member asked asks about, by its id.
107
+ #: (Hash[Symbol, untyped]) -> [String, Hash[String, untyped]]
108
+ def named_entry(asked)
109
+ id = asked.fetch(:change).member_id
110
+ [id, named(asked.fetch(:placeholders), id)]
117
111
  end
118
112
 
119
- # The acknowledgement was accepted and file holds it.
120
- #: (principle_id: String, member_id: String, file: String) -> AnsweredRequest
121
- def acknowledged(principle_id:, member_id:, file:)
122
- fields = {
123
- "status" => "acknowledged", "principle_id" => principle_id, "member_ids" => [member_id],
124
- "files_to_commit" => [file],
125
- "next_action" => "Commit #{file}. #{member_id} reads as judged until it is edited again.\n" \
126
- "This no longer lists it: " \
127
- "#{@invocation.in_project("list-member-problems", principle_id, usage: "--short")}"
128
- }
129
- AnsweredRequest.new(fields)
113
+ # How to fill the answer to request_id, acknowledging member_ids of principle_ids: saved bare from
114
+ # start-audit --as template to a file the agent edits.
115
+ #: (Array[String], Array[String], request_id: String) -> String
116
+ def to_fill(principle_ids, member_ids, request_id:)
117
+ AnswerInAFile.new(@invocation).acknowledgement(principle_ids, member_ids, request_id:)
130
118
  end
131
119
 
132
- private
120
+ # Each member the principles' requests ask about, once, in the order they ask.
121
+ #: (Hash[String, Array[Hash[Symbol, untyped]]]) -> Array[String]
122
+ def across_member_ids(principles) = principles.values.flatten.map { it.fetch(:change).member_id }.uniq
133
123
 
134
124
  # Where to read the deferred findings an acknowledgement across principles keeps, and the full audit of each
135
125
  # principle in ids that resolves them, one command to a line; nothing when ids is empty.
@@ -0,0 +1,53 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "context_parts"
5
+ require_relative "invocation"
6
+ require_relative "prompts"
7
+
8
+ module Principles
9
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
+ module Views
11
+ # How to fill an answer this tool prints bare: save it to a file outside the project, fill it there with the
12
+ # agent's own file-edit tool, and submit that file, with the three characters JSON escapes. Filling a template
13
+ # in a shell heredoc took a script, since prose full of quotes needed escaping for the shell and for JSON.
14
+ class AnswerInAFile
15
+ #: (Invocation) -> void
16
+ def initialize(invocation)
17
+ @invocation = invocation
18
+ freeze
19
+ end
20
+
21
+ # The line for a full audit's assessment, whose answer start-audit --part response_template prints bare.
22
+ #: (String, request_id: String) -> String
23
+ def assessment(principle_id, request_id:)
24
+ line(@invocation.in_project("start-audit", principle_id, options: ["--part", ContextParts::TEMPLATE]),
25
+ request_id:)
26
+ end
27
+
28
+ # The line for acknowledging member_ids of principle_ids, whose answer start-audit --member --as template prints
29
+ # bare.
30
+ #: (Array[String], Array[String], request_id: String) -> String
31
+ def acknowledgement(principle_ids, member_ids, request_id:)
32
+ named = member_ids.flat_map { ["--member", it] }
33
+ line(@invocation.listed_in_project("start-audit", principle_ids, options: [*named, "--as", "template"]),
34
+ request_id:)
35
+ end
36
+
37
+ # The line for an open correction, whose answer show-open-correction prints bare, of which only the
38
+ # dispositions are the agent's to fill.
39
+ #: (String, request_id: String) -> String
40
+ def correction(principle_id, request_id:)
41
+ line(@invocation.in_project("show-open-correction", principle_id), request_id:, what: "only its dispositions")
42
+ end
43
+
44
+ # The line for the answer request_id names, which the printed command save prints bare; what is the part of it
45
+ # the agent fills.
46
+ #: (String, request_id: String, ?what: String) -> String
47
+ def line(save, request_id:, what: "it")
48
+ Prompts.text("answer-any-judgement-request/fill-the-answer-in-a-file",
49
+ save:, what:, answer_with: @invocation.submit_answer(request_id))
50
+ end
51
+ end
52
+ end
53
+ end
@@ -18,7 +18,8 @@ module Principles
18
18
  # reviewed_check_placeholders is the text a checked member's template prints in each field it may leave as
19
19
  # printed to give none, for a check reviewed before it runs; unchanged_check_placeholders, for one the
20
20
  # last audit ran.
21
- # assessment_placeholder is the text a fresh member's assessment prints, which an answer may not send back.
21
+ # assessment_placeholder is the text a fresh member's assessment prints, which an answer may not send back, its
22
+ # %<id>s filled with the member's id, so each slot's is its own and one edit fills one slot.
22
23
  #: (Array[Hash[String, untyped]], reviewed_check_placeholders: Hash[String, String],
23
24
  #| unchanged_check_placeholders: Hash[String, String], assessment_placeholder: String) -> void
24
25
  def initialize(members, reviewed_check_placeholders:, unchanged_check_placeholders:, assessment_placeholder:)
@@ -151,7 +152,8 @@ module Principles
151
152
 
152
153
  #: (Hash[String, untyped]) -> Hash[String, untyped]
153
154
  def fresh(member)
154
- { "member_id" => member.fetch("id"), "assessment" => @assessment_placeholder,
155
+ id = member.fetch("id")
156
+ { "member_id" => id, "assessment" => format(@assessment_placeholder, id:),
155
157
  "delivery" => "not_observed", "evidence" => member.fetch("evidence") }
156
158
  end
157
159
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "assessment_request"
5
+ require_relative "answer_in_a_file"
5
6
  require_relative "answered_request"
6
7
  require_relative "audit_changes"
7
8
  require_relative "completed_audit_next_step"
@@ -101,7 +102,8 @@ module Principles
101
102
  output = judgement("assessment", request, { "read_in_parts" => read_in_parts(request.principle_id) },
102
103
  to_fill: { "response_template" => request.template })
103
104
  note = TrimmedInstructionsNote.new(request.trimmed_instruction_fields).to_h
104
- output.merge("context" => output.fetch("context").merge(note))
105
+ fill = AnswerInAFile.new(@invocation).assessment(request.principle_id, request_id: request.request_id)
106
+ output.merge("context" => output.fetch("context").merge(note), "next_action" => fill)
105
107
  end
106
108
 
107
109
  # start-audit --as template: the assessment's answer alone, to fill and submit.
@@ -60,7 +60,7 @@ module Principles
60
60
  def shown(name)
61
61
  return { INDEX => index } if name == INDEX
62
62
  return EMPTY if left_out.include?(name)
63
- return { TEMPLATE => @template } if name == TEMPLATE
63
+ return @template if name == TEMPLATE
64
64
  return { name => @context.fetch(name) } unless name.start_with?(MEMBER)
65
65
 
66
66
  id = name.delete_prefix(MEMBER)
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "answer_head"
5
+ require_relative "answer_in_a_file"
5
6
  require_relative "invocation"
6
7
  require_relative "prompts"
7
8
 
@@ -12,7 +13,8 @@ module Principles
12
13
  # every disposition's shape, and what submitting the assessment stored.
13
14
  class CorrectionRequest
14
15
  # head is what the answer hands back unchanged, the request's id and the basis the correction depends on;
15
- # placeholders is the text the template leaves in each field the agent writes.
16
+ # placeholders is the text the template leaves in each field the agent writes, with %<id>s where each
17
+ # disposition names its finding.
16
18
  #: (head: AnswerHead, principle_id: String, findings: Array[untyped], placeholders: Hash[String, String]) -> void
17
19
  def initialize(head:, principle_id:, findings:, placeholders:)
18
20
  @head = head
@@ -31,7 +33,15 @@ module Principles
31
33
  def context
32
34
  { "principle_id" => @principle_id, "findings" => @findings,
33
35
  "question" => Prompts.text("dispose-of-each-finding/fix-or-record-each-finding"),
34
- "answer_guide" => Prompts.data("dispose-of-each-finding/answer-guide") }
36
+ "answer_guide" => self.class.answer_guide(@placeholders.fetch("reason")) }
37
+ end
38
+
39
+ # The guide to every disposition's shape, whose deferred sample's reason is reason_placeholder, the template's,
40
+ # its slot filled for no one finding, as the guide speaks of any.
41
+ #: (String) -> Hash[String, untyped]
42
+ def self.answer_guide(reason_placeholder)
43
+ Prompts.data("dispose-of-each-finding/answer-guide",
44
+ reason_placeholder: format(reason_placeholder, id: "this finding"))
35
45
  end
36
46
 
37
47
  # The answer to fill in, as show-open-correction and show-answer-check --as template print it alone: one
@@ -40,10 +50,11 @@ module Principles
40
50
  #: () -> Hash[String, untyped]
41
51
  def template
42
52
  @head.leading("dispositions" => @findings.map do |finding|
43
- { "finding_id" => finding["id"], "action" => @placeholders.fetch("action"),
44
- "reason" => @placeholders.fetch("reason"), "changed_members" => [], "removed_members" => [],
53
+ named = @placeholders.transform_values { format(it, id: finding["id"]) }
54
+ { "finding_id" => finding["id"], "action" => named.fetch("action"),
55
+ "reason" => named.fetch("reason"), "changed_members" => [], "removed_members" => [],
45
56
  "evidence" => [],
46
- "reassessment" => @placeholders.fetch("reassessment"), "recorded_at" => nil, "waits_on" => nil }
57
+ "reassessment" => named.fetch("reassessment"), "recorded_at" => nil, "waits_on" => nil }
47
58
  end)
48
59
  end
49
60
 
@@ -69,15 +80,10 @@ module Principles
69
80
  "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
70
81
  end
71
82
 
72
- # How to fill the correction by hand: save its answer alone, which show-open-correction prints from the open
73
- # record, to a file, fill only its dispositions there, and submit that file.
83
+ # How to fill the correction by hand: save its answer alone, which show-open-correction prints bare from the
84
+ # open record, to a file, fill only its dispositions there with a file-edit tool, and submit that file.
74
85
  #: (Invocation) -> String
75
- def to_fill_by_hand(invocation)
76
- "Save the correction's answer alone in a file outside the project, such as under $TMPDIR, from this " \
77
- "command's output, which prints it again from the open record whenever you need it: " \
78
- "#{invocation.in_project("show-open-correction", @principle_id)}\nEdit only its dispositions in that " \
79
- "file, then submit it: #{invocation.submit_answer(request_id)}"
80
- end
86
+ def to_fill_by_hand(invocation) = AnswerInAFile.new(invocation).correction(@principle_id, request_id:)
81
87
 
82
88
  # What to keep while the correction is open, and the read-only command that prints its answer again from the
83
89
  # open record, in git or outside it.
@@ -17,6 +17,22 @@ module Principles
17
17
  "ending_at" => "NEW_ENDING_TEXT", "query" => "QUERY",
18
18
  "path" => "NEW_PATH" }.freeze #: Hash[String, String]
19
19
 
20
+ # One move that may repair the member: the locator fields it keeps, by name, and those the agent fills in.
21
+ class Move
22
+ #: Hash[String, String]
23
+ attr_reader :keep
24
+
25
+ #: Array[String]
26
+ attr_reader :fill
27
+
28
+ #: (keep: Hash[String, String], fill: Array[String]) -> void
29
+ def initialize(keep:, fill:)
30
+ @keep = keep
31
+ @fill = fill
32
+ freeze
33
+ end
34
+ end
35
+
20
36
  #: (Invocation) -> void
21
37
  def initialize(invocation)
22
38
  @invocation = invocation
@@ -25,14 +41,14 @@ module Principles
25
41
 
26
42
  # The repairs for member_id of principle id: each of moves, as Models::MemberRepairMoves gives them, the locator
27
43
  # fields it keeps and those to fill in, as a copyable move-member, then remove-member.
28
- #: (String, String, Array[Hash[String, untyped]]) -> Array[String]
44
+ #: (String, String, Array[Move]) -> Array[String]
29
45
  def commands(id, member_id, moves)
30
46
  [*moves.map { move(id, member_id, it) }, @invocation.in_project("remove-member", id, member_id)]
31
47
  end
32
48
 
33
49
  # member, as show-principle prints it, with its repairs as repair_with when moves, its moves, are given, as the
34
50
  # controller gives them for a member an audit would refuse.
35
- #: (String, Hash[String, untyped], Array[Hash[String, untyped]]?) -> Hash[String, untyped]
51
+ #: (String, Hash[String, untyped], Array[Move]?) -> Hash[String, untyped]
36
52
  def beside(id, member, moves)
37
53
  return member unless moves
38
54
 
@@ -41,10 +57,10 @@ module Principles
41
57
 
42
58
  private
43
59
 
44
- #: (String, String, Hash[String, untyped]) -> String
60
+ #: (String, String, Move) -> String
45
61
  def move(id, member_id, move)
46
- kept = move.fetch("keep").flat_map { |field, value| [FLAGS.fetch(field), value] }
47
- fill = move.fetch("fill")
62
+ kept = move.keep.flat_map { |field, value| [FLAGS.fetch(field), value] }
63
+ fill = move.fill
48
64
  usage = fill.map { "#{FLAGS.fetch(it)} #{PLACEHOLDERS.fetch(it)}" }.join(" ") unless fill.empty?
49
65
  @invocation.in_project("move-member", id, member_id, options: kept, usage: usage)
50
66
  end
@@ -52,16 +52,37 @@ module Principles
52
52
  Prompts.text("set-principles-up/what-the-passage-presumes", estimated_tokens: estimated_tokens.to_s)
53
53
  end
54
54
 
55
+ # The passage as the agent pastes it: its text, its size in bytes and estimated tokens, which loads in every
56
+ # session that loads the entry file it goes in, and what it presumes of a teammate without principles.
57
+ class Passage
58
+ #: Integer
59
+ attr_reader :estimated_tokens
60
+
61
+ #: (text: String, bytes: Integer, estimated_tokens: Integer, presumes: String) -> void
62
+ def initialize(text:, bytes:, estimated_tokens:, presumes:)
63
+ @text = text
64
+ @bytes = bytes
65
+ @estimated_tokens = estimated_tokens
66
+ @presumes = presumes
67
+ freeze
68
+ end
69
+
70
+ #: () -> Hash[String, untyped]
71
+ def to_h
72
+ { "text" => @text, "bytes" => @bytes, "estimated_tokens" => @estimated_tokens, "presumes" => @presumes }
73
+ end
74
+ end
75
+
55
76
  # Where the passage can go, as the agent places it from: how this run was started and whether the plugin's
56
- # session-start hook runs in this session, each root entry file's facts, and the passage's text with its size
57
- # and what it presumes of a teammate without principles.
77
+ # session-start hook runs in this session, each root entry file's facts, and the passage.
58
78
  class Placement
59
79
  #: (runs_from: String, session_start_hook_in_this_session: bool, entry_files: Array[Hash[String, untyped]],
60
- #| passage: Hash[String, untyped]) -> void
80
+ #| passage: Passage) -> void
61
81
  def initialize(runs_from:, session_start_hook_in_this_session:, entry_files:, passage:)
62
82
  @fields = { "runs_from" => runs_from,
63
83
  "session_start_hook_in_this_session" => session_start_hook_in_this_session,
64
- "entry_files" => entry_files, "passage" => passage }.freeze #: Hash[String, untyped]
84
+ "entry_files" => entry_files, "passage" => passage.to_h }.freeze #: Hash[String, untyped]
85
+ @passage = passage
65
86
  freeze
66
87
  end
67
88
 
@@ -70,7 +91,7 @@ module Principles
70
91
 
71
92
  # The passage's estimated size, which loads in every session that loads the entry file it goes in.
72
93
  #: () -> Integer
73
- def estimated_tokens = @fields.fetch("passage").fetch("estimated_tokens")
94
+ def estimated_tokens = @passage.estimated_tokens
74
95
 
75
96
  # Whether the plugin's hooks report in this session, so its hook entries need no offer.
76
97
  #: () -> bool
@@ -4,6 +4,7 @@
4
4
  require_relative "assessment_request"
5
5
  require_relative "context_parts"
6
6
  require_relative "invocation"
7
+ require_relative "answer_in_a_file"
7
8
  require_relative "shell_word"
8
9
  require_relative "trimmed_instructions_note"
9
10
 
@@ -21,18 +22,19 @@ module Principles
21
22
 
22
23
  # The index of request, with the note naming the instructions it prints only in part, the command that submits
23
24
  # its answer and, as the next step, reading each part, where skipping a carried member's is the agent's choice,
24
- # then the one printing that answer to fill, which is too large to carry here, keeping each carried entry.
25
+ # then filling the answer the template part prints bare, which is too large to carry here, keeping each carried
26
+ # entry, in a file the agent edits with its own tool, since escaping prose for a shell took a script.
25
27
  #: (Hash[String, untyped], AssessmentRequest) -> Hash[String, untyped]
26
28
  def printed(index, request)
27
- to_fill = @invocation.in_project("start-audit", request.principle_id,
28
- options: ["--part", ContextParts::TEMPLATE])
29
+ request_id = index.fetch("request_id")
29
30
  read = "Run part_command with each part as printed; skipping a member marked carries_forward is fine, " \
30
31
  "unless you judge it again. --as template prints the same answer long, with each slot's help. " \
31
- "Then fill in the answer this command prints"
32
+ "Then fill in the answer the response_template part prints"
33
+ fill = AnswerInAFile.new(@invocation).assessment(request.principle_id, request_id:)
32
34
  listed(index, request.principle_id)
33
35
  .merge(TrimmedInstructionsNote.new(request.trimmed_instruction_fields).to_h)
34
- .merge("answer_with" => @invocation.submit_answer(index.fetch("request_id")),
35
- "next_action" => "#{read}, #{carried(request)}, and submit it with answer_with: #{to_fill}")
36
+ .merge("answer_with" => @invocation.submit_answer(request_id),
37
+ "next_action" => "#{read}, #{carried(request)}. #{fill}")
36
38
  end
37
39
 
38
40
  private
@@ -25,7 +25,7 @@ module Principles
25
25
  # an audit would refuse, with its repair_with commands, from the moves repairs gives it.
26
26
  # hook_settings_not_read names each project settings file whose hooks this tool could not read.
27
27
  # loaded_files lists each file the members load once, with the total of those loading at session start.
28
- #: (PrintedPrinciple, repairs: Hash[String, Array[Hash[String, untyped]]],
28
+ #: (PrintedPrinciple, repairs: Hash[String, Array[MemberRepairs::Move]],
29
29
  #| ?hook_settings_not_read: Array[Hash[String, String]], ?loaded_files: Hash[String, untyped])
30
30
  #| -> Hash[String, untyped]
31
31
  def shown(principle, repairs:, hook_settings_not_read: [], loaded_files: {})
@@ -87,7 +87,7 @@ module Principles
87
87
  end
88
88
 
89
89
  # member, with its repairs when repairs names it.
90
- #: (String, Hash[String, untyped], Hash[String, Array[Hash[String, untyped]]]) -> Hash[String, untyped]
90
+ #: (String, Hash[String, untyped], Hash[String, Array[MemberRepairs::Move]]) -> Hash[String, untyped]
91
91
  def repaired(id, member, repairs)
92
92
  MemberRepairs.new(@invocation).beside(id, member, repairs[member.fetch("id")])
93
93
  end
@@ -52,12 +52,17 @@ module Principles
52
52
  status: short.status)
53
53
  end
54
54
 
55
- # at_session_start's stdout, a line for each principle with changed audited members: how many, why that
55
+ # at_session_start's stdout: for one principle with changed audited members, a line saying how many, why that
56
56
  # matters, to act before the user's task, and the command whose output offers acknowledging them or auditing
57
- # again. Its command leaves out --project, as the hook's own commands do, since a session runs in its project.
57
+ # again; for several, one line counting them, whose command lists each, so the line does not grow with their
58
+ # count. Its command leaves out --project, as the hook's own commands do, since a session runs in its project.
58
59
  #: (changed: Hash[String, Integer]) -> Array[String]
59
60
  def session_start_lines(changed:)
60
- changed.map { |id, count| changed_line(id, count) }
61
+ return changed.map { |id, count| changed_line(id, count) } if changed.size <= 1
62
+
63
+ [Prompts.text("start-a-session/act-on-the-changed-principles",
64
+ count: changed.size.to_s,
65
+ command: @invocation.without_project.in_project("list-member-problems", options: ["--short"]))]
61
66
  end
62
67
 
63
68
  private
@@ -54,6 +54,17 @@ module Principles
54
54
  [report.merge("next_action" => action), commands]
55
55
  end
56
56
 
57
+ # report, with each member's history leaving out its commits unless history, which an agent asks for with
58
+ # --history: the rest says what changed and what clears it.
59
+ #: (Hash[String, untyped], history: bool) -> Hash[String, untyped]
60
+ def listed(report, history:)
61
+ return report if history || !report.key?("members")
62
+
63
+ report.merge("members" => report.fetch("members").map do |member|
64
+ member.key?("history") ? member.merge("history" => member.fetch("history").except("commits")) : member
65
+ end)
66
+ end
67
+
57
68
  # For each principle with members no baseline holds, what gives them one: outside git a completed audit,
58
69
  # and in git committing the files no_baseline_files names.
59
70
  #: (Hash[String, untyped], Hash[String, Array[String]]) -> Array[MembersWithNoBaseline]
@@ -0,0 +1,6 @@
1
+ Save the answer alone in a file outside the project, such as under $TMPDIR: %{save} > FILE
2
+
3
+ Fill %{what} with your own file-edit tool, not a shell heredoc; JSON escapes only a double quote, a backslash and a line
4
+ break, as \", \\ and \n, never an apostrophe.
5
+
6
+ Submit that file: %{answer_with}
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "deferred": {
13
13
  "action": "deferred",
14
- "reason": "Why, and what remains",
14
+ "reason": "%{reason_placeholder}",
15
15
  "changed_members": [],
16
16
  "evidence": [],
17
17
  "recorded_at": { "path": "where the project keeps the write-up, or set recorded_at null if none", "starting_at": "the line that states the problem" },
@@ -12,6 +12,7 @@ Run during a full audit, between an accepted assessment and its correction, to f
12
12
  in the `changed_map_entries` of the fixed disposition it fixes, and submit the correction. This tool prints both
13
13
  that step and starting the audit, since it cannot tell in git whether a correction is open.
14
14
 
15
- An id no member has is refused with `unknown_member`. When it differs from one mapped id only in case, spacing,
16
- dashes or quotes, the refusal names that id under `did_you_mean` and starts its repair with this command run on it
17
- instead. This tool never acts on the near miss: check that it is the member you meant before you run it.
15
+ An id no member has is refused with `unknown_member`. When it differs from one mapped id only in case, spacing, dashes
16
+ or quotes, or is the heading or passage of exactly one mapped id given without its path, the refusal names that id under
17
+ `did_you_mean` and starts its repair with this command run on it instead. This tool never acts on the near miss: check
18
+ that it is the member you meant before you run it.
@@ -4,6 +4,7 @@ Run during a full audit, between an accepted assessment and its correction, to f
4
4
  in the `changed_map_entries` of the fixed disposition it fixes, and submit the correction. This tool prints both
5
5
  that step and starting the audit, since it cannot tell in git whether a correction is open.
6
6
 
7
- An id no member has is refused with `unknown_member`. When it differs from one mapped id only in case, spacing,
8
- dashes or quotes, the refusal names that id under `did_you_mean` and starts its repair with this command run on it
9
- instead. This tool never acts on the near miss: check that it is the member you meant before you run it.
7
+ An id no member has is refused with `unknown_member`. When it differs from one mapped id only in case, spacing, dashes
8
+ or quotes, or is the heading or passage of exactly one mapped id given without its path, the refusal names that id under
9
+ `did_you_mean` and starts its repair with this command run on it instead. This tool never acts on the near miss: check
10
+ that it is the member you meant before you run it.