principles 0.0.11 → 0.1.1

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -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/committed_texts.rb +58 -0
  16. data/lib/principles/data/first_parent_log.rb +50 -10
  17. data/lib/principles/data/json_text.rb +5 -1
  18. data/lib/principles/data/parser_message.rb +61 -0
  19. data/lib/principles/data/project_files.rb +4 -2
  20. data/lib/principles/data/repository.rb +29 -37
  21. data/lib/principles/data/running_version.rb +1 -1
  22. data/lib/principles/data/schemas/audit-record.schema.json +15 -0
  23. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  24. data/lib/principles/data/schemas/{repointing-answer.schema.json → deciding-answer.schema.json} +12 -6
  25. data/lib/principles/data/working_tree_changes.rb +62 -0
  26. data/lib/principles/invocation_options.rb +1 -1
  27. data/lib/principles/launch.rb +5 -3
  28. data/lib/principles/models/after_commit_input.rb +1 -0
  29. data/lib/principles/models/assessment_basis.rb +1 -1
  30. data/lib/principles/models/audit.rb +23 -3
  31. data/lib/principles/models/audit_entry_protecting_map.rb +1 -0
  32. data/lib/principles/models/audit_record.rb +5 -14
  33. data/lib/principles/models/audit_records.rb +1 -1
  34. data/lib/principles/models/audited_member_lines.rb +1 -1
  35. data/lib/principles/models/candidate_files.rb +1 -1
  36. data/lib/principles/models/candidate_inventory.rb +19 -9
  37. data/lib/principles/models/candidate_outline.rb +1 -1
  38. data/lib/principles/models/changed_regions.rb +1 -1
  39. data/lib/principles/models/command_steps.rb +1 -2
  40. data/lib/principles/models/correction_basis.rb +1 -1
  41. data/lib/principles/models/declared_map_changes.rb +1 -2
  42. data/lib/principles/models/finding_decision.rb +84 -0
  43. data/lib/principles/models/finding_write_ups.rb +2 -1
  44. data/lib/principles/models/first_full_audit.rb +1 -0
  45. data/lib/principles/models/frontmatter_fields.rb +1 -1
  46. data/lib/principles/models/guidance_search_path.rb +1 -1
  47. data/lib/principles/models/guidance_search_paths.rb +5 -1
  48. data/lib/principles/models/head_moves.rb +1 -0
  49. data/lib/principles/models/ignored_candidates.rb +1 -1
  50. data/lib/principles/models/instruction_named.rb +1 -1
  51. data/lib/principles/models/json_path_query.rb +1 -1
  52. data/lib/principles/models/json_path_selectors.rb +1 -1
  53. data/lib/principles/models/json_path_string.rb +1 -1
  54. data/lib/principles/models/last_completed_revision.rb +1 -1
  55. data/lib/principles/models/line_diff.rb +1 -1
  56. data/lib/principles/models/line_span.rb +1 -1
  57. data/lib/principles/models/loading_scope.rb +1 -0
  58. data/lib/principles/models/located_text.rb +1 -1
  59. data/lib/principles/models/map_change.rb +66 -0
  60. data/lib/principles/models/mapped_principles.rb +4 -0
  61. data/lib/principles/models/markdown_file.rb +22 -1
  62. data/lib/principles/models/member.rb +1 -1
  63. data/lib/principles/models/member_elsewhere.rb +1 -1
  64. data/lib/principles/models/member_file.rb +6 -1
  65. data/lib/principles/models/member_hashes_as_written.rb +2 -2
  66. data/lib/principles/models/member_history.rb +1 -1
  67. data/lib/principles/models/member_lines.rb +1 -1
  68. data/lib/principles/models/member_loading_scopes.rb +1 -0
  69. data/lib/principles/models/member_mapping_run.rb +4 -4
  70. data/lib/principles/models/member_moves.rb +1 -2
  71. data/lib/principles/models/member_problems.rb +5 -1
  72. data/lib/principles/models/member_region.rb +1 -1
  73. data/lib/principles/models/members_elsewhere.rb +1 -1
  74. data/lib/principles/models/members_in_consecutive_sections.rb +1 -0
  75. data/lib/principles/models/members_sharing_lines.rb +1 -1
  76. data/lib/principles/models/misspelt_member_id.rb +1 -1
  77. data/lib/principles/models/open_finding.rb +4 -3
  78. data/lib/principles/models/open_findings_decision.rb +124 -0
  79. data/lib/principles/models/open_findings_elsewhere.rb +1 -1
  80. data/lib/principles/models/other_templates_placeholders.rb +1 -0
  81. data/lib/principles/models/outline_budget.rb +1 -1
  82. data/lib/principles/models/outline_group.rb +1 -1
  83. data/lib/principles/models/outline_section.rb +1 -1
  84. data/lib/principles/models/part_named.rb +1 -1
  85. data/lib/principles/models/plain_text_file.rb +1 -1
  86. data/lib/principles/models/principle_history.rb +3 -3
  87. data/lib/principles/models/principle_members.rb +1 -1
  88. data/lib/principles/models/problem_report.rb +26 -3
  89. data/lib/principles/models/project.rb +8 -3
  90. data/lib/principles/models/project_at_commit.rb +9 -19
  91. data/lib/principles/models/project_history.rb +8 -0
  92. data/lib/principles/models/prose_line.rb +36 -0
  93. data/lib/principles/models/record_format.rb +17 -4
  94. data/lib/principles/models/recorded_finding.rb +47 -7
  95. data/lib/principles/models/recorded_findings.rb +7 -7
  96. data/lib/principles/models/recorded_hashes.rb +1 -1
  97. data/lib/principles/models/recorded_members.rb +6 -8
  98. data/lib/principles/models/report_hooks.rb +1 -0
  99. data/lib/principles/models/request_id.rb +2 -2
  100. data/lib/principles/models/sent_answer.rb +1 -0
  101. data/lib/principles/models/session_start_input.rb +1 -0
  102. data/lib/principles/models/stale_request.rb +22 -8
  103. data/lib/principles/models/submitted_answer.rb +1 -1
  104. data/lib/principles/models/survey_search_paths.rb +13 -5
  105. data/lib/principles/models/text_within.rb +1 -1
  106. data/lib/principles/models/unchecked_members.rb +1 -0
  107. data/lib/principles/models/uncommitted_outside_the_map.rb +1 -1
  108. data/lib/principles/models/unknown_principle.rb +1 -0
  109. data/lib/principles/models/write_up_opening.rb +5 -31
  110. data/lib/principles/models/write_up_pointer.rb +2 -1
  111. data/lib/principles/start_audit_options.rb +25 -18
  112. data/lib/principles/version.rb +2 -2
  113. data/lib/principles/views/acknowledgement_result.rb +12 -9
  114. data/lib/principles/views/added_member.rb +10 -1
  115. data/lib/principles/views/answer_in_a_file.rb +16 -4
  116. data/lib/principles/views/assessment_answer_guide.rb +59 -0
  117. data/lib/principles/views/assessment_request.rb +2 -26
  118. data/lib/principles/views/audit_result.rb +15 -6
  119. data/lib/principles/views/candidate_files_result.rb +24 -13
  120. data/lib/principles/views/context_parts.rb +40 -9
  121. data/lib/principles/views/correction_request.rb +8 -5
  122. data/lib/principles/views/first_audit_brief.rb +2 -1
  123. data/lib/principles/views/guidance_search_paths_result.rb +13 -6
  124. data/lib/principles/views/invocation.rb +14 -4
  125. data/lib/principles/views/json_on_one_line.rb +18 -0
  126. data/lib/principles/views/open_findings_decision_result.rb +60 -0
  127. data/lib/principles/views/problem_facts.rb +46 -0
  128. data/lib/principles/views/problem_result.rb +42 -31
  129. data/lib/principles/views/prompts/answer-any-judgement-request/fill-the-answer-in-a-file.md +1 -1
  130. data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +2 -1
  131. data/lib/principles/views/prompts/decide-open-findings/give-only-what-changed-of-each.md +6 -0
  132. data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -1
  133. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +2 -2
  134. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +1 -1
  135. data/lib/principles/views/prompts/find-a-principle-to-map/ask-in-this-order-after-the-table.md +1 -0
  136. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner.md +1 -0
  137. data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -2
  138. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +3 -2
  139. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +2 -2
  140. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +2 -2
  141. data/lib/principles/views/prompts/find-a-principle-to-map/group-rules-into-principles.md +3 -0
  142. data/lib/principles/views/prompts/find-a-principle-to-map/where-a-survey-with-only-looks.md +4 -0
  143. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +2 -1
  144. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +1 -0
  145. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +12 -12
  146. data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -12
  147. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +2 -2
  148. data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +2 -2
  149. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +8 -8
  150. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -1
  151. metadata +20 -9
  152. data/lib/principles/controllers/repoint.rb +0 -67
  153. data/lib/principles/models/repoint.rb +0 -125
  154. data/lib/principles/models/write_up_repoint.rb +0 -38
  155. data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +0 -1
  156. data/lib/principles/views/prompts/repoint-write-ups/point-each-moved-write-up-at-its-new-place.md +0 -10
  157. data/lib/principles/views/repoint_result.rb +0 -80
@@ -10,6 +10,15 @@ module Principles
10
10
  # its full and short sha, subject line, author date and whether it is a root commit ("true" or "false"). The list
11
11
  # and each commit are frozen, and a list asked to be kept is read from git once, a refusal included.
12
12
  class FirstParentLog
13
+ # Each commit's full and short sha, subject line, author date and parents, as git log prints them.
14
+ FORMAT = "%H%x00%h%x00%s%x00%aI%x00%P" #: String
15
+
16
+ # What read_ahead's log starts each commit's full sha with: a byte no sha holds.
17
+ START = "\x01" #: String
18
+
19
+ # A token of read_ahead's log that starts a commit.
20
+ STARTS_A_COMMIT = /\A\x01\h{40}(?:\h{24})?\z/ #: Regexp
21
+
13
22
  #: (GitCommand) -> void
14
23
  def initialize(git)
15
24
  @git = git
@@ -25,24 +34,55 @@ module Principles
25
34
  @kept[[range, paths.dup.freeze]] ||= read(range, paths)
26
35
  end
27
36
 
37
+ # Reads the commits in range, one that always names the same commits, touching each of path_sets in one git log,
38
+ # and keeps each set's as touching keeps it: each log walks the whole history, whatever it lists. A merge counts
39
+ # by its changes from its first parent, as git log --first-parent counts it. When git cannot list them so, none
40
+ # is kept, and touching asks git for each set.
41
+ #: (String, Array[Array[String]]) -> void
42
+ def read_ahead(range, path_sets)
43
+ output, ok = @git.run(["log", "--first-parent", "--diff-merges=first-parent", "--no-renames", "--relative",
44
+ "--name-only", "-z", "--format=#{START}#{FORMAT}", "--end-of-options", range, "--",
45
+ *path_sets.flatten.uniq])
46
+ return unless ok
47
+
48
+ changed = changes(output)
49
+ path_sets.each do |paths|
50
+ @kept[[range, paths.dup.freeze]] ||=
51
+ changed.filter_map { |commit, names| commit if names.any? { |name| within?(name, paths) } }.freeze
52
+ end
53
+ end
54
+
28
55
  private
29
56
 
30
57
  #: (String, Array[String]) -> Array[Hash[String, String]]
31
58
  def read(range, paths)
32
- output, ok = @git.run(["log", "--first-parent", "--format=%H%x00%h%x00%s%x00%aI%x00%P", "--end-of-options",
33
- range, "--", *paths])
34
- (ok ? commits(output).each(&:freeze) : []).freeze
59
+ output, ok = @git.run(["log", "--first-parent", "--format=#{FORMAT}", "--end-of-options", range, "--", *paths])
60
+ (ok ? output.force_encoding("UTF-8").lines.map { |line| commit(line.chomp) } : []).freeze
35
61
  end
36
62
 
37
- # Each commit in output, the log read asks git for.
38
- #: (String) -> Array[Hash[String, String]]
39
- def commits(output)
40
- output.force_encoding("UTF-8").lines.map do |line|
41
- sha, short, subject, authored_at, parents = line.chomp.split("\0", 5)
42
- { "sha" => sha.to_s, "commit" => short.to_s, "subject" => subject.to_s, "authored_at" => authored_at.to_s,
43
- "root" => parents.to_s.empty?.to_s }
63
+ # Each commit in output, the log read_ahead asks git for, with the names it changed.
64
+ #: (String) -> Array[[Hash[String, String], Array[String]]]
65
+ def changes(output)
66
+ tokens = output.force_encoding("UTF-8").split("\0")
67
+ tokens.slice_before { |token| STARTS_A_COMMIT.match?(token) }.map do |fields|
68
+ names = fields.drop(5).map { |name| name.delete_prefix("\n") }.reject(&:empty?)
69
+ [commit(fields.first(5).join("\0").delete_prefix(START)), names]
44
70
  end
45
71
  end
72
+
73
+ # Whether name is one of paths, or lies in one of them, as git reads a literal pathspec.
74
+ #: (String, Array[String]) -> bool
75
+ def within?(name, paths)
76
+ paths.any? { |path| name == path || name.start_with?("#{path.delete_suffix("/")}/") }
77
+ end
78
+
79
+ # One commit as FORMAT prints it, frozen.
80
+ #: (String) -> Hash[String, String]
81
+ def commit(line)
82
+ sha, short, subject, authored_at, parents = line.split("\0", 5)
83
+ { "sha" => sha.to_s, "commit" => short.to_s, "subject" => subject.to_s, "authored_at" => authored_at.to_s,
84
+ "root" => parents.to_s.empty?.to_s }.freeze
85
+ end
46
86
  end
47
87
  end
48
88
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "json"
5
+ require_relative "parser_message"
5
6
 
6
7
  module Principles
7
8
  # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
@@ -36,10 +37,13 @@ module Principles
36
37
  freeze
37
38
  end
38
39
 
39
- # The parsed value, made only of plain hashes and arrays; raises JSON::ParserError on a duplicate key.
40
+ # The parsed value, made only of plain hashes and arrays; raises JSON::ParserError on a duplicate key, and on
41
+ # text it cannot parse with the parser's message, the rest of the input it quotes cut to an excerpt.
40
42
  #: () -> untyped
41
43
  def parsed
42
44
  plain(JSON.parse(@text, object_class: UniqueKeys))
45
+ rescue JSON::ParserError => e
46
+ raise JSON::ParserError, ParserMessage.new(@text, e.message).to_s
43
47
  end
44
48
 
45
49
  private
@@ -0,0 +1,61 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
6
+ module Data
7
+ # The json parser's message about text it could not parse, with the rest of the input it quotes from where it
8
+ # stopped cut to an excerpt, since a raw line break early in a long answer echoed the whole rest of the file.
9
+ # json 2.9.1, Ruby 3.4's own, quotes that rest with no line or column; later versions give both after it. A
10
+ # message quoting none of the input is kept as it is.
11
+ class ParserMessage
12
+ # The characters of the rest of the input the message keeps.
13
+ EXCERPT = 60 #: Integer
14
+
15
+ # How each json version's message ends just before the rest of the input it quotes: json 2.9.1's
16
+ # "unexpected token at '", and a later version's reason and colon. A message ending as the input does but
17
+ # after neither quotes none of it.
18
+ LEADS = ["at '", ": "].freeze #: Array[String]
19
+
20
+ # Where a later json says it stopped, after the rest of the input.
21
+ POSITION = / at line \d+ column \d+\z/ #: Regexp
22
+
23
+ #: (String, String) -> void
24
+ def initialize(text, message)
25
+ @text = text
26
+ @message = message
27
+ freeze
28
+ end
29
+
30
+ #: () -> String
31
+ def to_s
32
+ position = @message[POSITION].to_s
33
+ quoted = @message.delete_suffix(position)
34
+ quoted = quoted.delete_suffix("'") if quoted.end_with?("'") && !@text.end_with?("'")
35
+ rest = common_suffix(quoted)
36
+ lead = quoted.delete_suffix(rest)
37
+ return @message if rest.empty? || LEADS.none? { lead.end_with?(it) }
38
+
39
+ "#{lead.delete_suffix("'")}#{excerpt(rest)}#{position}"
40
+ end
41
+
42
+ private
43
+
44
+ # The longest end that quoted shares with the text: the rest of the input it quotes.
45
+ #: (String) -> String
46
+ def common_suffix(quoted)
47
+ length = 0
48
+ length += 1 while length < quoted.length && length < @text.length && quoted[-1 - length] == @text[-1 - length]
49
+ quoted[quoted.length - length, length].to_s
50
+ end
51
+
52
+ # rest's first characters, written so a line break or control character shows, and how many bytes follow.
53
+ #: (String) -> String
54
+ def excerpt(rest)
55
+ kept = rest[0, EXCERPT].to_s
56
+ left = rest.bytesize - kept.bytesize
57
+ left.positive? ? "#{kept.inspect} and #{left} more bytes" : kept.inspect
58
+ end
59
+ end
60
+ end
61
+ end
@@ -87,8 +87,10 @@ module Principles
87
87
  end
88
88
 
89
89
  # The instruction files hosts load by convention, as CandidateFilesFound lists them, and the files also names.
90
- #: (?also: Array[String], ?matching: Array[String]) -> Hash[String, untyped]
91
- def inventory(also: [], matching: []) = CandidateFilesFound.new(self, also:, matching:).to_h
90
+ #: (?also: Array[String], ?matching: Array[String], ?conventional: bool) -> Hash[String, untyped]
91
+ def inventory(also: [], matching: [], conventional: true)
92
+ CandidateFilesFound.new(self, also:, matching:, conventional:).to_h
93
+ end
92
94
 
93
95
  # Literal outline requests never walk the project or load saved search paths.
94
96
  #: (Array[String]) -> Hash[String, untyped]
@@ -4,6 +4,8 @@
4
4
  require_relative "git_command"
5
5
  require_relative "verified_head"
6
6
  require_relative "first_parent_log"
7
+ require_relative "working_tree_changes"
8
+ require_relative "committed_texts"
7
9
 
8
10
  module Principles
9
11
  # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
@@ -24,8 +26,9 @@ module Principles
24
26
  def initialize(root)
25
27
  @root = root
26
28
  @git = GitCommand.new(root) #: GitCommand
27
- @texts = {} #: Hash[[String, String], String?]
29
+ @texts = CommittedTexts.new(root, ->(name) { show(name) }) #: CommittedTexts
28
30
  @log = FirstParentLog.new(@git) #: FirstParentLog
31
+ @changes = WorkingTreeChanges.new(@git) #: WorkingTreeChanges
29
32
  end
30
33
 
31
34
  # A strict permission snapshot; legacy best-effort readers keep their existing behavior.
@@ -100,34 +103,15 @@ module Principles
100
103
  # Which of paths, relative to the project, are untracked or ignored, or differ from HEAD in the index
101
104
  # or the working tree. Before the first commit, every path does.
102
105
  #: (Array[String]) -> Array[String]
103
- def uncommitted(paths)
104
- return [] if paths.empty?
105
- return paths.uniq.sort unless head
106
+ def uncommitted(paths) = @changes.uncommitted(paths, committed: !head.nil?)
106
107
 
107
- changed, = git(["diff", "--name-only", "--relative", "-z", "HEAD", "--", *paths])
108
- untracked, = git(["ls-files", "--others", "-z", "--", *paths])
109
- (changed.split("\0") + untracked.split("\0")).uniq.sort
110
- end
111
-
112
- # Which of paths, relative to the project, git does not track and does not ignore. Before the first
113
- # commit, every path not staged is one.
108
+ # Which of paths, relative to the project, git does not track and does not ignore.
114
109
  #: (Array[String]) -> Array[String]
115
- def untracked_excluding_ignored(paths)
116
- return [] if paths.empty?
117
-
118
- output, = git(["ls-files", "--others", "--exclude-standard", "-z", "--", *paths])
119
- output.split("\0").sort
120
- end
110
+ def untracked_excluding_ignored(paths) = @changes.untracked_excluding_ignored(paths)
121
111
 
122
- # Which of paths, relative to the project, git does not track, ignored or not. Unlike
123
- # untracked_excluding_ignored, it names an ignored file too, since git holds it no more than an untracked one.
112
+ # Which of paths, relative to the project, git does not track, ignored or not.
124
113
  #: (Array[String]) -> Array[String]
125
- def untracked_including_ignored(paths)
126
- return [] if paths.empty?
127
-
128
- output, = git(["ls-files", "--others", "-z", "--", *paths])
129
- output.split("\0").sort
130
- end
114
+ def untracked_including_ignored(paths) = @changes.untracked_including_ignored(paths)
131
115
 
132
116
  # Every path in the project git tracks, as git spells it, sorted, so a path a disk that folds case opens under
133
117
  # another spelling can be told apart; none outside git.
@@ -137,16 +121,10 @@ module Principles
137
121
  ok ? output.force_encoding("UTF-8").split("\0").sort : []
138
122
  end
139
123
 
140
- # Every file in the project that differs from HEAD, is gone since it, or is untracked, sorted. Unlike
141
- # uncommitted, it leaves ignored files out: it is asked about the whole project, where an ignored file is
142
- # one the owner chose to keep out of git, while uncommitted is asked about named members, which an audit
143
- # needs committed. Before the first commit, every file not ignored is one.
124
+ # Every file in the project that differs from HEAD, is gone since it, or is untracked, ignored ones aside,
125
+ # sorted.
144
126
  #: () -> Array[String]
145
- def changed_files
146
- changed, = head ? git(["diff", "--name-only", "--relative", "-z", "HEAD"]) : [""]
147
- untracked, = git(["ls-files", "--others", "--exclude-standard", "-z"])
148
- (changed.split("\0") + untracked.split("\0")).uniq.sort
149
- end
127
+ def changed_files = @changes.changed_files(committed: !head.nil?)
150
128
 
151
129
  # path's text at commit, frozen, or nil when the commit does not hold it. Text at a full sha never changes, so
152
130
  # git is asked for it once; HEAD moves with each commit, so it is asked every time.
@@ -154,7 +132,7 @@ module Principles
154
132
  def text_at(commit, path)
155
133
  return read_text_at(commit, path) unless FULL_SHA.match?(commit)
156
134
 
157
- @texts[[commit, path]] ||= read_text_at(commit, path)
135
+ @texts.text(name_at(commit, path))
158
136
  end
159
137
 
160
138
  # The commits after commit, up to HEAD, that changed any of paths, newest first, each as its short sha and
@@ -181,11 +159,25 @@ module Principles
181
159
  @log.touching(range, paths, kept: [since || up_to, up_to].all? { FULL_SHA.match?(it) })
182
160
  end
183
161
 
162
+ # Reads the commits on up_to's first-parent line, up_to a full sha, touching each of path_sets in one git log,
163
+ # so commits_touching asks git no more for any of them up to it. Any other up_to is not kept, so nothing is read.
164
+ #: (Array[Array[String]], up_to: String) -> void
165
+ def read_ahead(path_sets, up_to:)
166
+ @log.read_ahead(revision(up_to), path_sets) if FULL_SHA.match?(up_to) && !path_sets.empty?
167
+ end
168
+
184
169
  private
185
170
 
186
171
  #: (String, String) -> String?
187
- def read_text_at(commit, path)
188
- text, ok = git(["show", "--end-of-options", "#{revision(commit)}:./#{path}"])
172
+ def read_text_at(commit, path) = show(name_at(commit, path))
173
+
174
+ # How git names path, relative to the project, at commit.
175
+ #: (String, String) -> String
176
+ def name_at(commit, path) = "#{revision(commit)}:./#{path}"
177
+
178
+ #: (String) -> String?
179
+ def show(name)
180
+ text, ok = git(["show", "--end-of-options", name])
189
181
  ok ? text.force_encoding("UTF-8").freeze : nil
190
182
  end
191
183
 
@@ -12,7 +12,7 @@ module Principles
12
12
  class RunningVersion
13
13
  # git archive writes the short sha of the commit it archives here, since .gitattributes marks this file
14
14
  # export-subst; a checkout keeps the placeholder as written.
15
- ARCHIVED_COMMIT = "6eaca172" #: String
15
+ ARCHIVED_COMMIT = "e72082ee" #: String
16
16
 
17
17
  #: (?String, release: String, ?built: String?, ?archived_commit: String) -> void
18
18
  def initialize(checkout = File.expand_path("../../..", __dir__), release:, built: nil,
@@ -277,6 +277,21 @@
277
277
  "query": { "type": "string" }
278
278
  }
279
279
  },
280
+ "changed_since_audit": {
281
+ "type": "array",
282
+ "description": "Each change a decision on this open finding made since the full audit that kept it: the field, its value before and after, when and why. Only principles writes it.",
283
+ "items": {
284
+ "type": "object",
285
+ "required": ["field", "from", "to", "at", "reason"],
286
+ "properties": {
287
+ "field": { "type": "string", "enum": ["waits_on", "action", "recorded_at"] },
288
+ "from": {},
289
+ "to": {},
290
+ "at": { "type": "string", "minLength": 1 },
291
+ "reason": { "type": "string", "minLength": 1 }
292
+ }
293
+ }
294
+ },
280
295
  "repointed": {
281
296
  "type": "array",
282
297
  "description": "Each repoint of recorded_at since the full audit that kept this finding: where it pointed, where it points, when and why. Only principles writes it.",
@@ -72,7 +72,7 @@
72
72
  "usage": { "$ref": "#/$defs/prose" },
73
73
  "group": { "$ref": "#/$defs/slug" },
74
74
  "options": { "type": "array", "uniqueItems": true,
75
- "items": { "enum": ["description", "path", "section", "starting-at", "ending-at", "query", "role", "check", "file", "short", "session-start", "commits-after", "hook-event", "member", "when-files", "when-invoked", "always", "write-ups", "as", "instruction", "part", "also", "confirm", "lines", "open-findings", "history"] } },
75
+ "items": { "enum": ["description", "path", "section", "starting-at", "ending-at", "query", "role", "check", "file", "short", "session-start", "commits-after", "hook-event", "member", "when-files", "when-invoked", "always", "write-ups", "as", "instruction", "part", "also", "only", "confirm", "lines", "open-findings", "history"] } },
76
76
  "requires": { "type": "array", "uniqueItems": true, "items": { "enum": ["file"] } },
77
77
  "summary": { "$ref": "#/$defs/prose" },
78
78
  "help": { "type": "string", "pattern": "^[a-z]+(-[a-z]+)+/[a-z]+(-[a-z]+)+$" },
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "repointing-answer.schema.json",
4
- "title": "Repointing answer",
5
- "description": "What an agent answers a repoint of a principle's open findings' write-ups with: the request's id and basis, then for each finding a new recorded_at, or null to leave it, and a one-line reason. Fields this tool does not read are refused. Models::Repoint locates each new pointer.",
3
+ "$id": "deciding-answer.schema.json",
4
+ "title": "Deciding answer",
5
+ "description": "What an agent answers start-audit ID --open-findings with: the request's id and basis, then a decision per open finding it names, giving only the fields that change and a one-line reason. A field left out keeps its value. Fields this tool does not read are refused. Models::FindingDecision checks each decision.",
6
6
  "type": "object",
7
7
  "additionalProperties": false,
8
- "required": ["request_id", "basis", "repoints"],
8
+ "required": ["request_id", "basis", "decisions"],
9
9
  "properties": {
10
10
  "request_id": { "type": "string" },
11
11
  "basis": {
@@ -16,14 +16,20 @@
16
16
  "revision": { "type": ["string", "null"] }
17
17
  }
18
18
  },
19
- "repoints": {
19
+ "decision_fields": {
20
+ "type": "object",
21
+ "description": "The note start-audit ID --open-findings --as template prints at its head naming each field a decision may give and what it means, which an answer may send back and Models::OpenFindingsDecision ignores, whatever it holds."
22
+ },
23
+ "decisions": {
20
24
  "type": "array",
21
25
  "items": {
22
26
  "type": "object",
23
27
  "additionalProperties": false,
24
- "required": ["finding_id", "recorded_at", "reason"],
28
+ "required": ["finding_id"],
25
29
  "properties": {
26
30
  "finding_id": { "type": "string", "minLength": 1 },
31
+ "action": { "type": "string" },
32
+ "waits_on": { "type": ["string", "null"] },
27
33
  "recorded_at": {
28
34
  "type": ["object", "null"],
29
35
  "required": ["path"],
@@ -0,0 +1,62 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "git_command"
5
+
6
+ module Principles
7
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
8
+ module Data
9
+ # Which files in the project's working tree differ from HEAD, or git does not track, as git reports them, with
10
+ # paths relative to the project. Each is asked whether HEAD has a commit at all, since before the first commit
11
+ # nothing is committed and git has no HEAD to diff against.
12
+ class WorkingTreeChanges
13
+ #: (GitCommand) -> void
14
+ def initialize(git)
15
+ @git = git
16
+ freeze
17
+ end
18
+
19
+ # Which of paths are untracked or ignored, or differ from HEAD in the index or the working tree. Before the
20
+ # first commit, every path does.
21
+ #: (Array[String], committed: bool) -> Array[String]
22
+ def uncommitted(paths, committed:)
23
+ return [] if paths.empty?
24
+ return paths.uniq.sort unless committed
25
+
26
+ changed, = @git.run(["diff", "--name-only", "--relative", "-z", "HEAD", "--", *paths])
27
+ untracked, = @git.run(["ls-files", "--others", "-z", "--", *paths])
28
+ (changed.split("\0") + untracked.split("\0")).uniq.sort
29
+ end
30
+
31
+ # Which of paths git does not track and does not ignore. Before the first commit, every path not staged is one.
32
+ #: (Array[String]) -> Array[String]
33
+ def untracked_excluding_ignored(paths)
34
+ return [] if paths.empty?
35
+
36
+ output, = @git.run(["ls-files", "--others", "--exclude-standard", "-z", "--", *paths])
37
+ output.split("\0").sort
38
+ end
39
+
40
+ # Which of paths git does not track, ignored or not. Unlike untracked_excluding_ignored, it names an ignored
41
+ # file too, since git holds it no more than an untracked one.
42
+ #: (Array[String]) -> Array[String]
43
+ def untracked_including_ignored(paths)
44
+ return [] if paths.empty?
45
+
46
+ output, = @git.run(["ls-files", "--others", "-z", "--", *paths])
47
+ output.split("\0").sort
48
+ end
49
+
50
+ # Every file in the project that differs from HEAD, is gone since it, or is untracked, sorted. Unlike
51
+ # uncommitted, it leaves ignored files out: it is asked about the whole project, where an ignored file is
52
+ # one the owner chose to keep out of git, while uncommitted is asked about named members, which an audit
53
+ # needs committed. Before the first commit, every file not ignored is one.
54
+ #: (committed: bool) -> Array[String]
55
+ def changed_files(committed:)
56
+ changed, = committed ? @git.run(["diff", "--name-only", "--relative", "-z", "HEAD"]) : [""]
57
+ untracked, = @git.run(["ls-files", "--others", "--exclude-standard", "-z"])
58
+ (changed.split("\0") + untracked.split("\0")).uniq.sort
59
+ end
60
+ end
61
+ end
62
+ end
@@ -14,7 +14,7 @@ module Principles
14
14
  FLAG_OPTIONS = %w[short lines when-invoked always write-ups confirm open-findings history].freeze #: Array[String]
15
15
  # The options that may be given more than once, each value kept in order, as change-activation --when-files and
16
16
  # start-audit --member and --part.
17
- LIST_OPTIONS = %w[when-files also member part].freeze #: Array[String]
17
+ LIST_OPTIONS = %w[when-files also only member part].freeze #: Array[String]
18
18
  # The words that name an option taking the next word as its value.
19
19
  VALUE_WORDS = (VALUE_OPTIONS + LIST_OPTIONS).map { |name| "--#{name}" }.freeze #: Array[String]
20
20
  # Every word the parser reads as an option, which an option taking a value refuses as its value.
@@ -1,6 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "tmpdir"
4
5
  require_relative "version"
5
6
  require_relative "data/running_version"
6
7
  require_relative "data/principles_on_path"
@@ -8,8 +9,8 @@ require_relative "controllers/running_tool"
8
9
 
9
10
  module Principles
10
11
  # This process as its entry point launched it: the executable that entry point names itself by, the file it was
11
- # launched as, PATH and the folder it started in, read here so that no layer reads them. It gives every controller
12
- # the same RunningTool.
12
+ # launched as, PATH, the folder it started in and its temporary folder, read here so that no layer reads them. It
13
+ # gives every controller the same RunningTool.
13
14
  class Launch
14
15
  #: (String) -> void
15
16
  def initialize(executable)
@@ -24,7 +25,8 @@ module Principles
24
25
  Controllers::RunningTool.new(executable: @executable, version: -> { running_version },
25
26
  other_on_path: ->(asking) { on_path.other(asking) },
26
27
  launched_on_path: -> { on_path.own_first? },
27
- cwd: started_in)
28
+ folders: Controllers::RunningTool::Folders.new(cwd: started_in,
29
+ temp_directory: Dir.tmpdir))
28
30
  end
29
31
 
30
32
  private
@@ -4,6 +4,7 @@
4
4
  require "json"
5
5
 
6
6
  module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
7
8
  module Models
8
9
  # The JSON a host hands its hook after each shell call, as report-after-commit reads it: the event it ran on,
9
10
  # when the call started, and the directories whose repositories the call may have committed in. Input it cannot
@@ -5,7 +5,7 @@ require_relative "audit_record"
5
5
  require_relative "last_completed_revision"
6
6
 
7
7
  module Principles
8
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
8
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
9
9
  module Models
10
10
  # What an assessment request prints as its basis, which the agent hands back with the answer: the commit the
11
11
  # audit is based on, nil outside git, and the revision of the last completed audit record when the request was
@@ -17,6 +17,7 @@ require_relative "prior_findings"
17
17
  require_relative "decided_prior_findings"
18
18
  require_relative "disposition"
19
19
  require_relative "stale_request"
20
+ require_relative "map_change"
20
21
 
21
22
  module Principles
22
23
  # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
@@ -61,14 +62,18 @@ module Principles
61
62
  # now, and, in git, the members are as its base holds them (committed).
62
63
  # It returns the findings the last audit, whose record is given, left for this one to decide; loads is
63
64
  # what the audit lists to check now, so a change to what lists a member to check makes the request stale.
65
+ # The block gives the map at the base commit, nil when it cannot be read, asked only for a request that no
66
+ # longer matches, so the refusal names a change to the map when that map explains it.
64
67
  #: (RequestId, basis: AssessmentBasis, committed: Hash[String, String]?, record: AuditRecord?,
65
- #| loads: LoadsToCheck) -> PriorFindings
66
- def check_assessment_request(request_id, basis:, committed:, record:, loads:)
68
+ #| loads: LoadsToCheck) ?{ () -> Principle? } -> PriorFindings
69
+ def check_assessment_request(request_id, basis:, committed:, record:, loads:, &started_from)
67
70
  prior = prior_findings(record)
68
71
  now_id = assessment_id(basis, prior.digested, loads.listed)
69
72
  return prior if now_id == request_id && (basis.base.nil? || committed == @now)
70
73
 
71
- raise StaleRequest.new(id, changed_since(committed), correction_open: record&.open? || false).refusal
74
+ raise StaleRequest.new(id, changed_since(committed), correction_open: record&.open? || false,
75
+ map_change: map_change(request_id, basis, record, loads,
76
+ started_from)).refusal
72
77
  end
73
78
 
74
79
  # The answer to this audit's assessment request, checked against each member, each member's check
@@ -216,6 +221,21 @@ module Principles
216
221
 
217
222
  #: () -> Error
218
223
  def stale_request = StaleRequest.new(id).refusal
224
+
225
+ # How the map differs from the one started_from gives, when the request was printed from that map with the
226
+ # members as they are now; nil when there is no such map, it is this one, it does not give request_id, or the
227
+ # change names nothing.
228
+ #: (RequestId, AssessmentBasis, AuditRecord?, LoadsToCheck, (^() -> Principle?)?) -> MapChange?
229
+ def map_change(request_id, basis, record, loads, started_from)
230
+ base = started_from&.call
231
+ return unless base && base.version != map_version
232
+
233
+ printed = Audit.new(map: base, now: @now)
234
+ return unless printed.assessment_id(basis, printed.prior_findings(record).digested, loads.listed) == request_id
235
+
236
+ change = MapChange.new(base, @map)
237
+ change unless change.empty?
238
+ end
219
239
  end
220
240
  end
221
241
  end
@@ -4,6 +4,7 @@
4
4
  require_relative "../error"
5
5
 
6
6
  module Principles
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
7
8
  module Models
8
9
  # A current audit entry protects its map from unconfirmed removal, whether the entry is readable or not.
9
10
  class AuditEntryProtectingMap
@@ -10,7 +10,7 @@ require_relative "recorded_findings"
10
10
  require_relative "record_format"
11
11
  require_relative "recorded_members"
12
12
  require_relative "json_digest"
13
- require_relative "write_up_repoint"
13
+ require_relative "finding_decision"
14
14
  require_relative "../data/schema_check"
15
15
 
16
16
  module Principles
@@ -183,19 +183,10 @@ module Principles
183
183
  AuditRecord.new(@fields.merge("members" => members.acknowledged(key, change, check_result:).to_h))
184
184
  end
185
185
 
186
- # This record with each finding a repoint names moved by it at at; the last repoint naming a finding
187
- # wins.
188
- #: (Array[WriteUpRepoint], at: String) -> AuditRecord
189
- def repointed(repoints, at:)
190
- AuditRecord.new(@fields.merge("findings" => findings.repointed(repoints, at: at).to_a))
191
- end
192
-
193
- # The ids of the findings it leaves open whose recorded_at points elsewhere than earlier's did, as a repoint
194
- # moved them.
195
- #: (AuditRecord) -> Array[String]
196
- def write_ups_moved_since(earlier)
197
- before = earlier.left_open.to_h { |finding| [finding.id, finding.recorded_at] }
198
- left_open.select { |finding| before.key?(finding.id) && before[finding.id] != finding.recorded_at }.map(&:id)
186
+ # This record with each decision applied at at to the finding it names.
187
+ #: (Array[FindingDecision], at: String) -> AuditRecord
188
+ def decided(decisions, at:)
189
+ AuditRecord.new(@fields.merge("findings" => findings.decided(decisions, at: at).to_a))
199
190
  end
200
191
 
201
192
  # Each finding the last completed audit deferred or accepted, which the next full audit must decide:
@@ -97,7 +97,7 @@ module Principles
97
97
  #: (String) -> RecordedHashes
98
98
  def hashes_to_compare(id)
99
99
  audit = find(id) or return RecordedHashes::NONE
100
- RecordedHashes.new(audit.members.hashes_by_key, waiting: RecordFormat.new(audit.to_h).newer?)
100
+ audit.members.hashes(waiting: RecordFormat.new(audit.to_h).newer?)
101
101
  rescue RecordFormat::NewerFormatError
102
102
  RecordedHashes.new(member_hashes_as_written(id).by_key, waiting: true)
103
103
  end
@@ -7,7 +7,7 @@ require_relative "located_text"
7
7
  require_relative "line_span"
8
8
 
9
9
  module Principles
10
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
10
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
11
11
  module Models
12
12
  # The lines a full audit's members span now, each with its file, against which each evidence item of another
13
13
  # principle's open finding is said to share lines or not. These are lines, not a verdict on whether
@@ -4,7 +4,7 @@
4
4
  require_relative "candidate_outline"
5
5
 
6
6
  module Principles
7
- # The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
7
+ # The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
8
8
  module Models
9
9
  # The instruction files list-candidate-files offers, shortened without judging what is guidance. A
10
10
  # skill's templates, references and examples once filled most of a 10KB inventory (alpha 011