principles 0.0.5 → 0.0.6

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/lib/principles/after_commit_hook_options.rb +4 -1
  3. data/lib/principles/command_line.rb +12 -28
  4. data/lib/principles/command_routes.rb +7 -1
  5. data/lib/principles/controllers/acknowledgement.rb +36 -26
  6. data/lib/principles/controllers/answer.rb +7 -5
  7. data/lib/principles/controllers/assessment.rb +14 -3
  8. data/lib/principles/controllers/audit_completion.rb +3 -1
  9. data/lib/principles/controllers/command.rb +2 -2
  10. data/lib/principles/controllers/correction.rb +3 -1
  11. data/lib/principles/controllers/full_audit_request.rb +1 -1
  12. data/lib/principles/controllers/guidance_search_paths.rb +31 -0
  13. data/lib/principles/controllers/inventory.rb +3 -22
  14. data/lib/principles/controllers/mapping.rb +9 -1
  15. data/lib/principles/controllers/member_addition.rb +65 -0
  16. data/lib/principles/controllers/member_entries.rb +6 -24
  17. data/lib/principles/controllers/member_problems_report.rb +2 -2
  18. data/lib/principles/controllers/members_to_assess.rb +1 -1
  19. data/lib/principles/controllers/meta_principle_setup.rb +1 -1
  20. data/lib/principles/controllers/repoint.rb +5 -2
  21. data/lib/principles/controllers/survey.rb +60 -0
  22. data/lib/principles/data/audit_files.rb +4 -0
  23. data/lib/principles/data/candidate_files_found.rb +48 -13
  24. data/lib/principles/data/command-steps.json +77 -16
  25. data/lib/principles/data/committed_tree.rb +84 -0
  26. data/lib/principles/data/first_parent_log.rb +48 -0
  27. data/lib/principles/data/first_parent_range.rb +122 -0
  28. data/lib/principles/data/git_command.rb +37 -0
  29. data/lib/principles/data/guidance_search_paths_file.rb +107 -0
  30. data/lib/principles/data/map_files.rb +35 -10
  31. data/lib/principles/data/principles_directory.rb +40 -0
  32. data/lib/principles/data/principles_subfolder.rb +39 -16
  33. data/lib/principles/data/project_files.rb +11 -3
  34. data/lib/principles/data/repository.rb +55 -29
  35. data/lib/principles/data/requested_candidate_files.rb +43 -0
  36. data/lib/principles/data/running_version.rb +3 -5
  37. data/lib/principles/data/schemas/acknowledgement-answer.schema.json +4 -5
  38. data/lib/principles/data/schemas/answer-guide.schema.json +255 -63
  39. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  40. data/lib/principles/data/schemas/correction-answer-guide.schema.json +2 -1
  41. data/lib/principles/data/schemas/correction-answer.schema.json +6 -0
  42. data/lib/principles/data/schemas/guidance-search-paths.schema.json +13 -0
  43. data/lib/principles/data/schemas/member-map-history.schema.json +20 -0
  44. data/lib/principles/data/verified_head.rb +162 -0
  45. data/lib/principles/invocation_options.rb +2 -2
  46. data/lib/principles/models/acknowledgement.rb +28 -6
  47. data/lib/principles/models/acknowledgement_left_as_printed.rb +51 -0
  48. data/lib/principles/models/audit_entry_protecting_map.rb +28 -0
  49. data/lib/principles/models/audit_record.rb +4 -0
  50. data/lib/principles/models/audit_records.rb +34 -8
  51. data/lib/principles/models/candidate_files.rb +17 -6
  52. data/lib/principles/models/candidate_inventory.rb +51 -7
  53. data/lib/principles/models/captured_head.rb +72 -0
  54. data/lib/principles/models/check_since_last_audit.rb +4 -8
  55. data/lib/principles/models/declared_map_changes.rb +25 -9
  56. data/lib/principles/models/declared_member_removals.rb +75 -0
  57. data/lib/principles/models/disposition.rb +4 -2
  58. data/lib/principles/models/fix_only_fields.rb +12 -0
  59. data/lib/principles/models/guidance_search_path.rb +26 -0
  60. data/lib/principles/models/guidance_search_paths.rb +57 -0
  61. data/lib/principles/models/line_span.rb +6 -0
  62. data/lib/principles/models/loaded_files.rb +1 -2
  63. data/lib/principles/models/loading_scope.rb +61 -0
  64. data/lib/principles/models/locator.rb +6 -0
  65. data/lib/principles/models/mapped_principles.rb +39 -37
  66. data/lib/principles/models/member_file.rb +20 -71
  67. data/lib/principles/models/member_history.rb +7 -5
  68. data/lib/principles/models/member_loading_scopes.rb +49 -0
  69. data/lib/principles/models/member_loads.rb +4 -0
  70. data/lib/principles/models/member_mapping_run.rb +30 -0
  71. data/lib/principles/models/member_moves.rb +4 -0
  72. data/lib/principles/models/member_problems.rb +48 -24
  73. data/lib/principles/models/member_region.rb +129 -0
  74. data/lib/principles/models/member_repair_moves.rb +9 -11
  75. data/lib/principles/models/member_snapshots.rb +14 -1
  76. data/lib/principles/models/members_in_consecutive_sections.rb +56 -0
  77. data/lib/principles/models/meta_principle.rb +14 -0
  78. data/lib/principles/models/missing_files.rb +2 -2
  79. data/lib/principles/models/other_templates_placeholders.rb +1 -1
  80. data/lib/principles/models/outline_budget.rb +29 -14
  81. data/lib/principles/models/principle.rb +14 -7
  82. data/lib/principles/models/principle_file_revision.rb +48 -0
  83. data/lib/principles/models/principle_history.rb +46 -19
  84. data/lib/principles/models/principle_lineage.rb +118 -0
  85. data/lib/principles/models/principle_map_revision.rb +39 -0
  86. data/lib/principles/models/principle_mapping_history.rb +132 -0
  87. data/lib/principles/models/principle_members.rb +14 -0
  88. data/lib/principles/models/principle_predecessor.rb +45 -0
  89. data/lib/principles/models/principle_publication.rb +177 -0
  90. data/lib/principles/models/principle_revision.rb +104 -0
  91. data/lib/principles/models/problem_report.rb +17 -5
  92. data/lib/principles/models/project.rb +43 -27
  93. data/lib/principles/models/project_history.rb +45 -25
  94. data/lib/principles/models/record_format.rb +6 -0
  95. data/lib/principles/models/reported_check.rb +2 -1
  96. data/lib/principles/models/sent_answer.rb +10 -0
  97. data/lib/principles/models/survey_search_paths.rb +26 -0
  98. data/lib/principles/models/uncommitted_files.rb +50 -0
  99. data/lib/principles/models/unknown_principle.rb +29 -0
  100. data/lib/principles/positional_arguments.rb +37 -0
  101. data/lib/principles/version.rb +2 -2
  102. data/lib/principles/views/acknowledgement_result.rb +16 -12
  103. data/lib/principles/views/added_member.rb +41 -0
  104. data/lib/principles/views/answered_request.rb +21 -0
  105. data/lib/principles/views/assessment_request.rb +2 -1
  106. data/lib/principles/views/audit_result.rb +21 -26
  107. data/lib/principles/views/candidate_files_result.rb +56 -12
  108. data/lib/principles/views/candidate_outlines_result.rb +25 -0
  109. data/lib/principles/views/consecutive_sections_elsewhere.rb +27 -0
  110. data/lib/principles/views/correction_request.rb +32 -1
  111. data/lib/principles/views/guidance_search_paths_result.rb +26 -0
  112. data/lib/principles/views/json_with_entries_on_lines.rb +12 -4
  113. data/lib/principles/views/map_added_to.rb +56 -2
  114. data/lib/principles/views/map_result.rb +22 -42
  115. data/lib/principles/views/maps_needing_members_or_audit.rb +47 -0
  116. data/lib/principles/views/member_change_since_baseline.rb +2 -1
  117. data/lib/principles/views/member_repairs.rb +2 -1
  118. data/lib/principles/views/new_loading_scope.rb +31 -0
  119. data/lib/principles/views/one_member_check_result_template.rb +25 -21
  120. data/lib/principles/views/principle_read_result.rb +4 -1
  121. data/lib/principles/views/principles_with_no_completed_audit.rb +9 -3
  122. data/lib/principles/views/problem_lines.rb +3 -1
  123. data/lib/principles/views/problem_result.rb +8 -3
  124. data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -3
  125. data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -6
  126. data/lib/principles/views/prompts/assess-every-member/answer-guide.json +67 -43
  127. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -0
  128. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +12 -0
  129. data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -0
  130. data/lib/principles/views/prompts/find-a-principle-to-map/ask-about-other-guidance-search-paths.md +6 -0
  131. data/lib/principles/views/prompts/find-a-principle-to-map/choose-an-existing-or-new-principle.md +2 -0
  132. data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +4 -2
  133. data/lib/principles/views/prompts/find-a-principle-to-map/compare-with-mapped-principles.md +11 -0
  134. data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +2 -2
  135. data/lib/principles/views/prompts/find-a-principle-to-map/survey-a-later-range.md +3 -0
  136. data/lib/principles/views/prompts/find-a-principle-to-map/what-each-command-writes.md +4 -4
  137. data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +5 -4
  138. data/lib/principles/views/prompts/learn-what-a-command-does/add-guidance-search-path.md +17 -0
  139. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +35 -6
  140. data/lib/principles/views/prompts/learn-what-a-command-does/create-principle.md +16 -0
  141. data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +37 -4
  142. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +5 -4
  143. data/lib/principles/views/prompts/learn-what-a-command-does/move-member.md +5 -0
  144. data/lib/principles/views/prompts/learn-what-a-command-does/remove-guidance-search-path.md +13 -0
  145. data/lib/principles/views/prompts/learn-what-a-command-does/remove-principle.md +25 -0
  146. data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +26 -0
  147. data/lib/principles/views/prompts/learn-what-a-command-does/show-candidate-outlines.md +21 -0
  148. data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +2 -2
  149. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +51 -54
  150. data/lib/principles/views/prompts/read-requested-outlines/continue-the-survey.md +7 -0
  151. metadata +55 -4
  152. data/lib/principles/models/candidate_listing.rb +0 -41
@@ -59,8 +59,8 @@ module Principles
59
59
  # (#187), and each principle waiting on an upgrade.
60
60
  #: (Models::ProblemReport, Array[Views::RecordWaitingOnAnUpgrade]) -> untyped
61
61
  def member_problems(problems, waiting)
62
- report = problems.checked do |map_id, member, baseline, now|
63
- principle_history(map_id).member_history(member, baseline: baseline, now: now)
62
+ report = problems.checked do |map_id, member, baseline, now, mapping|
63
+ @project.principle_history(map_id, mapping: mapping).member_history(member, baseline: baseline, now: now)
64
64
  end
65
65
  Views::ProblemResult.new(invocation).checked(report, not_read: @project.unread_older_files,
66
66
  no_baseline_files: problems.files_to_commit(@principles),
@@ -39,7 +39,7 @@ module Principles
39
39
  @principle_id = principle_id
40
40
  @record = @audit_records.find(principle_id) #: Models::AuditRecord?
41
41
  @completed = @record&.last_completed #: Models::AuditRecord?
42
- @checks = Models::CheckSinceLastAudit.new(id: principle_id, history: @history, principles: @principles,
42
+ @checks = Models::CheckSinceLastAudit.new(principle_history: principle_history(principle_id),
43
43
  record: @record) #: Models::CheckSinceLastAudit
44
44
  end
45
45
 
@@ -43,7 +43,7 @@ module Principles
43
43
  #: (Models::Principle) -> Views::MetaPrincipleResult::MapInProject
44
44
  def map_in_project(map)
45
45
  Views::MetaPrincipleResult::MapInProject.new(
46
- already_mapped: @principles.mapped?(map.id), members_in_entry_files: map.members_in(Models::EntryFiles::PATHS),
46
+ already_mapped: @principles.mapped?(map.id), members_in_entry_files: map.members.members_in(Models::EntryFiles::PATHS),
47
47
  set_up: @principles.set_up?
48
48
  )
49
49
  end
@@ -7,6 +7,8 @@ require_relative "../models/finding_write_ups"
7
7
  require_relative "../models/repoint"
8
8
  require_relative "../views/repoint_result"
9
9
 
10
+ require_relative "../views/answered_request"
11
+
10
12
  module Principles
11
13
  # Each runs one command: reads models, applies their rules and prints through a view.
12
14
  # controllers/CLAUDE.md owns the boundary.
@@ -29,7 +31,7 @@ module Principles
29
31
  # The result of answering, and the record it changes, not yet written, which the repoint refuses once the last
30
32
  # completed record changed after the request was printed, unless it writes nothing.
31
33
  # @override
32
- #: (Models::SubmittedAnswer) -> [Hash[String, untyped], Array[Models::AuditRecord]]
34
+ #: (Models::SubmittedAnswer) -> [Views::AnsweredRequest, Array[Models::AuditRecord]]
33
35
  def answered(submitted)
34
36
  id = submitted.request_id.principle_id
35
37
  response = submitted.response
@@ -37,7 +39,8 @@ module Principles
37
39
  repointed, changes = repoint.writable(response, records: @audit_records, at: Time.now.utc.iso8601) do |locator|
38
40
  snapshot(locator)
39
41
  end
40
- [view.repointed(principle_id: id, file: @audit_records.file(id), outcome: outcome(repoint, repointed)), changes]
42
+ [Views::AnsweredRequest.new(view.repointed(principle_id: id, file: @audit_records.file(id),
43
+ outcome: outcome(repoint, repointed))), changes]
41
44
  end
42
45
 
43
46
  private
@@ -0,0 +1,60 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../views/candidate_files_result"
6
+ require_relative "../views/candidate_outlines_result"
7
+ require_relative "../views/json_with_entries_on_lines"
8
+
9
+ module Principles
10
+ # Each runs one command: reads models, applies their rules and prints through a view.
11
+ # controllers/CLAUDE.md owns the boundary.
12
+ module Controllers
13
+ # list-candidate-files: the survey of the files that look like agent guidance, with their outlines within the
14
+ # budget, and the question of which principle they carry. It changes nothing on disk, and changes for the survey's
15
+ # reasons alone, apart from the reads of what is already mapped (#1015).
16
+ class Survey < Command
17
+ #: (String, String?, Hash[String, untyped]) -> untyped
18
+ def call(command, _id, options)
19
+ naming_the_executable do
20
+ case command
21
+ when "list-candidate-files" then list_candidate_files(options)
22
+ when "show-candidate-outlines" then show_candidate_outlines(options.fetch("path"))
23
+ else unknown(command)
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ #: (Array[String]) -> Views::JsonWithEntriesOnLines
31
+ def show_candidate_outlines(paths)
32
+ found = @project.candidate_outlines(paths)
33
+ .within_budget { |inventory| Views::CandidateOutlinesResult.new(inventory.to_h).result.text.bytesize }
34
+ Views::CandidateOutlinesResult.new(found.to_h).result
35
+ end
36
+
37
+ # The survey; with a revision, only once it names a commit in git (#1171).
38
+ #: (Hash[String, untyped]) -> untyped
39
+ def list_candidate_files(options)
40
+ after = options["commits_after"]
41
+ mapped = @principles.descriptions
42
+ commit = @history.commit_named(after) if after
43
+ found = @project.candidate_files(after: commit, also: options.fetch("also", []))
44
+ .within_budget { |inventory| candidate_files_result(inventory, mapped).text.bytesize }
45
+ candidate_files_result(found, mapped)
46
+ end
47
+
48
+ # list-candidate-files' result for one inventory, as it prints.
49
+ #: (Models::CandidateInventory, Array[Hash[String, untyped]]) -> Views::JsonWithEntriesOnLines
50
+ def candidate_files_result(found, mapped)
51
+ listed = Views::CandidateFilesResult::Found.new(inventory: found.to_h, untracked: found.untracked,
52
+ owner_asks: found.owner_asks)
53
+ question = Views::CandidateFilesResult.new(invocation).question(listed, existing_maps: @principles.ids,
54
+ map_file: @principles.file("ID"),
55
+ mapped_principles: mapped)
56
+ Views::JsonWithEntriesOnLines.new(question.merge("wrote" => []), under: "inventory", key: "files")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -33,6 +33,10 @@ module Principles
33
33
  @directory.exist?(id)
34
34
  end
35
35
 
36
+ # Any current entry, including an unreadable record or dangling link, protects a map from removal.
37
+ #: (String) -> bool
38
+ def entry?(id) = @directory.entry?(id, shown_as: relative(id))
39
+
36
40
  # The record of id's last audit, or nil when it has none, checked against its schema (D29), handing the block
37
41
  # a record the schema refuses, as parse does.
38
42
  #: (String) ?{ (untyped) -> void } -> Hash[String, untyped]?
@@ -15,7 +15,7 @@ module Principles
15
15
  # Folders the inventory never enters: version control, this tool's own records, and installed packages.
16
16
  PRUNED_FOLDERS = %w[.git .principles .memeplex .coord node_modules vendor .bundle].freeze
17
17
 
18
- # The instruction files an agent host loads by convention. The inventory lists only these.
18
+ # The instruction files an agent host loads by convention, beside any explicitly selected paths.
19
19
  CANDIDATE_NAMES = %w[CLAUDE.md AGENTS.md].freeze
20
20
  CANDIDATE_PATH = %r{(?:\A|/)\.claude/(?:rules/|skills/|agents/|settings[^/]*\.json\z)}
21
21
 
@@ -32,39 +32,73 @@ module Principles
32
32
  leads_to == path ? entry : entry.merge("symlink_to" => leads_to)
33
33
  end
34
34
 
35
- #: (ProjectFiles) -> void
36
- def initialize(files)
35
+ # also names more files to list, inside the project, beside those hosts load by convention.
36
+ #: (ProjectFiles, ?also: Array[String], ?matching: Array[String]) -> void
37
+ def initialize(files, also: [], matching: [])
37
38
  @files = files
39
+ @also = also
40
+ @matching = matching
38
41
  end
39
42
 
40
43
  #: () -> Hash[String, untyped]
41
44
  def to_h
42
- candidates = candidate_paths
45
+ walked = candidate_paths
46
+ candidates = walked | @also
43
47
  ignored = IgnoredByGit.new(@files.root, candidates).facts
44
- entries, skipped = readable(candidates - (ignored&.fetch("ignored") || []))
45
- entries = entries.sort_by { |entry| entry.fetch("path") }
46
- listed = { "files" => entries, "unreadable" => skipped,
47
- "possibly_test_data" => entries.filter_map { |entry| test_data_hint(entry.fetch("path")) } }
48
+ listed = listing(candidates - (ignored&.fetch("ignored") || [])).merge(additional_search_paths(walked))
48
49
  ignored ? listed.merge(ignored) : listed
49
50
  end
50
51
 
51
52
  private
52
53
 
54
+ # Explicit matches before ignore/readability filtering; counts of zero remain observable.
55
+ #: (Array[String]) -> Hash[String, untyped]
56
+ def additional_search_paths(paths)
57
+ return { "selected_files" => @also.uniq.sort } if @matching.empty?
58
+
59
+ matches = @matching.to_h { |glob| [glob, paths.select { |path| matches?(glob, path) }] }
60
+ { "selected_files" => (@also | matches.values.flatten).sort,
61
+ "additional_search_paths" => matches.map do |glob, found|
62
+ { "glob" => glob, "matched_files" => found.length }
63
+ end }
64
+ end
65
+
66
+ #: (String, String) -> bool
67
+ def matches?(glob, path)
68
+ File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
69
+ end
70
+
71
+ # Readable file entries and per-path refusals, with the test-data hints for readable entries.
72
+ #: (Array[String]) -> Hash[String, untyped]
73
+ def listing(paths)
74
+ entries, skipped = readable(paths)
75
+ entries = entries.sort_by { |entry| entry.fetch("path") }
76
+ { "files" => entries, "unreadable" => skipped,
77
+ "possibly_test_data" => entries.filter_map { |entry| test_data_hint(entry.fetch("path")) } }
78
+ end
79
+
53
80
  # Each candidate's path relative to the root, in the order the walk finds them.
54
81
  #: () -> Array[String]
55
82
  def candidate_paths
56
83
  paths = [] #: Array[String]
57
84
  Find.find(@files.root) do |absolute|
58
- if File.directory?(absolute)
59
- Find.prune if PRUNED_FOLDERS.include?(File.basename(absolute)) || nested_repository?(absolute)
60
- next
61
- end
85
+ next unless file_in_walk?(absolute)
86
+
62
87
  relative = absolute.delete_prefix("#{@files.root}/")
63
88
  paths << relative if candidate?(relative)
64
89
  end
65
90
  paths
66
91
  end
67
92
 
93
+ # Whether this walk visits a file, pruning internal folders and other projects before descending.
94
+ #: (String) -> bool
95
+ def file_in_walk?(absolute)
96
+ return File.basename(absolute) != ".git" unless File.directory?(absolute)
97
+
98
+ Find.prune if PRUNED_FOLDERS.include?(File.basename(absolute)) || nested_repository?(absolute)
99
+ false
100
+ end
101
+
68
102
  # A folder below the root holding its own .git, a worktree's file or a clone's folder, is another project,
69
103
  # as git treats it (#376). The root may hold one too: this tool runs in a worktree.
70
104
  #: (String) -> bool
@@ -98,7 +132,8 @@ module Principles
98
132
 
99
133
  #: (String) -> bool
100
134
  def candidate?(relative)
101
- CANDIDATE_NAMES.include?(File.basename(relative)) || relative.match?(CANDIDATE_PATH)
135
+ CANDIDATE_NAMES.include?(File.basename(relative)) || relative.match?(CANDIDATE_PATH) ||
136
+ @matching.any? { |glob| matches?(glob, relative) }
102
137
  end
103
138
  end
104
139
  end
@@ -4,6 +4,10 @@
4
4
  "writes": "Writes nothing." },
5
5
  { "id": "write-map", "heading": "Write the member map, `.principles/maps/ID.json`, which the project commits",
6
6
  "writes": "Writes `.principles/maps/ID.json`; commit it as it changes. Never a member's file." },
7
+ { "id": "remove-map", "heading": "Remove an obsolete map; retain its member files and audit history",
8
+ "writes": "Removes only `.principles/maps/ID.json`, listed under `removed`; `wrote` is empty. Commit the removal if the map was tracked. Retains member files and audit entries." },
9
+ { "id": "write-guidance-search-paths", "heading": "Write the recorded guidance search paths, which the project commits",
10
+ "writes": "Writes `.principles/guidance-search-paths.json`; commit it as it changes. Never a map, audit or guidance file." },
7
11
  { "id": "write-audit-record", "heading": "Audit; these write only the audit record, `.principles/audits/ID.json`, which the project commits",
8
12
  "writes": "Writes `.principles/audits/ID.json`, listed under `wrote` when it does; commit it. Never the map or a member's file." }
9
13
  ],
@@ -18,19 +22,43 @@
18
22
  },
19
23
  "commands": [
20
24
  {
21
- "name": "list-candidate-files", "usage": "list-candidate-files", "group": "read", "options": [],
25
+ "name": "list-candidate-files", "usage": "list-candidate-files [--commits-after REV] [--also GLOB]...", "group": "read", "options": ["commits-after", "also"],
22
26
  "summary": "Ask what in this project looks like a principle.",
23
27
  "help": "learn-what-a-command-does/list-candidate-files",
24
28
  "steps": [
25
29
  { "id": "list-instruction-files", "actor": "cli",
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." },
30
+ "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. With --commits-after, lists the files the commits after it changed first, marked, Markdown outside those places included, and refuses outside git and a revision git cannot resolve to a commit. Repeated --also root-relative globs include explicitly selected guidance, including skill references and named non-Markdown files; additional_search_paths reports each match count within traversal boundaries. No location is saved.",
31
+ "refuses": ["range_needs_git", "unknown_revision", "invalid_guidance_search_path"] },
27
32
  { "id": "choose-one-principle", "actor": "agent",
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.",
33
+ "does": "Show the user a table of the principles several listed files reinforce, asking nothing before it, then, when maps exist, compare each rule with the descriptions in mapped_principles before choosing whether to extend an existing map or create a distinct one. Decide whether each file named in possibly_test_data is guidance or a sample. After the table, ask where else the repository keeps guidance; --also includes it in a read-only survey without recording it.",
29
34
  "prompt": "find-a-principle-to-map/choose-one-principle",
30
- "cannot_check": "whether a file is guidance or test data; ask the project's owner when you cannot tell.",
35
+ "cannot_check": "whether a rule is a facet of an existing principle or distinct, or whether a file is guidance or test data; ask the project's owner when you cannot tell.",
36
+ "next": [
37
+ { "to": "extend-existing-principle", "when": "the rule is a facet of an existing principle" },
38
+ { "to": "map-distinct-principle", "when": "the rule is a distinct principle" }
39
+ ] },
40
+ { "id": "extend-existing-principle", "actor": "agent",
41
+ "does": "Choose the existing principle and the additional place that carries it, with its role.",
42
+ "answer_with": "add-member" },
43
+ { "id": "map-distinct-principle", "actor": "agent",
44
+ "does": "Choose a lower-kebab-case id and describe what the distinct principle is and why it matters.",
31
45
  "answer_with": "create-principle" }
32
46
  ]
33
47
  },
48
+ {
49
+ "name": "show-candidate-outlines", "usage": "show-candidate-outlines PATH...", "group": "read", "options": [],
50
+ "summary": "Read the outlines the survey left out, by literal file path.",
51
+ "help": "learn-what-a-command-does/show-candidate-outlines",
52
+ "steps": [
53
+ { "id": "read-requested-outlines", "actor": "cli",
54
+ "does": "Lists only the requested literal project files, once each, in path order. Each readable Markdown file receives the survey's outline, including explicitly requested test data and skill references; non-Markdown files show path and size alone. Ignored files and links to ignored text stay unread. Each failed path retains its refusal beside successful entries. The whole rendered result uses OutlineBudget and names shortened or omitted outlines.",
55
+ "refuses_like": ["locate-text"] },
56
+ { "id": "continue-the-survey", "actor": "agent",
57
+ "does": "Judge which requested outlines matter to the survey. Repair failed paths; request fewer paths to recover omitted outlines, or read only needed line ranges when one file remains too large.",
58
+ "prompt": "read-requested-outlines/continue-the-survey",
59
+ "cannot_check": "whether a file or rule matters to the task; the agent judges relevance." }
60
+ ]
61
+ },
34
62
  {
35
63
  "name": "list-principles", "usage": "list-principles", "group": "read", "options": [],
36
64
  "summary": "Every mapped principle and whether its members are current.",
@@ -96,9 +124,9 @@
96
124
  "steps": [
97
125
  { "id": "check-without-writing", "actor": "cli",
98
126
  "does": "Runs every check submit-answer would and prints the same refusal, or names the files submitting would write. Writes nothing.",
99
- "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request", "stale_request", "stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git",
127
+ "refuses": ["unparseable_json", "unreadable_file", "request_mismatch", "unknown_request", "stale_request", "stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git", "invalid_removed_members", "empty_correction_map",
100
128
  "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding",
101
- "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes"],
129
+ "incomplete_dispositions", "invalid_disposition", "claimed_change_missing", "unassessed_changes", "git_history_unavailable"],
102
130
  "refuses_like": ["read-map", "read-audit", "locate-text", "rewrite-audit"] },
103
131
  { "id": "submit-the-checked-answer", "actor": "agent",
104
132
  "does": "Fix what a refusal names and check again, or submit the answer unchanged.",
@@ -125,14 +153,27 @@
125
153
  "help": "learn-what-a-command-does/create-principle",
126
154
  "steps": [
127
155
  { "id": "write-new-map", "actor": "cli",
128
- "does": "Checks that ID is lower-kebab-case, not yet mapped and not sticking-to-your-principles, which setup starts, then writes a map with the description and no members.",
129
- "refuses": ["invalid_id", "principle_exists", "meta_principle_id", "invalid_answer"] },
156
+ "does": "Checks that ID is lower-kebab-case, not yet mapped and not sticking-to-your-principles, which setup starts. Verifies that its map is absent at committed HEAD, requiring any prior removal to be committed, then writes a map with the description and no members.",
157
+ "refuses": ["invalid_id", "principle_exists", "meta_principle_id", "invalid_answer", "map_removal_not_committed", "git_history_unavailable"] },
130
158
  { "id": "choose-members", "actor": "agent",
131
- "does": "Choose the files, sections or passages that reinforce the principle, and the part each plays.",
159
+ "does": "Choose the files, sections or passages that reinforce the principle, and the part each plays, using list-candidate-files to survey the guidance first if no survey has been done.",
132
160
  "cannot_check": "whether the members you choose are the right ones.",
133
161
  "answer_with": "add-member" }
134
162
  ]
135
163
  },
164
+ {
165
+ "name": "remove-principle", "usage": "remove-principle ID [--confirm]", "group": "remove-map", "options": ["confirm"],
166
+ "summary": "Remove an obsolete map while keeping its member files and audit history.",
167
+ "help": "learn-what-a-command-does/remove-principle",
168
+ "steps": [
169
+ { "id": "remove-map-with-audit-protection", "actor": "cli",
170
+ "does": "Removes only the named map. Refuses any current audit entry unless --confirm explicitly deactivates its map in routine reports, preserving the entry and unresolved findings. An unknown entry check still refuses.",
171
+ "refuses_like": ["read-map"], "refuses": ["principle_has_audit_record", "store_entry_unreadable", "store_remove_failed", "symlinked_store_file", "not_a_file"] },
172
+ { "id": "inspect-remaining-maps", "actor": "agent",
173
+ "does": "Commit the map removal if it was tracked, then inspect the remaining principles.",
174
+ "answer_with": "list-principles" }
175
+ ]
176
+ },
136
177
  {
137
178
  "name": "change-description", "usage": "change-description ID --description TEXT", "group": "write-map", "options": ["description"],
138
179
  "summary": "Reword a mapped principle.",
@@ -158,8 +199,8 @@
158
199
  "help": "learn-what-a-command-does/add-member",
159
200
  "steps": [
160
201
  { "id": "locate-new-member", "actor": "cli",
161
- "does": "Finds the member's text, so a locator that matches nothing is refused now rather than at the audit.",
162
- "refuses": ["invalid_answer", "ending_without_start"], "refuses_like": ["read-map", "locate-text"] },
202
+ "does": "Loads the map, or starts sticking-to-your-principles only after verifying its map path is absent at committed HEAD, requiring any prior removal to be committed. Then finds the member's text, so a locator that matches nothing is refused now rather than at the audit.",
203
+ "refuses": ["invalid_answer", "ending_without_start", "ambiguous_passage_end", "map_removal_not_committed", "git_history_unavailable"], "refuses_like": ["read-map", "locate-text"] },
163
204
  { "id": "write-member", "actor": "cli",
164
205
  "does": "Refuses a member already in the map, then adds it with its role; the first member of sticking-to-your-principles creates its map.",
165
206
  "refuses": ["member_exists"] },
@@ -178,7 +219,7 @@
178
219
  "refuses": ["unknown_member", "invalid_answer"], "refuses_like": ["read-map"] },
179
220
  { "id": "locate-new-place", "actor": "cli",
180
221
  "does": "Finds the text at the new locator, in PATH when --path names the file the member's file was renamed to or its text moved into, or else in its own file. The locator replaces the old one whole, and the member keeps its role and the key its audit is filed under.",
181
- "refuses": ["invalid_answer", "ending_without_start", "member_exists"], "refuses_like": ["locate-text"] }
222
+ "refuses": ["invalid_answer", "ending_without_start", "ambiguous_passage_end", "member_exists"], "refuses_like": ["locate-text"] }
182
223
  ]
183
224
  },
184
225
  {
@@ -279,8 +320,8 @@
279
320
  "next": [{ "to": "check-assessment", "when": "the request was an assessment" },
280
321
  { "to": "check-dispositions", "when": "the request was a correction" }] },
281
322
  { "id": "check-assessment", "actor": "cli",
282
- "does": "Refuses an answer when the map, a member, its base commit or the listed loads changed since the request. Then checks every member is covered once, every field and piece of evidence resolves, and each listed loading and prior finding is decided once. Prints a correction request for findings; outside git, writes the record as open.",
283
- "refuses": ["stale_request", "audit_completed_since_request", "incomplete_prior_findings", "invalid_decision", "raised_in_not_found", "raised_in_unreadable", "raised_in_lacks_finding", "raised_in_time_differs", "first_raised_not_earlier", "incomplete_loading_decisions", "invalid_loading_decision", "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding"],
323
+ "does": "Refuses changed request inputs or, with a Git base, a committed current-ID map gap on captured HEAD's first-parent line; unverifiable continuity refuses. Checks complete member, loading and prior-finding decisions and resolvable evidence. Prints a correction request for findings, writing an open record only outside git.",
324
+ "refuses": ["stale_request", "git_history_unavailable", "audit_completed_since_request", "incomplete_prior_findings", "invalid_decision", "raised_in_not_found", "raised_in_unreadable", "raised_in_lacks_finding", "raised_in_time_differs", "first_raised_not_earlier", "incomplete_loading_decisions", "invalid_loading_decision", "incomplete_coverage", "invalid_delivery", "observation_repeats_last_audit", "invalid_check_result", "invalid_answer", "unknown_member", "duplicate_finding"],
284
325
  "refuses_like": ["locate-text"],
285
326
  "next": [{ "to": "complete-audit", "when": "there are no findings" },
286
327
  { "to": "dispose-of-each-finding", "when": "there are findings" }] },
@@ -291,8 +332,8 @@
291
332
  "cannot_check": "whether a fix is right or a deferral justified.",
292
333
  "answer_with": "submit-answer" },
293
334
  { "id": "check-dispositions", "actor": "cli",
294
- "does": "Refuses a correction when the map changed since the assessment beyond moved_members. Then checks one disposition per finding, that only fixed findings' members changed since the base, and that each recorded_at resolves.",
295
- "refuses": ["stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git", "stale_request", "audit_completed_since_request", "incomplete_dispositions", "invalid_disposition", "invalid_answer", "claimed_change_missing", "unassessed_changes"],
335
+ "does": "Checks the original request, basis and hashes and, with a Git base, uninterrupted current-ID map presence on captured HEAD's first-parent line. Refuses unverifiable continuity or undeclared map changes. Checks one disposition per finding, that only fixed members changed since the base, and each recorded_at resolves.",
336
+ "refuses": ["stale_map", "undeclared_move", "moves_need_git", "map_entries_need_git", "invalid_removed_members", "empty_correction_map", "stale_request", "git_history_unavailable", "audit_completed_since_request", "incomplete_dispositions", "invalid_disposition", "invalid_answer", "claimed_change_missing", "unassessed_changes"],
296
337
  "refuses_like": ["locate-text"] },
297
338
  { "id": "complete-audit", "actor": "cli",
298
339
  "does": "Writes the record unless it already says the same, and prints the open and resolved findings and the files to commit, in git only those differing from HEAD, with the commits since the base touching each changed member.",
@@ -301,6 +342,26 @@
301
342
  "does": "Commit the record with your fixes, and report the outcome, open findings included, to the project's owner.",
302
343
  "cannot_check": "that the owner was told, or that you committed." }
303
344
  ]
345
+ },
346
+ {
347
+ "name": "add-guidance-search-path", "usage": "add-guidance-search-path GLOB", "group": "write-guidance-search-paths", "options": [],
348
+ "summary": "Record an additional guidance search path after the principles table has been shown.",
349
+ "help": "learn-what-a-command-does/add-guidance-search-path",
350
+ "steps": [
351
+ { "id": "record-guidance-search-path", "actor": "cli",
352
+ "does": "Validate a root-relative glob and record it once in the project's guidance search paths.",
353
+ "refuses": ["invalid_guidance_search_path", "unparseable_guidance_search_paths", "invalid_guidance_search_paths", "newer_guidance_search_paths", "guidance_search_paths_io_error", "symlinked_directory", "symlinked_guidance_search_paths"] }
354
+ ]
355
+ },
356
+ {
357
+ "name": "remove-guidance-search-path", "usage": "remove-guidance-search-path GLOB", "group": "write-guidance-search-paths", "options": [],
358
+ "summary": "Stop recording one additional guidance search path.",
359
+ "help": "learn-what-a-command-does/remove-guidance-search-path",
360
+ "steps": [
361
+ { "id": "remove-recorded-location", "actor": "cli",
362
+ "does": "Validate the glob and remove that recorded location, retaining an empty configuration after the last removal.",
363
+ "refuses": ["invalid_guidance_search_path", "unknown_guidance_search_path", "unparseable_guidance_search_paths", "invalid_guidance_search_paths", "newer_guidance_search_paths", "guidance_search_paths_io_error", "symlinked_directory", "symlinked_guidance_search_paths"] }
364
+ ]
304
365
  }
305
366
  ]
306
367
  }
@@ -0,0 +1,84 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../error"
5
+ require_relative "git_command"
6
+
7
+ module Principles
8
+ # Every file and process this tool reads or writes. data/CLAUDE.md owns the boundary.
9
+ module Data
10
+ # The literal entries of one exact committed tree, read through its supplied Git command.
11
+ class CommittedTree
12
+ SHA = /\A\h{40}(?:\h{24})?\z/ #: Regexp
13
+ ENTRY_TYPES = { "100644" => "blob", "100755" => "blob", "120000" => "blob", "040000" => "tree",
14
+ "160000" => "commit" }.freeze #: Hash[String, String]
15
+
16
+ #: (GitCommand, String, Error) -> void
17
+ def initialize(git, revision, refusal)
18
+ @git = git
19
+ @revision = revision.dup.freeze #: String
20
+ @refusal = refusal
21
+ freeze
22
+ end
23
+
24
+ #: (String) -> bool
25
+ def entry?(path) = !tree_output(path).empty?
26
+
27
+ #: (String) -> Hash[String, String]?
28
+ def raw_entry(path)
29
+ output = tree_output(path)
30
+ return nil if output.empty?
31
+
32
+ fields = raw_metadata(output, path)
33
+ return fields.freeze unless fields.fetch("type") == "blob"
34
+
35
+ fields.merge("bytes" => blob_bytes(fields.fetch("object_id"))).freeze
36
+ end
37
+
38
+ private
39
+
40
+ #: (String) -> String
41
+ def tree_output(path)
42
+ raise @refusal unless SHA.match?(@revision)
43
+
44
+ output, status = @git.run_with_status(["ls-tree", "-z", @revision, "--", path])
45
+ raise @refusal unless status&.zero?
46
+
47
+ output
48
+ end
49
+
50
+ #: (String, String) -> Hash[String, String]
51
+ def raw_metadata(output, path)
52
+ record = output.b
53
+ raise @refusal unless record.end_with?("\0") && record.count("\0") == 1
54
+
55
+ metadata, returned = record.delete_suffix("\0").split("\t", 2)
56
+ raise @refusal unless returned == path.b
57
+
58
+ entry_fields(metadata.to_s)
59
+ end
60
+
61
+ #: (String) -> Hash[String, String]
62
+ def entry_fields(metadata)
63
+ match = /\A([0-7]{6}) (blob|tree|commit) (\h{40}(?:\h{24})?)\z/.match(metadata)
64
+ raise @refusal unless match
65
+
66
+ parts = match.captures.map { it.to_s.freeze }
67
+ mode = parts.fetch(0)
68
+ type = parts.fetch(1)
69
+ object_id = parts.fetch(2)
70
+ raise @refusal unless ENTRY_TYPES[mode] == type && object_id.length == @revision.length
71
+
72
+ { "mode" => mode, "type" => type, "object_id" => object_id }
73
+ end
74
+
75
+ #: (String) -> String
76
+ def blob_bytes(object_id)
77
+ bytes, status = @git.run_with_status(["cat-file", "blob", object_id])
78
+ raise @refusal unless status&.zero?
79
+
80
+ bytes.b.freeze
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,48 @@
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
+ # The commits on a first-parent line that changed any of some paths, as git log gives them, newest first, each as
10
+ # its full and short sha, subject line, author date and whether it is a root commit ("true" or "false"). The list
11
+ # and each commit are frozen, and a list asked to be kept is read from git once, a refusal included (#1161).
12
+ class FirstParentLog
13
+ #: (GitCommand) -> void
14
+ def initialize(git)
15
+ @git = git
16
+ @kept = {} #: Hash[[String, Array[String]], Array[Hash[String, String]]]
17
+ end
18
+
19
+ # The commits in range, a revision range Repository has checked, that changed any of paths; kept, when range
20
+ # always names the same commits, so git is not asked again.
21
+ #: (String, Array[String], kept: bool) -> Array[Hash[String, String]]
22
+ def touching(range, paths, kept:)
23
+ return read(range, paths) unless kept
24
+
25
+ @kept[[range, paths.dup.freeze]] ||= read(range, paths)
26
+ end
27
+
28
+ private
29
+
30
+ #: (String, Array[String]) -> Array[Hash[String, String]]
31
+ 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
35
+ end
36
+
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 }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end