principles 0.0.11 → 0.1.0

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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/lib/principles/controllers/answer.rb +2 -2
  4. data/lib/principles/controllers/assessment.rb +19 -3
  5. data/lib/principles/controllers/audit.rb +14 -4
  6. data/lib/principles/controllers/full_audit_request.rb +16 -10
  7. data/lib/principles/controllers/guidance_search_paths.rb +1 -1
  8. data/lib/principles/controllers/member_addition.rb +4 -1
  9. data/lib/principles/controllers/member_problems_report.rb +7 -6
  10. data/lib/principles/controllers/open_finding_decisions.rb +66 -0
  11. data/lib/principles/controllers/running_tool.rb +22 -5
  12. data/lib/principles/controllers/survey.rb +3 -2
  13. data/lib/principles/data/candidate_files_found.rb +6 -4
  14. data/lib/principles/data/command-steps.json +17 -17
  15. data/lib/principles/data/json_text.rb +5 -1
  16. data/lib/principles/data/parser_message.rb +61 -0
  17. data/lib/principles/data/project_files.rb +4 -2
  18. data/lib/principles/data/running_version.rb +1 -1
  19. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  20. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  21. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  22. data/lib/principles/invocation_options.rb +1 -1
  23. data/lib/principles/launch.rb +5 -3
  24. data/lib/principles/models/after_commit_input.rb +1 -0
  25. data/lib/principles/models/assessment_basis.rb +1 -1
  26. data/lib/principles/models/audit.rb +23 -3
  27. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  28. data/lib/principles/models/audit_record.rb +5 -14
  29. data/lib/principles/models/audit_records.rb +1 -1
  30. data/lib/principles/models/audited_member_lines.rb +1 -1
  31. data/lib/principles/models/candidate_files.rb +1 -1
  32. data/lib/principles/models/candidate_inventory.rb +19 -9
  33. data/lib/principles/models/candidate_outline.rb +1 -1
  34. data/lib/principles/models/changed_regions.rb +1 -1
  35. data/lib/principles/models/command_steps.rb +1 -2
  36. data/lib/principles/models/correction_basis.rb +1 -1
  37. data/lib/principles/models/declared_map_changes.rb +1 -2
  38. data/lib/principles/models/finding_decision.rb +84 -0
  39. data/lib/principles/models/finding_write_ups.rb +2 -1
  40. data/lib/principles/models/first_full_audit.rb +1 -0
  41. data/lib/principles/models/frontmatter_fields.rb +1 -1
  42. data/lib/principles/models/guidance_search_path.rb +1 -1
  43. data/lib/principles/models/guidance_search_paths.rb +5 -1
  44. data/lib/principles/models/head_moves.rb +1 -0
  45. data/lib/principles/models/ignored_candidates.rb +1 -1
  46. data/lib/principles/models/instruction_named.rb +1 -1
  47. data/lib/principles/models/json_path_query.rb +1 -1
  48. data/lib/principles/models/json_path_selectors.rb +1 -1
  49. data/lib/principles/models/json_path_string.rb +1 -1
  50. data/lib/principles/models/last_completed_revision.rb +1 -1
  51. data/lib/principles/models/line_diff.rb +1 -1
  52. data/lib/principles/models/line_span.rb +1 -1
  53. data/lib/principles/models/loading_scope.rb +1 -0
  54. data/lib/principles/models/located_text.rb +1 -1
  55. data/lib/principles/models/map_change.rb +66 -0
  56. data/lib/principles/models/mapped_principles.rb +4 -0
  57. data/lib/principles/models/markdown_file.rb +22 -1
  58. data/lib/principles/models/member.rb +1 -1
  59. data/lib/principles/models/member_elsewhere.rb +1 -1
  60. data/lib/principles/models/member_file.rb +6 -1
  61. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  62. data/lib/principles/models/member_history.rb +1 -1
  63. data/lib/principles/models/member_lines.rb +1 -1
  64. data/lib/principles/models/member_loading_scopes.rb +1 -0
  65. data/lib/principles/models/member_mapping_run.rb +4 -4
  66. data/lib/principles/models/member_moves.rb +1 -2
  67. data/lib/principles/models/member_problems.rb +5 -1
  68. data/lib/principles/models/member_region.rb +1 -1
  69. data/lib/principles/models/members_elsewhere.rb +1 -1
  70. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  71. data/lib/principles/models/members_sharing_lines.rb +1 -1
  72. data/lib/principles/models/misspelt_member_id.rb +1 -1
  73. data/lib/principles/models/open_finding.rb +4 -3
  74. data/lib/principles/models/open_findings_decision.rb +124 -0
  75. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  76. data/lib/principles/models/other_templates_placeholders.rb +1 -0
  77. data/lib/principles/models/outline_budget.rb +1 -1
  78. data/lib/principles/models/outline_group.rb +1 -1
  79. data/lib/principles/models/outline_section.rb +1 -1
  80. data/lib/principles/models/part_named.rb +1 -1
  81. data/lib/principles/models/plain_text_file.rb +1 -1
  82. data/lib/principles/models/principle_history.rb +3 -3
  83. data/lib/principles/models/principle_members.rb +1 -1
  84. data/lib/principles/models/problem_report.rb +13 -1
  85. data/lib/principles/models/project.rb +8 -3
  86. data/lib/principles/models/project_at_commit.rb +9 -19
  87. data/lib/principles/models/prose_line.rb +36 -0
  88. data/lib/principles/models/record_format.rb +17 -4
  89. data/lib/principles/models/recorded_finding.rb +47 -7
  90. data/lib/principles/models/recorded_findings.rb +7 -7
  91. data/lib/principles/models/recorded_hashes.rb +1 -1
  92. data/lib/principles/models/recorded_members.rb +6 -8
  93. data/lib/principles/models/report_hooks.rb +1 -0
  94. data/lib/principles/models/request_id.rb +2 -2
  95. data/lib/principles/models/sent_answer.rb +1 -0
  96. data/lib/principles/models/session_start_input.rb +1 -0
  97. data/lib/principles/models/stale_request.rb +22 -8
  98. data/lib/principles/models/submitted_answer.rb +1 -1
  99. data/lib/principles/models/survey_search_paths.rb +13 -5
  100. data/lib/principles/models/text_within.rb +1 -1
  101. data/lib/principles/models/unchecked_members.rb +1 -0
  102. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  103. data/lib/principles/models/unknown_principle.rb +1 -0
  104. data/lib/principles/models/write_up_opening.rb +5 -31
  105. data/lib/principles/models/write_up_pointer.rb +2 -1
  106. data/lib/principles/start_audit_options.rb +25 -18
  107. data/lib/principles/version.rb +2 -2
  108. data/lib/principles/views/acknowledgement_result.rb +12 -9
  109. data/lib/principles/views/added_member.rb +10 -1
  110. data/lib/principles/views/answer_in_a_file.rb +16 -4
  111. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  112. data/lib/principles/views/assessment_request.rb +2 -26
  113. data/lib/principles/views/audit_result.rb +15 -6
  114. data/lib/principles/views/candidate_files_result.rb +9 -4
  115. data/lib/principles/views/context_parts.rb +40 -9
  116. data/lib/principles/views/correction_request.rb +8 -5
  117. data/lib/principles/views/first_audit_brief.rb +2 -1
  118. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  119. data/lib/principles/views/invocation.rb +14 -4
  120. data/lib/principles/views/json_on_one_line.rb +18 -0
  121. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  122. data/lib/principles/views/problem_facts.rb +46 -0
  123. data/lib/principles/views/problem_result.rb +42 -31
  124. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  125. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  126. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  127. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  128. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  129. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  130. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  131. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  132. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  133. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  134. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  135. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  136. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  137. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  138. metadata +14 -7
  139. data/lib/principles/controllers/repoint.rb +0 -67
  140. data/lib/principles/models/repoint.rb +0 -125
  141. data/lib/principles/models/write_up_repoint.rb +0 -38
  142. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  143. data/lib/principles/views/repoint_result.rb +0 -80
@@ -4,19 +4,21 @@
4
4
  require_relative "invocation_options"
5
5
 
6
6
  module Principles
7
- # The options that choose which audit start-audit begins, --member and --write-ups, and the form --as prints
8
- # it in, and what is wrong with them as given, which CommandLine refuses as a usage error.
7
+ # The options that choose which audit start-audit begins, --member or --open-findings, and the form
8
+ # --as prints it in, and what is wrong with them as given, which CommandLine refuses as a usage error.
9
9
  class StartAuditOptions
10
10
  # The part that prints the answer to fill bare, saved as it stands, so no other part may print beside it.
11
11
  TEMPLATE_PART = "response_template" #: String
12
+ # Each option that starts an audit other than a full one, by its key among the options, and its flag.
13
+ AUDITS = { "member" => "--member",
14
+ "open_findings" => "--open-findings" }.freeze #: Hash[String, String]
12
15
 
13
16
  # several_ids is whether start-audit was given more than one principle id.
14
17
  #: (InvocationOptions, ?several_ids: bool) -> void
15
18
  def initialize(options, several_ids: false)
16
19
  @several_ids = several_ids
17
20
  @members = options.value("member") || [] #: Array[String]
18
- @member = !@members.empty? #: bool
19
- @write_ups = !options.value("write_ups").nil? #: bool
21
+ @audits = AUDITS.reject { |key, _| options.value(key).nil? }.values #: Array[String]
20
22
  @form = options.value("as") #: String?
21
23
  @instruction = !options.value("instruction").nil? #: bool
22
24
  @parts = options.value("part") || [] #: Array[String]
@@ -27,17 +29,25 @@ module Principles
27
29
  # What is wrong with the options as given, or nil when they fit.
28
30
  #: () -> String?
29
31
  def fault
30
- return "--member and --write-ups each start a different audit; give one" if @member && @write_ups
31
-
32
- several_ids_fault || member_fault || part_fault || instruction_fault || form_fault
32
+ audits_fault || several_ids_fault || member_fault || part_fault || instruction_fault || form_fault
33
33
  end
34
34
 
35
35
  private
36
36
 
37
+ # Two of the options that each start a different audit; nil when at most one is given.
38
+ #: () -> String?
39
+ def audits_fault
40
+ "#{@audits.first(2).join(" and ")} each start a different audit; give one" if @audits.size > 1
41
+ end
42
+
43
+ # Whether flag, one of AUDITS, was given.
44
+ #: (String) -> bool
45
+ def audit?(flag) = @audits.include?(flag)
46
+
37
47
  # Several principle ids, which only an acknowledgement of members they each map spans; nil otherwise.
38
48
  #: () -> String?
39
49
  def several_ids_fault
40
- return unless @several_ids && !@member
50
+ return unless @several_ids && !audit?("--member")
41
51
 
42
52
  "several principle ids start one acknowledgement of the members they map, with --member; give one id for " \
43
53
  "any other audit"
@@ -74,29 +84,26 @@ module Principles
74
84
  "--instruction prints one field of a full audit's request, not of #{other}" if other
75
85
  end
76
86
 
77
- # What --as, --member or --write-ups prints instead of a full audit's request, which --part and --instruction each
78
- # read from; nil when none is given.
87
+ # What --as, --member or --open-findings prints instead of a full audit's request, which --part and --instruction
88
+ # each read from; nil when none is given.
79
89
  #: () -> String?
80
90
  def other_output
81
91
  @form ? "the answer --as template prints" : other_audit
82
92
  end
83
93
 
84
- # What --member or --write-ups starts instead of a full audit; nil when neither is given.
94
+ # What --member or --open-findings starts instead of a full audit; nil when neither is given.
85
95
  #: () -> String?
86
96
  def other_audit
87
- if @member then "the one-member audit --member starts"
88
- elsif @write_ups then "the repoint --write-ups starts"
97
+ if audit?("--member") then "the one-member audit --member starts"
98
+ elsif audit?("--open-findings") then "the decision --open-findings starts"
89
99
  end
90
100
  end
91
101
 
92
- # --as template prints a full audit's answer alone, or a one-member audit's, the one form
93
- # built so far; nil when it fits.
102
+ # --as template prints an audit's answer alone, the one form built so far; nil when it fits.
94
103
  #: () -> String?
95
104
  def form_fault
96
105
  form = @form or return
97
- return "--as takes template, the answer alone, not #{form}" unless form == "template"
98
-
99
- "--as template prints a full or one-member audit's answer, not one --write-ups starts" if @write_ups
106
+ "--as takes template, the answer alone, not #{form}" unless form == "template"
100
107
  end
101
108
  end
102
109
  end
@@ -3,9 +3,9 @@
3
3
 
4
4
  module Principles
5
5
  # The next production release, as major.minor.patch. A production build is versioned with this alone.
6
- RELEASE = "0.0.11"
6
+ RELEASE = "0.1.0"
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.11" #: String?
10
+ BUILT_VERSION = "0.1.0" #: String?
11
11
  end
@@ -23,12 +23,13 @@ module Principles
23
23
  # asked is what the request asks of its member: under :change its change since its baseline; under :context
24
24
  # what the request's context shows beside it, such as the record's findings on the member; and under
25
25
  # :placeholders the text the template prints in each field the agent writes. What the agent judges is under
26
- # context, the question last, as in a full audit's request.
26
+ # context, the question first, so an agent reading the request's head finds what it is asked before the text.
27
27
  #: (request_id: String, principle_id: String, asked: Hash[Symbol, untyped]) -> Hash[String, untyped]
28
28
  def request(request_id:, principle_id:, asked:)
29
29
  { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "acknowledgement",
30
- "context" => { "principle_id" => principle_id, **asked.fetch(:change).to_h, **asked.fetch(:context),
31
- "question" => Prompts.text("acknowledge-a-change/say-whether-the-change-keeps-the-meaning") },
30
+ "context" => { "principle_id" => principle_id,
31
+ "question" => Prompts.text("acknowledge-a-change/say-whether-the-change-keeps-the-meaning"),
32
+ **asked.fetch(:change).to_h, **asked.fetch(:context) },
32
33
  "response_template" => answer_to_fill(request_id:, asked:),
33
34
  "answer_with" => @invocation.submit_answer(request_id),
34
35
  "next_action" => to_fill([principle_id], [asked.fetch(:change).member_id], request_id:) }
@@ -47,13 +48,14 @@ module Principles
47
48
 
48
49
  # The request for several members' acknowledgements in one answer: each of members holds a member's
49
50
  # change, the context its own request shows beside it and the placeholders its template prints, as one member's
50
- # request holds them, under context.members and the template's members in the order the agent named them.
51
+ # request holds them, under context.members and the template's members in the order the agent named them. The
52
+ # question leads the context, so an agent reading the request's head finds what it is asked before the members.
51
53
  #: (request_id: String, principle_id: String, members: Array[Hash[Symbol, untyped]]) -> Hash[String, untyped]
52
54
  def several_request(request_id:, principle_id:, members:)
53
55
  { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "acknowledgements",
54
56
  "context" => { "principle_id" => principle_id,
55
- "members" => shown(members),
56
- "question" => Prompts.text("acknowledge-a-change/say-whether-each-change-keeps-its-meaning") },
57
+ "question" => Prompts.text("acknowledge-a-change/say-whether-each-change-keeps-its-meaning"),
58
+ "members" => shown(members) },
57
59
  "response_template" => several_to_fill(request_id:, members:),
58
60
  "answer_with" => @invocation.submit_answer(request_id),
59
61
  "next_action" => to_fill([principle_id], members.map { it.fetch(:change).member_id }, request_id:) }
@@ -70,13 +72,14 @@ module Principles
70
72
  # The request for the members several principles map in one answer: under context.principles, each
71
73
  # principle's members as its own request for several shows them, and in the template one entry per member,
72
74
  # judged once for every principle that maps it. keeping_deferred names each principle whose members keep a
73
- # deferred finding, which the request says only a full audit resolves.
75
+ # deferred finding, which the request says only a full audit resolves. The question leads the context, as in
76
+ # one principle's requests.
74
77
  #: (request_id: String, principles: Hash[String, Array[Hash[Symbol, untyped]]],
75
78
  #| ?keeping_deferred: Array[String]) -> Hash[String, untyped]
76
79
  def across_request(request_id:, principles:, keeping_deferred: [])
77
80
  { "status" => "agent_judgement_required", "request_id" => request_id, "phase" => "acknowledgements",
78
- "context" => { "principles" => shown_once(principles),
79
- **deferred_findings_kept(keeping_deferred), "question" => across_question },
81
+ "context" => { "question" => across_question, "principles" => shown_once(principles),
82
+ **deferred_findings_kept(keeping_deferred) },
80
83
  "response_template" => across_to_fill(request_id:, principles:),
81
84
  "answer_with" => @invocation.submit_answer(request_id),
82
85
  "next_action" => to_fill(principles.keys.uniq.sort, across_member_ids(principles), request_id:) }
@@ -34,7 +34,16 @@ module Principles
34
34
  #: () -> String
35
35
  def span
36
36
  "#{id} spans lines #{@added.fetch("first_line")} to #{@added.fetch("last_line")}; " \
37
- "if that is not the passage you meant, move it with move-member. "
37
+ "if that is not the passage you meant, move it with move-member. #{runs_on}"
38
+ end
39
+
40
+ # What the agent judges when the paragraph or list item a one-line passage starts runs on past it; it ends with
41
+ # a space, or is empty.
42
+ #: () -> String
43
+ def runs_on
44
+ line = @added["continues_to_line"] or return ""
45
+ "Its paragraph or list item continues to line #{line}; if the member is all of it, move it with " \
46
+ "--ending-at quoting the words that end it. "
38
47
  end
39
48
  end
40
49
  end
@@ -4,13 +4,15 @@
4
4
  require_relative "context_parts"
5
5
  require_relative "invocation"
6
6
  require_relative "prompts"
7
+ require_relative "shell_word"
7
8
 
8
9
  module Principles
9
10
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
10
11
  module Views
11
- # 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.
12
+ # How to fill an answer this tool prints bare: save it to a file outside the project, named in full, fill it
13
+ # there with the agent's own file-edit tool, and submit that file, with the three characters JSON escapes.
14
+ # Filling a template in a shell heredoc took a script, since prose full of quotes needed escaping for the shell
15
+ # and for JSON.
14
16
  class AnswerInAFile
15
17
  #: (Invocation) -> void
16
18
  def initialize(invocation)
@@ -34,6 +36,14 @@ module Principles
34
36
  request_id:)
35
37
  end
36
38
 
39
+ # The line for a decision on principle_id's open findings, whose answer start-audit --open-findings --as template
40
+ # prints bare.
41
+ #: (String, request_id: String) -> String
42
+ def open_findings(principle_id, request_id:)
43
+ line(@invocation.in_project("start-audit", principle_id, options: %w[--open-findings --as template]),
44
+ request_id:)
45
+ end
46
+
37
47
  # The line for an open correction, whose answer show-open-correction prints bare, of which only the
38
48
  # dispositions are the agent's to fill.
39
49
  #: (String, request_id: String) -> String
@@ -45,8 +55,10 @@ module Principles
45
55
  # the agent fills.
46
56
  #: (String, request_id: String, ?what: String) -> String
47
57
  def line(save, request_id:, what: "it")
58
+ file = @invocation.answer_file(request_id)
48
59
  Prompts.text("answer-any-judgement-request/fill-the-answer-in-a-file",
49
- save:, what:, answer_with: @invocation.submit_answer(request_id))
60
+ save: "#{save} > #{ShellWord.new(file)}", what:,
61
+ answer_with: @invocation.submit_answer(request_id, file:))
50
62
  end
51
63
  end
52
64
  end
@@ -0,0 +1,59 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "assessed_members"
5
+ require_relative "instruction"
6
+ require_relative "json_on_one_line"
7
+ require_relative "prompts"
8
+
9
+ module Principles
10
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
11
+ module Views
12
+ # The guide to a full audit's answer shapes, printed under answer_guide with the entries whose case the request's
13
+ # members hold.
14
+ class AssessmentAnswerGuide
15
+ #: (AssessedMembers) -> void
16
+ def initialize(members)
17
+ @members = members
18
+ freeze
19
+ end
20
+
21
+ # The answer guide, showing check_result's fields only when a member has a check, so an audit
22
+ # with no checks costs no more context than before, and delivery's shapes only when a member is judged
23
+ # afresh, since a carried member's marker gives none. check_result's limits say how to review a check
24
+ # before running it only when a check is new or changed, as that check's own template says too.
25
+ #: () -> GuideInstruction
26
+ def instruction
27
+ guide = with_examples_on_lines(Prompts.data("assess-every-member/answer-guide"))
28
+ narrowed = @members.check_to_review? ? {} : guide.slice("check_result")
29
+ GuideInstruction.new("answer_guide", guide.merge("check_result" => reviewed(guide.fetch("check_result"))),
30
+ narrowed:) do |entry|
31
+ case entry
32
+ when "check_result" then @members.checked?
33
+ when "member_delivery" then @members.judged_afresh?
34
+ else true
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # guide with each entry's examples printing compact, a line each, since the agent copies each one whole.
42
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
43
+ def with_examples_on_lines(guide)
44
+ guide.transform_values do |entry|
45
+ next entry unless entry.is_a?(Hash) && entry.key?("examples")
46
+
47
+ entry.merge("examples" => entry.fetch("examples").transform_values { JsonOnOneLine[it] })
48
+ end
49
+ end
50
+
51
+ # check_result's guide entry whole, its limits ending with how to review a new or changed check before running it.
52
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
53
+ def reviewed(check_result)
54
+ review = Prompts.text("assess-every-member/review-a-new-or-changed-check-before-running-it")
55
+ check_result.merge("limits" => "#{check_result.fetch("limits")} #{review}")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "answer_head"
5
+ require_relative "assessment_answer_guide"
5
6
  require_relative "assessed_members"
6
7
  require_relative "context_parts"
7
8
  require_relative "instruction"
@@ -142,7 +143,7 @@ module Principles
142
143
  #: () -> Array[Instruction | GuideInstruction]
143
144
  def instructions
144
145
  [question, judge_because_instruction,
145
- carried_forward_instruction, mapped_elsewhere_instruction, answer_guide]
146
+ carried_forward_instruction, mapped_elsewhere_instruction, AssessmentAnswerGuide.new(@members).instruction]
146
147
  end
147
148
 
148
149
  # The question, defining observed only when a member is judged afresh, whose delivery it guides.
@@ -176,31 +177,6 @@ module Principles
176
177
  end
177
178
  end
178
179
 
179
- # The answer guide, showing check_result's fields only when a member has a check, so an audit
180
- # with no checks costs no more context than before, and delivery's shapes only when a member is judged
181
- # afresh, since a carried member's marker gives none. check_result's limits say how to review a check
182
- # before running it only when a check is new or changed, as that check's own template says too.
183
- #: () -> GuideInstruction
184
- def answer_guide
185
- guide = Prompts.data("assess-every-member/answer-guide")
186
- narrowed = @members.check_to_review? ? {} : guide.slice("check_result")
187
- GuideInstruction.new("answer_guide", guide.merge("check_result" => reviewed(guide.fetch("check_result"))),
188
- narrowed:) do |entry|
189
- case entry
190
- when "check_result" then @members.checked?
191
- when "member_delivery" then @members.judged_afresh?
192
- else true
193
- end
194
- end
195
- end
196
-
197
- # check_result's guide entry whole, its limits ending with how to review a new or changed check before running it.
198
- #: (Hash[String, untyped]) -> Hash[String, untyped]
199
- def reviewed(check_result)
200
- review = Prompts.text("assess-every-member/review-a-new-or-changed-check-before-running-it")
201
- check_result.merge("limits" => "#{check_result.fetch("limits")} #{review}")
202
- end
203
-
204
180
  # How to answer when the request carries some members' last assessments forward; nothing when it carries none.
205
181
  # What a compact carried member shows, and what prints one whole, only when one prints compactly.
206
182
  #: () -> Instruction
@@ -11,6 +11,7 @@ require_relative "invocation"
11
11
  require_relative "prior_finding_decisions_result"
12
12
  require_relative "prompts"
13
13
  require_relative "report_hooks_offer"
14
+ require_relative "shell_word"
14
15
  require_relative "trimmed_instructions_note"
15
16
  require_relative "../prose_list"
16
17
 
@@ -95,11 +96,10 @@ module Principles
95
96
 
96
97
  # start-audit: the assessment request, as a judgement to answer under its request id, its context naming the
97
98
  # instructions it prints only in part and the flag that prints one whole, so a trimmed field is not taken for
98
- # the whole, without the command the agent just ran. Its head names the command listing its parts, so a long
99
- # request is read in parts rather than paged by script.
100
- #: (AssessmentRequest) -> Hash[String, untyped]
101
- def assessment_request(request)
102
- output = judgement("assessment", request, { "read_in_parts" => read_in_parts(request.principle_id) },
99
+ # the whole, without the command the agent just ran, after its head, which sizes each part as part_bytes.
100
+ #: (AssessmentRequest, part_bytes: Hash[String, Integer]) -> Hash[String, untyped]
101
+ def assessment_request(request, part_bytes:)
102
+ output = judgement("assessment", request, assessment_head(request.principle_id, part_bytes),
103
103
  to_fill: { "response_template" => request.template })
104
104
  note = TrimmedInstructionsNote.new(request.trimmed_instruction_fields).to_h
105
105
  fill = AnswerInAFile.new(@invocation).assessment(request.principle_id, request_id: request.request_id)
@@ -182,6 +182,15 @@ module Principles
182
182
  result.merge(field => facts, "next_action" => [judge, result["next_action"]].compact.join("\n"))
183
183
  end
184
184
 
185
+ # What a full audit's request of principle_id prints before its context: the command listing its parts, so a
186
+ # long request is read in parts rather than paged by script, and part_bytes, each part's bytes by its name as a
187
+ # shell reads it, as the index prints them, so the agent sizes its reads without running a script for them.
188
+ #: (String, Hash[String, Integer]) -> Hash[String, untyped]
189
+ def assessment_head(principle_id, part_bytes)
190
+ { "read_in_parts" => read_in_parts(principle_id),
191
+ "part_bytes" => part_bytes.transform_keys { ShellWord.new(it).to_s } }
192
+ end
193
+
185
194
  # How to read principle_id's full-audit request in parts: the command listing them, and the flag printing one.
186
195
  #: (String) -> String
187
196
  def read_in_parts(principle_id)
@@ -192,7 +201,7 @@ module Principles
192
201
  # request as a judgement to answer in phase, under its id, which its template's head also gives, with any
193
202
  # opening fields after the phase and before the context, and to_fill, the answer to fill when this request
194
203
  # prints it, after the context.
195
- #: (String, AssessmentRequest | CorrectionRequest, ?Hash[String, String], ?to_fill: Hash[String, untyped])
204
+ #: (String, AssessmentRequest | CorrectionRequest, ?Hash[String, untyped], ?to_fill: Hash[String, untyped])
196
205
  #| -> Hash[String, untyped]
197
206
  def judgement(phase, request, opening = {}, to_fill: {})
198
207
  { "status" => "agent_judgement_required", "request_id" => request.request_id, "phase" => phase, **opening,
@@ -33,12 +33,15 @@ module Principles
33
33
  #: () -> Integer?
34
34
  def range_outlines_bytes = @inventory["range_outlines_bytes"]
35
35
 
36
+ # conventional says whether the survey looked in the places hosts load by convention, as it does
37
+ # unless --only narrowed it to its globs' matches.
36
38
  #: (inventory: Hash[String, untyped], untracked: Array[String]?,
37
- #| owner_asks: Hash[String, Array[String]]) -> void
38
- def initialize(inventory:, untracked:, owner_asks:)
39
+ #| owner_asks: Hash[String, Array[String]], ?conventional: bool) -> void
40
+ def initialize(inventory:, untracked:, owner_asks:, conventional: true)
39
41
  @inventory = inventory
40
42
  @untracked = untracked
41
43
  @owner_asks = owner_asks
44
+ @conventional = conventional
42
45
  freeze
43
46
  end
44
47
 
@@ -47,8 +50,10 @@ module Principles
47
50
  #: () -> Hash[String, untyped]
48
51
  def listed
49
52
  files = @inventory.fetch("files").map { |file| file.slice(*PRINTED_FILE_FIELDS) }
50
- listed = @inventory.merge("files" => files,
51
- "scope" => Prompts.text("find-a-principle-to-map/where-the-inventory-looks"))
53
+ scope = if @conventional then Prompts.text("find-a-principle-to-map/where-the-inventory-looks")
54
+ else Prompts.text("find-a-principle-to-map/where-a-survey-with-only-looks")
55
+ end
56
+ listed = @inventory.merge("files" => files, "scope" => scope)
52
57
  @untracked ? listed.merge("untracked" => @untracked) : listed
53
58
  end
54
59
  end
@@ -1,6 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative "../prose_list"
4
5
  require_relative "member_lines_beside_text"
5
6
  require_relative "printed_json"
6
7
 
@@ -20,10 +21,6 @@ module Principles
20
21
  # The part holding the answer to fill, as the request prints it beside its context.
21
22
  TEMPLATE = "response_template" #: String
22
23
 
23
- # What --part prints for an optional part the request leaves out, holding nothing for it.
24
- EMPTY = { "part_empty" => "Nothing to list for this request; " \
25
- "the answer needs nothing for it." }.freeze #: Hash[String, String]
26
-
27
24
  # instruction_fields is each field the context prints an instruction under, in order. template is the answer to
28
25
  # fill, as the request prints it. texts is each member's lines now, by id, one string each, which its part
29
26
  # prints and the whole request does not. optional names each part the context lists only when it holds something.
@@ -54,12 +51,16 @@ module Principles
54
51
  #: () -> Array[String]
55
52
  def left_out = @optional - @context.keys
56
53
 
54
+ # Each part's name, as names lists it, with the bytes --part prints of its value.
55
+ #: () -> Hash[String, Integer]
56
+ def part_bytes = names.to_h { [it, bytes(shown(it))] }
57
+
57
58
  # The part name, under its key, as the context prints it; a member's entry alone under members, with its text
58
59
  # when given, its id read after the one prefix, so an id with a slash, or starting members/, is read whole.
59
60
  #: (String) -> Hash[String, untyped]
60
61
  def shown(name)
61
62
  return { INDEX => index } if name == INDEX
62
- return EMPTY if left_out.include?(name)
63
+ return empty([name]) if left_out.include?(name)
63
64
  return @template if name == TEMPLATE
64
65
  return { name => @context.fetch(name) } unless name.start_with?(MEMBER)
65
66
 
@@ -67,16 +68,46 @@ module Principles
67
68
  { "members" => members.select { it.fetch("id") == id }.map { with_text(it) } }
68
69
  end
69
70
 
71
+ # The parts names, each as shown prints it, printed together: each member's in one members list and each empty
72
+ # one named in one part_empty, in the order given, where merging the parts one by one leaves the last alone.
73
+ #: (Array[String]) -> Hash[String, untyped]
74
+ def shown_together(names)
75
+ together = names.reduce({}) { |all, name| all.merge(shown(name)) } #: Hash[String, untyped]
76
+ with_every_empty(with_every_member(together, names), names)
77
+ end
78
+
70
79
  private
71
80
 
81
+ # together with each member names names in one members list; together as it is when names name no member.
82
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
83
+ def with_every_member(together, names)
84
+ return together unless together.key?("members")
85
+
86
+ together.merge("members" => names.flat_map { shown(it).fetch("members", []) })
87
+ end
88
+
89
+ # together with one part_empty naming every empty part names; together as it is when names name none.
90
+ #: (Hash[String, untyped], Array[String]) -> Hash[String, untyped]
91
+ def with_every_empty(together, names)
92
+ empty_named = names & left_out
93
+ empty_named.empty? ? together : together.merge(empty(empty_named))
94
+ end
95
+
96
+ # What --part prints for the optional parts names, which the request leaves out for holding nothing, naming each
97
+ # in the order given, so the agent knows which of the parts it asked for were empty.
98
+ #: (Array[String]) -> Hash[String, String]
99
+ def empty(names)
100
+ { "part_empty" => "Nothing to list for #{ProseList.new(names)} in this request; " \
101
+ "the answer needs nothing for #{names.one? ? "it" : "them"}." }
102
+ end
103
+
72
104
  # Each part with the bytes --part prints of its value, and each member with whether this audit judges it, and
73
105
  # why when the request says, or carries its last assessment forward.
74
106
  #: () -> Array[Hash[String, untyped]]
75
107
  def index
76
- names.map do |name|
77
- part = shown(name)
78
- entry = { "part" => name, "bytes" => bytes(part) }
79
- name.start_with?(MEMBER) ? entry.merge(judged(part.fetch("members").fetch(0))) : entry
108
+ part_bytes.map do |name, size|
109
+ entry = { "part" => name, "bytes" => size }
110
+ name.start_with?(MEMBER) ? entry.merge(judged(shown(name).fetch("members").fetch(0))) : entry
80
111
  end
81
112
  end
82
113
 
@@ -5,6 +5,7 @@ require_relative "answer_head"
5
5
  require_relative "answer_in_a_file"
6
6
  require_relative "invocation"
7
7
  require_relative "prompts"
8
+ require_relative "shell_word"
8
9
 
9
10
  module Principles
10
11
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -67,15 +68,17 @@ module Principles
67
68
  view.request(view.correction_request(self))
68
69
  end
69
70
 
70
- # How to save and fill the correction's answer after submitting the checked assessment, naming the command that
71
- # prints it alone rather than printing it here; keep its submit last.
71
+ # How to save and fill the correction's answer after submitting the checked assessment, to the file named in full
72
+ # that its submit names too, naming the command that prints it alone rather than printing it here; keep its
73
+ # submit last.
72
74
  #: (Hash[String, untyped], Invocation, String) -> Hash[String, untyped]
73
75
  def with_correction_to_fill(acceptable, invocation, answer_file)
74
76
  assessment_id = acceptable.fetch("request_id")
77
+ file = invocation.answer_file(request_id)
75
78
  save = "Once this answer is submitted with the last line's command, save the correction's answer it leads " \
76
- "to in a file outside the project, such as under $TMPDIR, from this command's output: " \
77
- "#{alone(assessment_id, answer_file, invocation)}\nFill only its dispositions, and submit it: " \
78
- "#{invocation.submit_answer(request_id)}"
79
+ "to in a file outside the project, at this full path, the same from every shell, from this command's " \
80
+ "output: #{alone(assessment_id, answer_file, invocation)} > #{ShellWord.new(file)}\nFill only its " \
81
+ "dispositions, and submit it: #{invocation.submit_answer(request_id, file:)}"
79
82
  acceptable.merge("correction_recovery" => recovery(invocation),
80
83
  "next_action" => "#{save}\n#{acceptable.fetch("next_action")}")
81
84
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "invocation"
5
5
  require_relative "prompts"
6
+ require_relative "shell_word"
6
7
 
7
8
  module Principles
8
9
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -25,7 +26,7 @@ module Principles
25
26
  def result(id)
26
27
  { "principle" => id,
27
28
  "brief" => Prompts.text("run-a-first-audit-in-the-background/follow-the-brief",
28
- id: id,
29
+ id: id, answer_file: ShellWord.new(@invocation.answer_file(id)).to_s,
29
30
  index: @invocation.in_project("start-audit", id, options: ["--part", "index"]),
30
31
  template: @invocation.in_project("start-audit", id, options: ["--as", "template"])),
31
32
  "wrote" => [] }
@@ -6,7 +6,8 @@ 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 recorded list and an immediate read-only survey after a guidance-search-path write.
9
+ # The recorded list and an immediate read-only survey after a guidance-search-path write: after an addition,
10
+ # of just the files the added glob matches, since the rest were surveyed before it.
10
11
  class GuidanceSearchPathsResult
11
12
  #: (Invocation) -> void
12
13
  def initialize(invocation)
@@ -14,12 +15,18 @@ module Principles
14
15
  freeze
15
16
  end
16
17
 
17
- #: (status: String, globs: Array[String], wrote: Array[String]) -> Hash[String, untyped]
18
- def result(status:, globs:, wrote:)
19
- survey = @invocation.in_project("list-candidate-files")
18
+ #: (status: String, globs: Array[String], wrote: Array[String], added: String?) -> Hash[String, untyped]
19
+ def result(status:, globs:, wrote:, added:)
20
20
  { "status" => status, "recorded_guidance_search_paths" => globs, "wrote" => wrote,
21
- "next_action" => "Commit changed configuration.\n" \
22
- "Survey again using the saved search paths: #{survey}" }
21
+ "next_action" => "Commit changed configuration.\n#{survey(added)}" }
22
+ end
23
+
24
+ private
25
+
26
+ #: (String?) -> String
27
+ def survey(added)
28
+ survey = @invocation.in_project("list-candidate-files", options: added ? ["--only", added] : [])
29
+ added ? "Survey just the files it matches: #{survey}" : "Survey again using the saved search paths: #{survey}"
23
30
  end
24
31
  end
25
32
  end
@@ -15,11 +15,13 @@ module Principles
15
15
  #: String
16
16
  attr_reader :project
17
17
 
18
- # named says whether each command names the project; without_project leaves it out.
19
- #: (executable: String, project: String, ?named: bool) -> void
20
- def initialize(executable:, project:, named: true)
18
+ # named says whether each command names the project; without_project leaves it out. temp_directory is the
19
+ # temporary folder the running tool was given, where a printed next step saves an answer.
20
+ #: (executable: String, project: String, temp_directory: String, ?named: bool) -> void
21
+ def initialize(executable:, project:, temp_directory:, named: true)
21
22
  @executable = executable
22
23
  @project = project
24
+ @temp_directory = temp_directory
23
25
  @named = named
24
26
  freeze
25
27
  end
@@ -27,7 +29,9 @@ module Principles
27
29
  # The same invocation, its commands leaving out --project, for output that names the project once and whose
28
30
  # commands run from there, as list-member-problems --short's stderr does.
29
31
  #: () -> Invocation
30
- def without_project = Invocation.new(executable: @executable, project: @project, named: false)
32
+ def without_project
33
+ Invocation.new(executable: @executable, project: @project, temp_directory: @temp_directory, named: false)
34
+ end
31
35
 
32
36
  # Whether each command names the project.
33
37
  #: () -> bool
@@ -55,6 +59,12 @@ module Principles
55
59
  in_project("submit-answer", request_id, options: ["--file", file])
56
60
  end
57
61
 
62
+ # The file to save the answer name names in, a request id or a principle id, by its full path in the temporary
63
+ # folder, so every shell that runs the printed commands names the same file: a sandboxed and an unsandboxed one
64
+ # read $TMPDIR as different folders.
65
+ #: (String) -> String
66
+ def answer_file(name) = "#{@temp_directory.chomp("/")}/principles-#{name}-answer.json"
67
+
58
68
  # The same command, its values given as one list, as a refusal's repair command holds them.
59
69
  #: (String, Array[String], ?options: Array[String], ?usage: String?) -> String
60
70
  def listed_in_project(command, values, options: [], usage: nil)