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
@@ -54,15 +54,17 @@ module Principles
54
54
  private
55
55
 
56
56
  # What the completed audit prints: its resolved and open findings, as the record it writes holds them, so they
57
- # agree with list-open-findings (#714); what it changed; and each prior finding's decision (D35).
57
+ # agree with list-open-findings (#714); what it changed; each prior finding's decision (D35); and, while
58
+ # principles is not set up, the offer to set it up (D95).
58
59
  #: (Models::AuditStart, Models::Audit, Array[Models::Disposition], Models::DecidedPriorFindings,
59
60
  #| Models::AuditRecord) -> untyped
60
61
  def completion_result(start, audit, dispositions, decided, written)
61
62
  decisions = Views::PriorFindingDecisionsResult.new(kept_ids: decided.kept_ids, closed: decided.closed,
62
63
  changed: decided.changed)
63
- audit_result.completion(principle_id: audit.id, resolved: written.resolved_ids(decided),
64
- open: written.open_ids, changes: changes(start, audit, dispositions, written),
65
- decisions: decisions)
64
+ completed = audit_result.completion(principle_id: audit.id, resolved: written.resolved_ids(decided),
65
+ open: written.open_ids,
66
+ changes: changes(start, audit, dispositions, written), decisions: decisions)
67
+ @principles.set_up? ? completed : audit_result.offering_set_up(completed)
66
68
  end
67
69
 
68
70
  # What the audit changed in the project: the files to commit, in git the commits since the base, the
@@ -8,6 +8,7 @@ require_relative "../models/audit"
8
8
  require_relative "../models/carried_assessments"
9
9
  require_relative "../models/member"
10
10
  require_relative "../models/member_grounds"
11
+ require_relative "../models/member_repair_moves"
11
12
  require_relative "../models/principle_history"
12
13
  require_relative "../models/members_sharing_lines"
13
14
  require_relative "../models/project"
@@ -96,8 +97,8 @@ module Principles
96
97
  def repaired(entry, repairs)
97
98
  principle = entry["principle"] or return entry
98
99
  id = entry["id"] or return entry
99
- fields = @principles.find(principle).member(id).merge(entry.slice("code")).merge("id" => id)
100
- entry.merge("repair_with" => repairs.commands(principle, fields))
100
+ moves = Models::MemberRepairMoves.new(@principles.find(principle).member(id), code: entry["code"]).to_a
101
+ entry.merge("repair_with" => repairs.commands(principle, id, moves))
101
102
  rescue Error
102
103
  entry
103
104
  end
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "command"
4
+ require_relative "answer_phase"
5
5
  require_relative "../models/audit"
6
6
  require_relative "../models/correction_answer"
7
7
  require_relative "../models/declared_map_changes"
@@ -16,31 +16,41 @@ module Principles
16
16
  # A full audit's correction, which submit-answer and show-answer-check hand over: this tool checks each
17
17
  # disposition, and any members moved or whose role or check a fix changed, against the map and hashes the
18
18
  # audit began from, and completes the audit (D28, D40).
19
- class Correction < Command
19
+ class Correction < AnswerPhase
20
20
  # The result of answering a correction request, and the record change it makes, not yet written. A refused
21
21
  # answer to a request printed before the record changed is refused as stale, so the agent starts again rather
22
22
  # than repairing it (#671).
23
- #: (Models::RequestId, untyped, Models::Audit) -> [untyped, Array[Models::AuditRecord]]
24
- def answered(request_id, response, audit)
23
+ # @override
24
+ #: (Models::SubmittedAnswer) -> [untyped, Array[Models::AuditRecord]]
25
+ def answered(submitted)
26
+ request_id = submitted.request_id
27
+ response = submitted.response
28
+ audit = audit_now(request_id.principle_id)
25
29
  Models::CorrectionBasis.new(response.fetch("basis")).printed_after
26
30
  .refusing_stale_first(audit.id, @audit_records.find(audit.id)) do
27
31
  judged_correction(request_id, response, audit)
28
32
  end
29
33
  end
30
34
 
31
- # What each map entry a fix claims changed, from the map the audit the block gives started from and its map
32
- # now; the audit is built and the base map read only when a fix claims one (#462).
33
- #: (untyped) { () -> Models::Audit } -> Array[Hash[String, untyped]]
34
- def map_entry_changes(response, &)
35
+ # What each map entry a fix in the answer claims changed, from the map its audit started from and its map now;
36
+ # the audit is built and the base map read only when a fix claims one (#462).
37
+ # @override
38
+ #: (Models::SubmittedAnswer) -> Array[Hash[String, untyped]]
39
+ def map_entry_changes(submitted)
40
+ response = submitted.response
35
41
  changes = Models::DeclaredMapChanges.declared_in(response)
36
42
  changes.entry_changes do
37
- audit = yield
43
+ audit = audit_now(submitted.request_id.principle_id)
38
44
  [started_from(Models::CorrectionBasis.new(response.fetch("basis")), audit, changes), audit.map]
39
45
  end
40
46
  end
41
47
 
42
48
  private
43
49
 
50
+ # The placeholders a correction's template printed, its dispositions' (#1084).
51
+ #: (Models::RequestId) -> Hash[String, untyped]?
52
+ def printed_placeholders(_request_id) = Models::Disposition::TEMPLATE_PLACEHOLDERS
53
+
44
54
  # The result of judging a correction answer: its basis, moves and dispositions checked, and the audit completed.
45
55
  #: (Models::RequestId, untyped, Models::Audit) -> [untyped, Array[Models::AuditRecord]]
46
56
  def judged_correction(request_id, response, audit)
@@ -4,6 +4,7 @@
4
4
  require_relative "command"
5
5
  require_relative "../models/audit"
6
6
  require_relative "../models/evidence_lines_since"
7
+ require_relative "../models/instruction_named"
7
8
  require_relative "../models/loading_decision"
8
9
  require_relative "../models/meta_principle"
9
10
  require_relative "../models/other_principles"
@@ -53,6 +54,15 @@ module Principles
53
54
  audit_result.answer_to_fill(asked)
54
55
  end
55
56
 
57
+ # The instruction field this request prints, read on its own and whole, with the paragraphs for cases the
58
+ # request does not hold (D81 step 2); refused when it prints none by that name.
59
+ #: (String) -> Hash[String, untyped]
60
+ def instruction(field)
61
+ request = asked
62
+ named = Models::InstructionNamed.new(field, principle_id: @id, printed: request.instruction_fields).field
63
+ { "request_id" => request.request_id, named => request.whole_instruction(named), "wrote" => [] }
64
+ end
65
+
56
66
  private
57
67
 
58
68
  # The request and what it asks, listing the findings the last completed audit left to decide, under an id that
@@ -2,10 +2,10 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
- require_relative "member_problems_report"
6
5
  require_relative "../models/member_state"
7
6
  require_relative "../models/meta_principle"
8
7
  require_relative "../views/candidate_files_result"
8
+ require_relative "../views/json_with_entries_on_lines"
9
9
  require_relative "../views/principle_read_result"
10
10
 
11
11
  module Principles
@@ -13,16 +13,14 @@ module Principles
13
13
  # controllers/CLAUDE.md owns the boundary.
14
14
  module Controllers
15
15
  # The reads that show what a project holds: its candidate instruction files, its principles, and each
16
- # member and how fresh it is against the last audit, handing list-member-problems to MemberProblemsReport. None
17
- # changes anything on disk.
16
+ # member and how fresh it is against the last audit. None changes anything on disk.
18
17
  class Inventory < Command
19
18
  #: (String, String?, Hash[String, untyped]) -> untyped
20
- def call(command, id, options)
19
+ def call(command, id, _options)
21
20
  naming_the_executable do
22
21
  case command
23
- when "list-candidate-files" then list_candidate_files.merge("wrote" => [])
22
+ when "list-candidate-files" then list_candidate_files
24
23
  when "list-principles" then listing.merge("wrote" => [])
25
- when "list-member-problems" then handed(MemberProblemsReport).printed(id, options)
26
24
  when "show-principle" then members(required_id(id)).merge("wrote" => [])
27
25
  else unknown(command)
28
26
  end
@@ -38,11 +36,18 @@ module Principles
38
36
 
39
37
  #: () -> untyped
40
38
  def list_candidate_files
41
- found = @project.candidate_files
39
+ found = @project.candidate_files.within_budget { |inventory| candidate_files_result(inventory).text.bytesize }
40
+ candidate_files_result(found)
41
+ end
42
+
43
+ # list-candidate-files' result for one inventory, as it prints.
44
+ #: (Models::CandidateInventory) -> Views::JsonWithEntriesOnLines
45
+ def candidate_files_result(found)
42
46
  listed = Views::CandidateFilesResult::Found.new(inventory: found.to_h, untracked: found.untracked,
43
47
  owner_asks: found.owner_asks)
44
- Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
45
- map_file: @principles.file("ID"), set_up: set_up?)
48
+ question = Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
49
+ map_file: @principles.file("ID"))
50
+ Views::JsonWithEntriesOnLines.new(question.merge("wrote" => []), under: "inventory", key: "files")
46
51
  end
47
52
 
48
53
  #: (String) -> untyped
@@ -52,7 +57,7 @@ module Principles
52
57
  hooks = @project.hook_commands
53
58
  members = shown_members(principle, audit, hooks)
54
59
  shown = read_result.shown(printed_principle(principle, members: members),
55
- broken: broken_ids(members), hook_settings_not_read: hooks.not_read,
60
+ repairs: repairs(principle, members), hook_settings_not_read: hooks.not_read,
56
61
  loaded_files: @project.loaded_files(principle.members, hooks).to_h)
57
62
  return shown unless audit
58
63
 
@@ -77,11 +82,15 @@ module Principles
77
82
  "loads" => loads.to_h)
78
83
  end
79
84
 
80
- # The id of each shown member whose reference is broken, so an audit would refuse it, in the map's order.
81
- #: (Array[Hash[String, untyped]]) -> Array[String]
82
- def broken_ids(members)
85
+ # The moves that may repair each shown member whose reference is broken, so an audit would refuse it, by id in the
86
+ # map's order.
87
+ #: (Models::Principle, Array[Hash[String, untyped]]) -> Hash[String, Array[Hash[String, untyped]]]
88
+ def repairs(principle, members)
83
89
  members.select { |member| Models::MemberState.new(member.fetch("id"), member.fetch("freshness")).broken? }
84
- .map { |member| member.fetch("id") }
90
+ .to_h do |member|
91
+ id = member.fetch("id")
92
+ [id, Models::MemberRepairMoves.new(principle.member(id), code: member.dig("error", "code")).to_a]
93
+ end
85
94
  end
86
95
 
87
96
  # The members sharing a line with this one, in its map and in others, as add-member names them, so a member
@@ -112,13 +121,9 @@ module Principles
112
121
  def listing
113
122
  ids = @principles.ids
114
123
  waiting = ids.filter_map { waiting_on_an_upgrade(it) }
115
- read_result.listing(rows(ids), set_up: set_up?, waiting: waiting, one_to_audit: waiting.size < ids.size)
124
+ read_result.listing(rows(ids), waiting: waiting, one_to_audit: waiting.size < ids.size)
116
125
  end
117
126
 
118
- # Whether principles is set up, as MappedPrinciples decides it (D68, D75).
119
- #: () -> bool
120
- def set_up? = @principles.set_up?
121
-
122
127
  # One map's row; a map this tool cannot read is listed with its refusal, so the others still show (D29), and one
123
128
  # whose record a later copy wrote says its audits wait on an upgrade, as show-audit does (#1067).
124
129
  #: (String) -> Hash[String, untyped]
@@ -135,7 +140,7 @@ module Principles
135
140
  # record a later copy wrote holds, read-only, when this copy cannot read the rest of it (#1067).
136
141
  #: (Models::Principle) -> Hash[String, Integer]
137
142
  def members_by_freshness(map)
138
- _, hashes = @audit_records.for_comparison(map.id)
143
+ hashes = @audit_records.hashes_to_compare(map.id)
139
144
  map.members_shown.map { |member| fresh(member, hashes).fetch("freshness") }.tally.sort.to_h
140
145
  end
141
146
  end
@@ -13,9 +13,18 @@ module Principles
13
13
  # Each runs one command: reads models, applies their rules and prints through a view.
14
14
  # controllers/CLAUDE.md owns the boundary.
15
15
  module Controllers
16
- # list-member-problems, which Inventory hands over: each member of one map or every map checked against its
17
- # baseline, printed as JSON, as --short's lines, or for the after-commit hook through MembersACommitChanged.
16
+ # list-member-problems: each member of one map or every map checked against its baseline, printed as JSON, as
17
+ # --short's lines, or for the after-commit hook through MembersACommitChanged.
18
18
  class MemberProblemsReport < Command
19
+ #: (String, String?, Hash[String, untyped]) -> untyped
20
+ def call(command, id, options)
21
+ naming_the_executable do
22
+ command == "list-member-problems" ? printed(id, options) : unknown(command)
23
+ end
24
+ end
25
+
26
+ private
27
+
19
28
  # list-member-problems' JSON result, or with --short its lines for a trigger (#291), or with --hook-event the
20
29
  # after-commit hook's JSON, which MembersACommitChanged prints (D73).
21
30
  #: (String?, Hash[String, untyped]) -> untyped
@@ -33,8 +42,6 @@ module Principles
33
42
  unassessed_change: problems.unassessed_change?)
34
43
  end
35
44
 
36
- private
37
-
38
45
  # list-member-problems' JSON result for map id, or every map, without the files it wrote.
39
46
  #: (String?) -> Hash[String, untyped]
40
47
  def checked_report(id) = checked(id).last
@@ -13,7 +13,8 @@ module Principles
13
13
  # exits 0 whatever it finds, since the host shows the user an error for any other status, and reports a refusal
14
14
  # only when those commits could have caused it, so a broken setup does not repeat at every commit (review R8).
15
15
  class MembersACommitChanged < Command
16
- # report gives list-member-problems' result for every map, as Inventory checks it, or raises its refusal.
16
+ # report gives list-member-problems' result for every map, as MemberProblemsReport checks it, or raises its
17
+ # refusal.
17
18
  #: (Models::Project, tool: RunningTool, report: ^() -> Hash[String, untyped]) -> void
18
19
  def initialize(project, tool:, report:)
19
20
  super(project, tool: tool)
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative "command"
5
+ require_relative "../models/carried_member"
5
6
  require_relative "../models/check_since_last_audit"
6
7
  require_relative "../models/open_findings_elsewhere"
7
8
  require_relative "../views/acknowledged_since_last_audit"
@@ -65,7 +66,7 @@ module Principles
65
66
  #| -> Hash[String, untyped]
66
67
  def member_listed(fields, carried, elsewhere, current)
67
68
  member = Models::Member.new(fields)
68
- judged = carried(member, carried)
69
+ judged = carried(member, carried, elsewhere)
69
70
  located(member, current).merge(checked(member), acknowledged(fields), judged,
70
71
  changed_since(fields, judged), shared_lines(member, elsewhere))
71
72
  end
@@ -99,16 +100,25 @@ module Principles
99
100
 
100
101
  # The member's last assessment carried forward, with whether any evidence it cited changed since and, in git,
101
102
  # whether its file changed since the last full audit's base commit, outside the member, whose own text did not;
102
- # or why it is judged again. These are facts: the agent may re-judge any carried member (D49).
103
- #: (Models::Member, Models::CarriedAssessments) -> Hash[String, untyped]
104
- def carried(member, carried)
103
+ # or why it is judged again. These are facts: the agent may re-judge any carried member (D49). flagged says
104
+ # whether any fires, or another principle leaves a finding open on its lines, so the request prints the member
105
+ # whole rather than compactly (D93).
106
+ #: (Models::Member, Models::CarriedAssessments, Models::OpenFindingsElsewhere) -> Hash[String, untyped]
107
+ def carried(member, carried, elsewhere)
105
108
  shown = carried.shown(member.id) { |locator, sha| evidence_changed?(locator, sha) }
106
- kept = shown["carried_forward"]
107
- base = @completed&.base_commit
108
- return shown unless kept && base
109
+ kept = shown["carried_forward"] or return shown
110
+
111
+ Models::CarriedMember.new(kept, file_changed_outside_member: file_changed_outside(member),
112
+ open_elsewhere: elsewhere.open_beside?(member.id),
113
+ open_here: @record&.open_ids_on(member.key) || []).shown
114
+ end
115
+
116
+ # Whether member's file changed since the last full audit's base commit; nil with no such commit, as outside git.
117
+ #: (Models::Member) -> bool?
118
+ def file_changed_outside(member)
119
+ base = @completed&.base_commit or return
109
120
 
110
- { "carried_forward" => kept.merge("file_changed_outside_member" =>
111
- @history.commits_since(base, member.path).any?) }
121
+ @history.commits_since(base, member.path).any?
112
122
  end
113
123
 
114
124
  # Whether the evidence at locator no longer hashes to sha, or can no longer be found.
@@ -157,10 +167,8 @@ module Principles
157
167
 
158
168
  #: (Models::Member) -> Hash[String, untyped]
159
169
  def checked(member)
160
- check = member.check or return {}
161
170
  hidden = member.check_hidden_characters
162
- { "check" => check, "check_since_last_audit" => @checks.of(member, check) }
163
- .merge(hidden.empty? ? {} : { "check_hidden_characters" => hidden })
171
+ @checks.entry(member).merge(hidden.empty? ? {} : { "check_hidden_characters" => hidden })
164
172
  end
165
173
  end
166
174
  end
@@ -2,9 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "time"
5
- require_relative "command"
5
+ require_relative "answer_phase"
6
6
  require_relative "../models/finding_write_ups"
7
- require_relative "../models/last_completed_revision"
8
7
  require_relative "../models/repoint"
9
8
  require_relative "../views/repoint_result"
10
9
 
@@ -14,33 +13,39 @@ module Principles
14
13
  module Controllers
15
14
  # A repoint of a principle's open findings' write-ups (D59): start-audit ID --write-ups lists each open finding
16
15
  # with where its write-up is now, and submit-answer points the recorded_at the agent gives in the audit record.
17
- class Repoint < Command
16
+ class Repoint < AnswerPhase
18
17
  # The request for principle id's open findings.
19
18
  #: (String) -> Hash[String, untyped]
20
19
  def start(id)
21
20
  naming_the_executable do
22
21
  record = @audit_records.find(id)
23
- repoint = Models::Repoint.new(principle_id: id, record: record, history: @history)
22
+ repoint = repoint_of(id, record)
24
23
  findings = Models::FindingWriteUps.of(@project, [record].compact).listed
25
24
  view.request(request_id: repoint.request_id.to_s, principle_id: id, revision: repoint.revision,
26
25
  findings: findings).merge("wrote" => [])
27
26
  end
28
27
  end
29
28
 
30
- # The result of answering request_id with response, and the record it changes, not yet written. It is
31
- # refused once the last completed record changed after the request was printed, unless it writes nothing.
32
- #: (Models::RequestId, untyped) -> [Hash[String, untyped], Array[Models::AuditRecord]]
33
- def answered(request_id, response)
34
- id = request_id.principle_id
35
- record = @audit_records.find(id)
36
- repoint = Models::Repoint.new(principle_id: id, record: record, history: @history)
37
- repointed = repoint.accepted(response, at: Time.now.utc.iso8601) { |locator| snapshot(locator) }
38
- changes = writable_changes(record, repointed, response.dig("basis", "revision"))
29
+ # The result of answering, and the record it changes, not yet written, which the repoint refuses once the last
30
+ # completed record changed after the request was printed, unless it writes nothing.
31
+ # @override
32
+ #: (Models::SubmittedAnswer) -> [Hash[String, untyped], Array[Models::AuditRecord]]
33
+ def answered(submitted)
34
+ id = submitted.request_id.principle_id
35
+ response = submitted.response
36
+ repoint = repoint_of(id, @audit_records.find(id))
37
+ repointed, changes = repoint.writable(response, records: @audit_records, at: Time.now.utc.iso8601) do |locator|
38
+ snapshot(locator)
39
+ end
39
40
  [view.repointed(principle_id: id, file: @audit_records.file(id), outcome: outcome(repoint, repointed)), changes]
40
41
  end
41
42
 
42
43
  private
43
44
 
45
+ # The repoint of principle id's open findings, as its record holds them.
46
+ #: (String, Models::AuditRecord?) -> Models::Repoint
47
+ def repoint_of(id, record) = Models::Repoint.new(principle_id: id, record: record, history: @history)
48
+
44
49
  # What the repoint did, and each other principle's open finding whose write-up cannot be found (T16).
45
50
  #: (Models::Repoint, Models::AuditRecord) -> Views::RepointResult::Outcome
46
51
  def outcome(repoint, repointed)
@@ -50,15 +55,6 @@ module Principles
50
55
  not_found_elsewhere: Models::FindingWriteUps.of(@project, others).not_found)
51
56
  end
52
57
 
53
- # The records repointed changes from record. Refused once record changed after the request, whose revision the
54
- # answer quotes back, was printed, unless there are none.
55
- #: (Models::AuditRecord?, Models::AuditRecord, String?) -> Array[Models::AuditRecord]
56
- def writable_changes(record, repointed, revision)
57
- changes = @audit_records.changes(repointed)
58
- Models::LastCompletedRevision.new(revision).confirm_writable(repointed.principle_id, record, changes)
59
- changes
60
- end
61
-
62
58
  #: () -> Views::RepointResult
63
59
  def view
64
60
  Views::RepointResult.new(invocation)
@@ -12,18 +12,23 @@ module Principles
12
12
  # Far above any instruction file, map, audit record or answer, and far below what exhausts memory.
13
13
  LIMIT = 4 * 1024 * 1024 #: Integer
14
14
 
15
- #: (String, ?shown_as: String) -> void
16
- def initialize(path, shown_as: path)
15
+ # shown_as is the path a refusal gives; named is what its message calls the file, such as "The answer" for a
16
+ # file the agent named and holds the path of (#1118).
17
+ #: (String, ?shown_as: String, ?named: String) -> void
18
+ def initialize(path, shown_as: path, named: shown_as)
17
19
  @path = path
18
20
  @shown_as = shown_as
21
+ @named = named
19
22
  freeze
20
23
  end
21
24
 
22
25
  # The file's text, read once it is known to be a regular file within LIMIT.
23
26
  #: (?encoding: String) -> String
24
27
  def read(encoding: "UTF-8")
28
+ raise Error.new("unreadable_file", "#{@named} does not exist", "Name a file that exists.", @shown_as) unless
29
+ File.exist?(@path)
25
30
  unless File.file?(@path)
26
- raise Error.new("not_a_file", "#{@shown_as} is not a regular file", "Name a regular file.", @shown_as)
31
+ raise Error.new("not_a_file", "#{@named} is not a regular file", "Name a regular file.", @shown_as)
27
32
  end
28
33
 
29
34
  refuse_larger(File.size(@path))
@@ -47,7 +52,7 @@ module Principles
47
52
  def refuse_larger(bytes)
48
53
  return if bytes <= LIMIT
49
54
 
50
- raise Error.new("file_too_large", "#{@shown_as} holds #{bytes} bytes, more than the #{LIMIT} bytes " \
55
+ raise Error.new("file_too_large", "#{@named} holds #{bytes} bytes, more than the #{LIMIT} bytes " \
51
56
  "read at most",
52
57
  "Name a smaller file, or map a smaller part of it.", @shown_as)
53
58
  end
@@ -25,7 +25,7 @@
25
25
  { "id": "list-instruction-files", "actor": "cli",
26
26
  "does": "Lists the instruction files agent hosts load by convention, naming git-ignored ones unread rather than listing them, each folder git ignores counted once, leaving out folders that hold their own git repository, and names any under a fixtures, examples or samples folder and, in git, any git does not track." },
27
27
  { "id": "choose-one-principle", "actor": "agent",
28
- "does": "Choose one principle several listed files reinforce. Decide whether each file named in possibly_test_data is guidance or a sample.",
28
+ "does": "Show the user a table of the principles several listed files reinforce, asking nothing before it, then choose one to map with the user. Decide whether each file named in possibly_test_data is guidance or a sample.",
29
29
  "prompt": "find-a-principle-to-map/choose-one-principle",
30
30
  "cannot_check": "whether a file is guidance or test data; ask the project's owner when you cannot tell.",
31
31
  "answer_with": "create-principle" }
@@ -81,7 +81,7 @@
81
81
  "help": "learn-what-a-command-does/list-open-findings",
82
82
  "steps": [
83
83
  { "id": "read-open-findings", "actor": "cli",
84
- "does": "Reads the last audit record of principle ID, or of every principle, and lists each deferred or accepted finding with its action, its members, its recorded_at pointer and when the audit was made. Says that an earlier audit's open findings are only in git. With --short, prints one line saying how many are open, how long the oldest has waited and what it waits on, and nothing when none is open; --session-start clear or compact words it for a context just cleared or compacted.",
84
+ "does": "Reads the last audit record of principle ID, or of every principle, and lists each deferred or accepted finding with its action, its members, its recorded_at pointer and when the audit was made. Says that an earlier audit's open findings are only in git. With --short, prints one line saying how many are open, how long the oldest has waited and what it waits on, and nothing when none is open; --session-start clear or compact words it for a context just cleared or compacted, and resume shortens it to the facts, since a resumed conversation holds the whole line already.",
85
85
  "refuses_like": ["read-map", "read-audit"] },
86
86
  { "id": "follow-up-each-finding", "actor": "agent",
87
87
  "does": "Read each finding where its recorded_at points, and decide each one at its principle's next full audit.",
@@ -90,7 +90,7 @@
90
90
  ]
91
91
  },
92
92
  {
93
- "name": "show-answer-check", "usage": "show-answer-check REQUEST --file FILE|-", "group": "read", "options": ["file"],
93
+ "name": "show-answer-check", "usage": "show-answer-check REQUEST_ID --file FILE|-", "group": "read", "options": ["file"], "requires": ["file"],
94
94
  "summary": "Check an answer without submitting it.",
95
95
  "help": "learn-what-a-command-does/show-answer-check",
96
96
  "steps": [
@@ -218,13 +218,13 @@
218
218
  ]
219
219
  },
220
220
  {
221
- "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups | --as template]", "group": "write-audit-record", "options": ["member", "write-ups", "as"],
221
+ "name": "start-audit", "usage": "start-audit ID [--member MEMBER | --write-ups] [--as template | --instruction FIELD]", "group": "write-audit-record", "options": ["member", "write-ups", "as", "instruction"],
222
222
  "summary": "Ask for an assessment of every member and the set.",
223
223
  "help": "learn-what-a-command-does/start-audit",
224
224
  "steps": [
225
225
  { "id": "snapshot-members", "actor": "cli",
226
226
  "does": "Refuses an empty map or, in git, an uncommitted map or member file; bases the audit on HEAD. Fill --as template's output with your own judgement, under $TMPDIR; its left_as_printed_rule says how a field left as printed is read.",
227
- "refuses": ["map_has_no_members", "uncommitted_files"], "refuses_like": ["read-map", "locate-text", "rewrite-audit"],
227
+ "refuses": ["map_has_no_members", "uncommitted_files", "unknown_instruction"], "refuses_like": ["read-map", "locate-text", "rewrite-audit"],
228
228
  "next": [{ "to": "assess-every-member", "when": "you passed neither --member nor --write-ups" },
229
229
  { "to": "start-acknowledgement", "when": "you passed --member" },
230
230
  { "to": "start-repointing", "when": "you passed --write-ups" }] },
@@ -235,7 +235,7 @@
235
235
  "cannot_check": "whether your assessment is true, a member reached your context, or your findings are the right ones.",
236
236
  "answer_with": "submit-answer" },
237
237
  { "id": "start-acknowledgement", "actor": "cli",
238
- "does": "With --member, starts a one-member audit instead: in git, for a member the last completed audit assessed whose text changed since, names its baseline commit and the change to read. Writes nothing.",
238
+ "does": "With --member, starts a one-member audit, or with --as template its answer alone: in git, for a member the last completed audit assessed that changed since, names its baseline commit and the change to read. Writes nothing.",
239
239
  "refuses": ["cannot_acknowledge"] },
240
240
  { "id": "judge-the-change", "actor": "agent",
241
241
  "does": "Say whether the change keeps the member's principle, with a one-line reason and a quote from then and now.",
@@ -249,18 +249,18 @@
249
249
  ]
250
250
  },
251
251
  {
252
- "name": "submit-answer", "usage": "submit-answer REQUEST --file FILE|-", "group": "write-audit-record", "options": ["file"],
252
+ "name": "submit-answer", "usage": "submit-answer REQUEST_ID --file FILE|-", "group": "write-audit-record", "options": ["file"], "requires": ["file"],
253
253
  "summary": "Give the answer a request asked for.",
254
254
  "help": "learn-what-a-command-does/submit-answer",
255
255
  "steps": [
256
256
  { "id": "match-request", "actor": "cli",
257
- "does": "Reads FILE, or stdin for -, and checks that its request_id is REQUEST, an id this tool prints.",
257
+ "does": "Reads FILE, or stdin for -, and checks that its request_id is REQUEST_ID, an id this tool prints.",
258
258
  "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request"], "refuses_like": ["rewrite-audit"],
259
259
  "next": [{ "to": "acknowledge-the-change", "when": "the request was a one-member audit" },
260
260
  { "to": "record-the-repoints", "when": "the request was a repoint of write-ups" },
261
261
  { "to": "recheck-members", "when": "the request was an assessment or a correction" }] },
262
262
  { "id": "acknowledge-the-change", "actor": "cli",
263
- "does": "For a one-member audit, checks that the answer says the meaning is kept, with a one-line reason and a quote of the member then and now, then moves its hash in the audit record and keeps the acknowledgement beside it.",
263
+ "does": "For a one-member audit, checks the answer's kept meaning, one-line reason, quotes then and now and any check result, then moves the member's hash and check result in the audit record beside the acknowledgement.",
264
264
  "refuses": ["stale_request", "cannot_acknowledge", "quote_not_found"] },
265
265
  { "id": "commit-the-acknowledgement", "actor": "agent",
266
266
  "does": "Commit the audit record, then check that list-member-problems --short no longer reports the member.",
@@ -82,17 +82,20 @@ module Principles
82
82
  #: () -> Hash[String, untyped]
83
83
  def inventory = CandidateFilesFound.new(self).to_h
84
84
 
85
- #: (String) -> untyped
86
- def read_json(path)
87
- parse_json(BoundedFile.new(path).read, path)
85
+ # JSON from the file at path, which a refusal's message calls named (#1118).
86
+ #: (String, ?named: String) -> untyped
87
+ def read_json(path, named: path)
88
+ parse_json(BoundedFile.new(path, named:).read, path, named:)
88
89
  rescue SystemCallError => e
89
- raise Error.new("unreadable_file", e.message, "Supply a readable JSON file.", path)
90
+ # The system's reason alone, such as "Permission denied", without the path its message ends with.
91
+ reason = e.class.new(nil).message
92
+ raise Error.new("unreadable_file", "#{named} cannot be read: #{reason}", "Supply a readable JSON file.", path)
90
93
  end
91
94
 
92
- # JSON from text read elsewhere, such as stdin, named by source in a refusal.
93
- #: (String, String) -> untyped
94
- def parse_json(text, source)
95
- BoundedFile.new(source).refuse_larger(text.bytesize)
95
+ # JSON from text read elsewhere, such as stdin, given by source in a refusal, whose message calls it named.
96
+ #: (String, String, ?named: String) -> untyped
97
+ def parse_json(text, source, named: source)
98
+ BoundedFile.new(source, named:).refuse_larger(text.bytesize)
96
99
  JsonText.new(text).parsed
97
100
  rescue JSON::ParserError => e
98
101
  raise Error.new("unparseable_json", e.message, "Repair this JSON and retry; no response was accepted.",
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "json"
5
5
  require_relative "../error"
6
+ require_relative "../prose_list"
6
7
  require_relative "expected_type"
7
8
  require_relative "known_fields"
8
9
 
@@ -56,13 +57,14 @@ module Principles
56
57
  KnownFields.new(@schema).of(data)
57
58
  end
58
59
 
59
- # data when it fits the schema; otherwise a refusal with code, naming source and each failing field.
60
- #: (untyped, code: String, source: String, repair: String) -> untyped
61
- def checked(data, code:, source:, repair:)
60
+ # data when it fits the schema; otherwise a refusal with code, giving source and each failing field, whose
61
+ # message calls data named.
62
+ #: (untyped, code: String, source: String, repair: String, ?named: String) -> untyped
63
+ def checked(data, code:, source:, repair:, named: source)
62
64
  found = problems(data)
63
65
  return data if found.empty?
64
66
 
65
- raise Error.new(code, "#{source} is not in the shape this tool reads", repair, source, fields: found)
67
+ raise Error.new(code, "#{named} is not in the shape this tool reads", repair, source, fields: found)
66
68
  end
67
69
 
68
70
  private
@@ -131,11 +133,19 @@ module Principles
131
133
  if property.is_a?(Hash)
132
134
  check(property, value, child(pointer, key), found)
133
135
  elsif property == false
134
- advice = schema.fetch(UNREAD_FIELD_ADVICE, {})[key]
135
- found << problem(child(pointer, key), ["is not a field this tool reads here", *advice].join("; "))
136
+ found << problem(child(pointer, key), unread(schema, key))
136
137
  end
137
138
  end
138
139
 
140
+ # Why key is refused in an object schema checks: not a field read there, the fields that are, so the agent need
141
+ # not guess them (#1115), and what the schema says of key, if anything (#769).
142
+ #: (Hash[String, untyped], String) -> String
143
+ def unread(schema, key)
144
+ read = schema.fetch("properties", {}).keys
145
+ ["is not a field this tool reads here", *("it reads #{ProseList.new(read)}" unless read.empty?),
146
+ *schema.fetch(UNREAD_FIELD_ADVICE, {})[key]].join("; ")
147
+ end
148
+
139
149
  #: (Hash[String, untyped], Array[untyped], String, Array[Hash[String, String]]) -> void
140
150
  def check_items(schema, value, pointer, found)
141
151
  items = schema["items"] or return