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.
- checksums.yaml +4 -4
- data/lib/principles/cli.rb +3 -1
- data/lib/principles/command_line.rb +35 -7
- data/lib/principles/command_routes.rb +4 -3
- data/lib/principles/controllers/acknowledgement.rb +80 -14
- data/lib/principles/controllers/answer.rb +42 -75
- data/lib/principles/controllers/answer_phase.rb +54 -0
- data/lib/principles/controllers/assessment.rb +33 -9
- data/lib/principles/controllers/audit.rb +17 -6
- data/lib/principles/controllers/audit_completion.rb +6 -4
- data/lib/principles/controllers/command.rb +3 -2
- data/lib/principles/controllers/correction.rb +19 -9
- data/lib/principles/controllers/full_audit_request.rb +10 -0
- data/lib/principles/controllers/inventory.rb +25 -20
- data/lib/principles/controllers/member_problems_report.rb +11 -4
- data/lib/principles/controllers/members_a_commit_changed.rb +2 -1
- data/lib/principles/controllers/members_to_assess.rb +20 -12
- data/lib/principles/controllers/repoint.rb +18 -22
- data/lib/principles/data/bounded_file.rb +9 -4
- data/lib/principles/data/command-steps.json +9 -9
- data/lib/principles/data/project_files.rb +11 -8
- data/lib/principles/data/schema_check.rb +16 -6
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +17 -3
- data/lib/principles/data/schemas/answer-guide.schema.json +5 -10
- data/lib/principles/data/schemas/audit-record.schema.json +10 -1
- data/lib/principles/data/schemas/command-steps.schema.json +2 -1
- data/lib/principles/invocation_options.rb +1 -1
- data/lib/principles/models/acknowledgement.rb +73 -84
- data/lib/principles/models/acknowledgement_refusal.rb +90 -0
- data/lib/principles/models/answer_place.rb +4 -0
- data/lib/principles/models/assessment_answer.rb +0 -45
- data/lib/principles/models/assessment_left_as_printed.rb +81 -0
- data/lib/principles/models/audit_record.rb +9 -17
- data/lib/principles/models/audit_records.rb +19 -16
- data/lib/principles/models/candidate_files.rb +30 -7
- data/lib/principles/models/candidate_inventory.rb +23 -6
- data/lib/principles/models/candidate_listing.rb +12 -3
- data/lib/principles/models/candidate_outline.rb +195 -0
- data/lib/principles/models/carried_member.rb +42 -0
- data/lib/principles/models/check_since_last_audit.rb +16 -3
- data/lib/principles/models/command_steps.rb +17 -1
- data/lib/principles/models/declared_map_changes.rb +5 -4
- data/lib/principles/models/frontmatter_fields.rb +9 -8
- data/lib/principles/models/instruction_named.rb +35 -0
- data/lib/principles/models/left_as_printed.rb +39 -0
- data/lib/principles/models/member_assessments.rb +9 -31
- data/lib/principles/models/member_file.rb +35 -11
- data/lib/principles/models/member_hashes_as_written.rb +10 -6
- data/lib/principles/models/member_lines.rb +63 -15
- data/lib/principles/models/member_problems.rb +24 -18
- data/lib/principles/models/member_repair_moves.rb +54 -0
- data/lib/principles/models/missing_files.rb +2 -2
- data/lib/principles/models/open_findings_elsewhere.rb +4 -0
- data/lib/principles/models/other_templates_placeholders.rb +81 -42
- data/lib/principles/models/outline_budget.rb +127 -0
- data/lib/principles/models/outline_group.rb +31 -0
- data/lib/principles/models/outline_section.rb +56 -0
- data/lib/principles/models/principle_members.rb +11 -0
- data/lib/principles/models/prior_decision_fields.rb +3 -2
- data/lib/principles/models/prior_finding_decision.rb +14 -4
- data/lib/principles/models/project.rb +10 -19
- data/lib/principles/models/quoted_change.rb +137 -0
- data/lib/principles/models/record_format.rb +6 -2
- data/lib/principles/models/recorded_entry.rb +6 -0
- data/lib/principles/models/recorded_hashes.rb +7 -3
- data/lib/principles/models/recorded_members.rb +27 -15
- data/lib/principles/models/refusal_before_shape.rb +21 -0
- data/lib/principles/models/repoint.rb +13 -0
- data/lib/principles/models/reported_check.rb +3 -13
- data/lib/principles/models/sent_answer.rb +51 -0
- data/lib/principles/models/shape_problems_beside.rb +40 -0
- data/lib/principles/models/submitted_answer.rb +34 -0
- data/lib/principles/models/template_placeholders.rb +34 -4
- data/lib/principles/models/text_within.rb +55 -0
- data/lib/principles/models/unchecked_members.rb +76 -0
- data/lib/principles/models/write_up_opening.rb +21 -4
- data/lib/principles/session_start_options.rb +2 -2
- data/lib/principles/start_audit_options.rb +19 -4
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +15 -7
- data/lib/principles/views/assessed_members.rb +43 -10
- data/lib/principles/views/assessment_request.rb +89 -30
- data/lib/principles/views/audit_result.rb +19 -2
- data/lib/principles/views/candidate_files_result.rb +41 -19
- data/lib/principles/views/check_notes.rb +44 -0
- data/lib/principles/views/check_result_template.rb +14 -23
- data/lib/principles/views/instruction.rb +74 -0
- data/lib/principles/views/json_with_entries_on_lines.rb +51 -0
- data/lib/principles/views/loads_to_check_result.rb +2 -2
- data/lib/principles/views/map_result.rb +2 -2
- data/lib/principles/views/member_change_since_baseline.rb +22 -5
- data/lib/principles/views/member_repairs.rb +21 -52
- data/lib/principles/views/members_a_commit_changed.rb +16 -6
- data/lib/principles/views/one_member_check_result_template.rb +43 -0
- data/lib/principles/views/open_findings_elsewhere_result.rb +3 -3
- data/lib/principles/views/open_findings_line.rb +77 -23
- data/lib/principles/views/principle_read_result.rb +20 -28
- data/lib/principles/views/prior_findings_result.rb +23 -15
- data/lib/principles/views/prompts/acknowledge-a-change/run-the-check-and-report-it-passing.md +3 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +6 -12
- data/lib/principles/views/prompts/assess-every-member/answer-guide.json +5 -10
- data/lib/principles/views/prompts/assess-every-member/assess-each-member-and-the-set.md +0 -4
- data/lib/principles/views/prompts/assess-every-member/claim-an-earlier-first-raised-at.md +7 -0
- data/lib/principles/views/prompts/assess-every-member/decide-each-prior-finding.md +4 -16
- data/lib/principles/views/prompts/assess-every-member/judge-the-set-with-carried-assessments.md +5 -10
- data/lib/principles/views/prompts/assess-every-member/keep-or-change-what-a-deferral-waits-on.md +4 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-compact-carried-member.md +8 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/review-a-new-or-changed-check-before-running-it.md +9 -0
- data/lib/principles/views/prompts/assess-every-member/say-what-observed-means.md +4 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +4 -3
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-after-the-table.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-which-principle-to-map.md +2 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/choose-one-principle.md +9 -5
- data/lib/principles/views/prompts/find-a-principle-to-map/leave-test-data-out-of-the-survey.md +1 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-a-cut-section-back.md +3 -0
- data/lib/principles/views/prompts/find-a-principle-to-map/read-left-out-files.md +3 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +21 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +4 -4
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +10 -11
- data/lib/principles/views/prompts/learn-what-a-command-does/list-principles.md +1 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +1 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +5 -5
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +24 -24
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +3 -3
- data/lib/principles/views/prompts/report-after-a-commit/the-principles-skill-is-where-to-start.md +1 -0
- data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +9 -6
- data/lib/principles/views/prompts/start-a-session/see-the-earlier-line.md +2 -0
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +3 -3
- data/lib/principles/views/request_part.rb +16 -8
- data/lib/principles/views/request_parts.rb +4 -0
- metadata +39 -5
- data/lib/principles/views/prompts/find-a-principle-to-map/ask-the-owner-before-mapping.md +0 -1
- data/lib/principles/views/prompts/report-after-a-commit/the-map-and-audit-skill-says-how-to-audit-these-members.md +0 -1
- data/lib/principles/views/prompts/set-principles-up/set-up-first.md +0 -2
|
@@ -67,17 +67,24 @@ module Principles
|
|
|
67
67
|
nil
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#: (String) ->
|
|
74
|
-
def
|
|
75
|
-
audit = find(id) or return
|
|
76
|
-
|
|
77
|
-
rescue
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
# The member hashes id's record holds, which its members are compared with: the record's own when this copy can
|
|
71
|
+
# read it, and as written when its schema refuses one a later copy wrote, marked waiting when a later copy wrote
|
|
72
|
+
# it, so the comparison is read-only (D85 V8, #1066, #1067); none when it has no record.
|
|
73
|
+
#: (String) -> RecordedHashes
|
|
74
|
+
def hashes_to_compare(id)
|
|
75
|
+
audit = find(id) or return RecordedHashes::NONE
|
|
76
|
+
RecordedHashes.new(audit.members.hashes_by_key, waiting: RecordFormat.new(audit.to_h).newer?)
|
|
77
|
+
rescue RecordFormat::NewerFormatError
|
|
78
|
+
RecordedHashes.new(member_hashes_as_written(id).by_key, waiting: true)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# id's record if this copy can read it; nil when it has none, or a later copy wrote it in a form this copy
|
|
82
|
+
# cannot read, whose audits wait on an upgrade (D85, V8).
|
|
83
|
+
#: (String) -> AuditRecord?
|
|
84
|
+
def readable(id)
|
|
85
|
+
find(id)
|
|
86
|
+
rescue RecordFormat::NewerFormatError
|
|
87
|
+
nil
|
|
81
88
|
end
|
|
82
89
|
|
|
83
90
|
# The record of each of ids that has one.
|
|
@@ -88,11 +95,7 @@ module Principles
|
|
|
88
95
|
# read across principles is not refused for that one, whose audits wait on an upgrade (D85, V8).
|
|
89
96
|
#: (Array[String]) -> Array[AuditRecord]
|
|
90
97
|
def readable_of(ids)
|
|
91
|
-
ids.filter_map
|
|
92
|
-
find(id)
|
|
93
|
-
rescue Error => e
|
|
94
|
-
raise unless e.payload.fetch("code") == "newer_audit_record"
|
|
95
|
-
end
|
|
98
|
+
ids.filter_map { readable(it) }
|
|
96
99
|
end
|
|
97
100
|
|
|
98
101
|
# id's record, refused when it has none.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative "candidate_outline"
|
|
5
|
+
|
|
4
6
|
module Principles
|
|
5
7
|
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
6
8
|
module Models
|
|
@@ -17,19 +19,33 @@ module Principles
|
|
|
17
19
|
IN_SKILL = %r{(?:\A|/)\.claude/skills/[^/]+/}
|
|
18
20
|
SKILL_ENTRY = %r{(?:\A|/)\.claude/skills/[^/]+/SKILL\.md\z}
|
|
19
21
|
|
|
20
|
-
#: (Array[Hash[String, untyped]]) -> void
|
|
21
|
-
def initialize(files)
|
|
22
|
+
#: (Array[Hash[String, untyped]], text_of: ^(String) -> String) -> void
|
|
23
|
+
def initialize(files, text_of:)
|
|
22
24
|
@files = files #: Array[Hash[String, untyped]]
|
|
25
|
+
@text_of = text_of
|
|
23
26
|
freeze
|
|
24
27
|
end
|
|
25
28
|
|
|
26
|
-
# The inventory's files, the
|
|
27
|
-
# listed file.
|
|
29
|
+
# The inventory's files, each Markdown one the survey reads with its outline, the other files counted by
|
|
30
|
+
# directory, and those test-data hints that name a listed file, whose files the survey leaves out unread (#1153).
|
|
28
31
|
#: (Array[Hash[String, untyped]]) -> Hash[String, untyped]
|
|
29
32
|
def listing(test_data_hints)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
outlines = outlines(test_data_hints)
|
|
34
|
+
files = listed.map do |file|
|
|
35
|
+
outline = outlines[file.fetch("path")]
|
|
36
|
+
outline ? file.merge(outline.to_h) : file
|
|
37
|
+
end
|
|
38
|
+
{ "files" => files,
|
|
39
|
+
"other_files_by_directory" => other_files_by_directory, "possibly_test_data" => hints(test_data_hints) }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The outline of each listed Markdown file the survey reads, by path: every one but those the test-data hints
|
|
43
|
+
# name (#1153), which the budget cuts by (#1155).
|
|
44
|
+
#: (Array[Hash[String, untyped]]) -> Hash[String, CandidateOutline]
|
|
45
|
+
def outlines(test_data_hints)
|
|
46
|
+
test_data = hints(test_data_hints).map { |hint| hint.fetch("path") }
|
|
47
|
+
paths = listed.map { |file| file.fetch("path") }.grep(MARKDOWN)
|
|
48
|
+
(paths - test_data).to_h { |path| [path, CandidateOutline.new(@text_of.call(path))] }
|
|
33
49
|
end
|
|
34
50
|
|
|
35
51
|
# Each Markdown or settings file, with its size.
|
|
@@ -49,6 +65,13 @@ module Principles
|
|
|
49
65
|
|
|
50
66
|
private
|
|
51
67
|
|
|
68
|
+
# The test-data hints that name a listed file.
|
|
69
|
+
#: (Array[Hash[String, untyped]]) -> Array[Hash[String, untyped]]
|
|
70
|
+
def hints(test_data_hints)
|
|
71
|
+
paths = listed.map { |file| file.fetch("path") }
|
|
72
|
+
test_data_hints.select { |hint| paths.include?(hint.fetch("path")) }
|
|
73
|
+
end
|
|
74
|
+
|
|
52
75
|
#: (String) -> String
|
|
53
76
|
def directory(path)
|
|
54
77
|
parent = path.rpartition("/").first
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative "candidate_listing"
|
|
5
|
+
require_relative "outline_budget"
|
|
5
6
|
require_relative "project_history"
|
|
6
7
|
|
|
7
8
|
module Principles
|
|
@@ -21,10 +22,14 @@ module Principles
|
|
|
21
22
|
|
|
22
23
|
# What the project's inventory lists, and which listed files, or files their links lead to, history says
|
|
23
24
|
# git does not track.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
# Each listed file's text, which its outline is read from, is what the block gives for its path.
|
|
26
|
+
#: (Hash[String, untyped], ProjectHistory) { (String) -> String } -> CandidateInventory
|
|
27
|
+
def self.found(inventory, history, &text_of)
|
|
28
|
+
texts = {} #: Hash[String, String]
|
|
29
|
+
listing = CandidateListing.new(inventory, text_of: ->(path) { texts[path] ||= text_of.call(path) })
|
|
30
|
+
listed = listing.to_h
|
|
31
|
+
new(listed, untracked: history.untracked(listed.fetch("files").map { it.fetch("path") }),
|
|
32
|
+
outlines: listing.outlines)
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
# The listing, as list-candidate-files prints it.
|
|
@@ -36,10 +41,12 @@ module Principles
|
|
|
36
41
|
#: Array[String]?
|
|
37
42
|
attr_reader :untracked
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
# outlines holds each outlined file's outline, by path, which within_budget cuts by.
|
|
45
|
+
#: (Hash[String, untyped], untracked: Array[String]?, ?outlines: Hash[String, CandidateOutline]) -> void
|
|
46
|
+
def initialize(listing, untracked:, outlines: {})
|
|
41
47
|
@listing = listing
|
|
42
48
|
@untracked = untracked
|
|
49
|
+
@outlines = outlines
|
|
43
50
|
@lists = listing.merge("untracked" => untracked) #: Hash[String, untyped]
|
|
44
51
|
freeze
|
|
45
52
|
end
|
|
@@ -47,6 +54,13 @@ module Principles
|
|
|
47
54
|
#: () -> Hash[String, untyped]
|
|
48
55
|
def to_h = @listing
|
|
49
56
|
|
|
57
|
+
# This inventory with its files' list items cut to OutlineBudget, the block giving the bytes each inventory tried
|
|
58
|
+
# prints as (#1155).
|
|
59
|
+
#: () { (CandidateInventory) -> Integer } -> CandidateInventory
|
|
60
|
+
def within_budget(&printed_bytes)
|
|
61
|
+
with(OutlineBudget.new(@outlines).cut(@listing) { |listing| printed_bytes.call(with(listing)) })
|
|
62
|
+
end
|
|
63
|
+
|
|
50
64
|
# Each list that names a file, in OWNER_ASK_KEYS' order, with the paths its ask names inline: all of
|
|
51
65
|
# them when there are at most NAMED_INLINE_AT_MOST, and none beyond.
|
|
52
66
|
#: () -> Hash[String, Array[String]]
|
|
@@ -59,6 +73,9 @@ module Principles
|
|
|
59
73
|
|
|
60
74
|
private
|
|
61
75
|
|
|
76
|
+
#: (Hash[String, untyped]) -> CandidateInventory
|
|
77
|
+
def with(listing) = CandidateInventory.new(listing, untracked: @untracked, outlines: @outlines)
|
|
78
|
+
|
|
62
79
|
# The path one list entry names: a file's path, a folder, or the path itself.
|
|
63
80
|
#: (untyped) -> String
|
|
64
81
|
def named(entry) = entry.is_a?(Hash) ? entry.fetch("path") { entry.fetch("folder") } : entry
|
|
@@ -11,15 +11,15 @@ module Principles
|
|
|
11
11
|
# by convention, the other files counted by directory, the listed files that look like test data, and in git
|
|
12
12
|
# the ignored ones, unread, each folder git ignores counted once.
|
|
13
13
|
class CandidateListing
|
|
14
|
-
#: (Hash[String, untyped]) -> void
|
|
15
|
-
def initialize(inventory)
|
|
14
|
+
#: (Hash[String, untyped], text_of: ^(String) -> String) -> void
|
|
15
|
+
def initialize(inventory, text_of:)
|
|
16
16
|
@inventory = inventory
|
|
17
|
+
@text_of = text_of
|
|
17
18
|
freeze
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
#: () -> Hash[String, untyped]
|
|
21
22
|
def to_h
|
|
22
|
-
files = CandidateFiles.new(@inventory.fetch("files"))
|
|
23
23
|
listed = @inventory.except("ignored", "ignored_ancestor_folders")
|
|
24
24
|
.merge(files.listing(@inventory.fetch("possibly_test_data")))
|
|
25
25
|
return listed unless @inventory.key?("ignored")
|
|
@@ -27,6 +27,15 @@ module Principles
|
|
|
27
27
|
listed.merge(IgnoredCandidates.new(paths: @inventory.fetch("ignored"),
|
|
28
28
|
folders: @inventory.fetch("ignored_ancestor_folders")).listing)
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
# The outline of each listed file the survey reads, by path.
|
|
32
|
+
#: () -> Hash[String, CandidateOutline]
|
|
33
|
+
def outlines = files.outlines(@inventory.fetch("possibly_test_data"))
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
#: () -> CandidateFiles
|
|
38
|
+
def files = CandidateFiles.new(@inventory.fetch("files"), text_of: @text_of)
|
|
30
39
|
end
|
|
31
40
|
end
|
|
32
41
|
end
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "frontmatter_fields"
|
|
6
|
+
require_relative "outline_group"
|
|
7
|
+
require_relative "outline_section"
|
|
8
|
+
require_relative "text_within"
|
|
9
|
+
|
|
10
|
+
module Principles
|
|
11
|
+
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
12
|
+
module Models
|
|
13
|
+
# One candidate file's outline, as the survey reads it in place of the file: its Markdown headings in order, and
|
|
14
|
+
# under each its top-level list items. The second alpha user scripted a heading grep over 45 files to survey them,
|
|
15
|
+
# and missed a principles section written as one numbered list, so this tool prints both (#1153).
|
|
16
|
+
class CandidateOutline
|
|
17
|
+
HEADING = /\A#+\s/
|
|
18
|
+
FENCE = /\A\s*(?:```|~~~)/
|
|
19
|
+
# A top-level list item, its marker and its text; an indented one is nested, and left out.
|
|
20
|
+
ITEM = /\A(\d+\.|[-*])\s+(.*)/
|
|
21
|
+
# A horizontal rule, such as `* * *` or `- - -`, which is no item.
|
|
22
|
+
RULE = /\A([-*_])(?:\s*\1){2,}\s*\z/
|
|
23
|
+
LINK = /\[([^\]]*)\]\([^)]*\)/
|
|
24
|
+
BOLD_LEAD = /\A\*\*[^*]+\*\*/
|
|
25
|
+
# The most characters of an item printed, cut back to a whole word.
|
|
26
|
+
ITEM_CHARACTERS = 60
|
|
27
|
+
# The most characters of the opening line printed, cut back to a sentence end, or else to a whole word. A cut
|
|
28
|
+
# mid-clause left 30 of the second alpha user's 45 opening lines a fragment (#1155). The line is short only when
|
|
29
|
+
# its first sentence is and the next runs past the cap, or an abbreviation such as "e.g." ends it early; that is
|
|
30
|
+
# accepted, since the file's path and outline still say what it holds.
|
|
31
|
+
OPENING_CHARACTERS = 160
|
|
32
|
+
# The cuts that shorten an outline to fit a budget, in the order they are made, each keeping those before it.
|
|
33
|
+
# The last leaves the whole outline out, which a big enough project needs once every other cut is made (#1155).
|
|
34
|
+
CUTS = %w[description items headings opening_line outline].freeze
|
|
35
|
+
# The cuts made on a root entry file, every one but the last, since a host loads it in every session.
|
|
36
|
+
ENTRY_FILE_CUTS = CUTS.length - 1 #: Integer
|
|
37
|
+
# The deepest heading level a cut outline keeps once its headings are folded.
|
|
38
|
+
FOLDED_BELOW = 2
|
|
39
|
+
# The most characters of a description a cut keeps, cut back to a sentence end, or else to a whole word. The
|
|
40
|
+
# second alpha user's descriptions printed 12,537 B uncut, and suggested about 300 (22645b61, #1155).
|
|
41
|
+
DESCRIPTION_CHARACTERS = 300
|
|
42
|
+
|
|
43
|
+
# A description's key and any block scalar indicator, which its text starts after.
|
|
44
|
+
DESCRIPTION_KEY = /\Adescription:\s*(?:[>|][-+]?\s)?/
|
|
45
|
+
# A value inside a matching pair of quotes, printed without them; its escapes are left as written.
|
|
46
|
+
QUOTED = /\A(["'])(.*)\1\z/
|
|
47
|
+
|
|
48
|
+
#: (String) -> void
|
|
49
|
+
def initialize(text)
|
|
50
|
+
@lines = text.lines #: Array[String]
|
|
51
|
+
@frontmatter = FrontmatterFields.new(path: "", lines: @lines) #: FrontmatterFields
|
|
52
|
+
freeze
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# The outline as the survey reads it: the whole frontmatter description and the opening line, each when the file
|
|
56
|
+
# has one, and the lines, with the first `cuts` of CUTS made.
|
|
57
|
+
#: (?cuts: Integer) -> Hash[String, untyped]
|
|
58
|
+
def to_h(cuts: 0)
|
|
59
|
+
return {} if left_out?(cuts)
|
|
60
|
+
|
|
61
|
+
{ "description" => made?("description", cuts) ? cut_description : description,
|
|
62
|
+
"opening_line" => (opening_line unless made?("opening_line", cuts) && description),
|
|
63
|
+
"outline" => outline_lines(cuts) }.compact
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Whether the first `cuts` of CUTS cut the outline's lines, rather than only its description.
|
|
67
|
+
#: (Integer) -> bool
|
|
68
|
+
def outline_cut?(cuts) = made?("items", cuts)
|
|
69
|
+
|
|
70
|
+
# Whether the first `cuts` of CUTS leave the whole outline out, the file printing its path and size alone.
|
|
71
|
+
#: (Integer) -> bool
|
|
72
|
+
def left_out?(cuts) = made?("outline", cuts)
|
|
73
|
+
|
|
74
|
+
# Each line of the outline, as Markdown, leaving out what a code fence holds.
|
|
75
|
+
#: () -> Array[String]
|
|
76
|
+
def lines = sections.flat_map(&:lines)
|
|
77
|
+
|
|
78
|
+
# The outline with its list items cut, each heading that held some followed by how many (#1155).
|
|
79
|
+
#: () -> Array[String]
|
|
80
|
+
def cut_lines = sections.flat_map(&:cut_lines)
|
|
81
|
+
|
|
82
|
+
# Each heading with the items under it, and the items before the first heading when there are any, each with
|
|
83
|
+
# the lines of the file it spans.
|
|
84
|
+
#: () -> Array[OutlineSection]
|
|
85
|
+
def sections
|
|
86
|
+
body = unfenced
|
|
87
|
+
starts = [0, *body.each_index.select { |index| body.fetch(index).match?(HEADING) }].uniq
|
|
88
|
+
starts.zip(starts.drop(1)).filter_map do |first, after|
|
|
89
|
+
section(body[first...(after || body.length)] || [], first_line: body_start + first + 1)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
# The outline's lines with the first `cuts` of CUTS made: whole, with items cut, or with third-level and deeper
|
|
96
|
+
# headings folded into the heading above, whose 11,112 B kept the second alpha user's result over budget.
|
|
97
|
+
#: (Integer) -> Array[String]
|
|
98
|
+
def outline_lines(cuts)
|
|
99
|
+
return lines unless outline_cut?(cuts)
|
|
100
|
+
return cut_lines unless made?("headings", cuts)
|
|
101
|
+
|
|
102
|
+
groups.flat_map(&:folded_lines)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Each section at FOLDED_BELOW or above, with the deeper sections after it; a file's first sections stand as a
|
|
106
|
+
# group of their own whatever their level.
|
|
107
|
+
#: () -> Array[OutlineGroup]
|
|
108
|
+
def groups
|
|
109
|
+
sections.slice_before { |section| section.level <= FOLDED_BELOW }
|
|
110
|
+
.map { |(section, *deeper)| OutlineGroup.new(section, deeper) }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Whether the first `cuts` of CUTS include the one named.
|
|
114
|
+
#: (String, Integer) -> bool
|
|
115
|
+
def made?(cut, cuts) = CUTS.take(cuts).include?(cut)
|
|
116
|
+
|
|
117
|
+
# The section these body lines hold, the first of them at first_line in the file; nil when they hold neither a
|
|
118
|
+
# heading nor an item.
|
|
119
|
+
#: (Array[String], first_line: Integer) -> OutlineSection?
|
|
120
|
+
def section(lines, first_line:)
|
|
121
|
+
heading = lines.first if lines.first&.match?(HEADING)
|
|
122
|
+
items = lines.select { |line| item?(line) }.map { |line| item(line) }
|
|
123
|
+
return nil unless heading || items.any?
|
|
124
|
+
|
|
125
|
+
OutlineSection.new(heading:, items:, first_line:, last_line: first_line + lines.length - 1)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# A top-level list item, not a horizontal rule written with the same marks.
|
|
129
|
+
#: (String) -> bool
|
|
130
|
+
def item?(line) = line.match?(ITEM) && !line.match?(RULE)
|
|
131
|
+
|
|
132
|
+
# The index in the file of the body's first line, after any frontmatter.
|
|
133
|
+
#: () -> Integer
|
|
134
|
+
def body_start = (@frontmatter.closing_line || -1) + 1
|
|
135
|
+
|
|
136
|
+
# The frontmatter's description as one line of text; nil without one, or where this tool refuses to read it.
|
|
137
|
+
#: () -> String?
|
|
138
|
+
def description
|
|
139
|
+
written = @frontmatter.field_lines("$.description") or return nil
|
|
140
|
+
text = written.map(&:strip).join(" ").sub(DESCRIPTION_KEY, "").strip
|
|
141
|
+
text[QUOTED, 2] || text
|
|
142
|
+
rescue Error
|
|
143
|
+
nil
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# The description, past DESCRIPTION_CHARACTERS cut to its last sentence end within them, saying how many more
|
|
147
|
+
# characters it holds and the lines of the file that hold it, so the agent reads just those back (#1155).
|
|
148
|
+
#: () -> String?
|
|
149
|
+
def cut_description
|
|
150
|
+
text = description or return nil
|
|
151
|
+
within = TextWithin.new(text, at_most: DESCRIPTION_CHARACTERS)
|
|
152
|
+
return text unless within.cut?
|
|
153
|
+
|
|
154
|
+
kept = within.kept
|
|
155
|
+
first, last = @frontmatter.field("$.description")
|
|
156
|
+
"#{kept} (#{text.length - kept.length} more characters, lines #{first + 1}-#{last})"
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# The first prose paragraph of the body, outside headings, lists, tables and code, its hard-wrapped lines
|
|
160
|
+
# joined, with links as their text. The first physical line was a fragment in a hard-wrapped file (#1155).
|
|
161
|
+
#: () -> String?
|
|
162
|
+
def opening_line
|
|
163
|
+
body = unfenced
|
|
164
|
+
first = body.index { |line| prose?(line) } or return nil
|
|
165
|
+
paragraph = body.drop(first).take_while { |line| prose?(line) }.map(&:strip).join(" ")
|
|
166
|
+
TextWithin.new(paragraph.gsub(LINK, '\1'), at_most: OPENING_CHARACTERS).by_sentences
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
#: (String) -> bool
|
|
170
|
+
def prose?(line)
|
|
171
|
+
text = line.strip
|
|
172
|
+
!text.empty? && !text.match?(HEADING) && !text.match?(ITEM) && !text.match?(RULE) && !text.start_with?("|")
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# The body's lines, after any frontmatter, each line of a code fence blank, so a fence ends a paragraph.
|
|
176
|
+
#: () -> Array[String]
|
|
177
|
+
def unfenced
|
|
178
|
+
fenced = false #: bool
|
|
179
|
+
body = @lines.drop(body_start).map(&:chomp)
|
|
180
|
+
body.map do |line|
|
|
181
|
+
fenced = !fenced if line.match?(FENCE)
|
|
182
|
+
fenced || line.match?(FENCE) ? "" : line
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# An item by its marker and its bold lead, or its opening words, with links as their text.
|
|
187
|
+
#: (String) -> String
|
|
188
|
+
def item(line)
|
|
189
|
+
marker, text = line.match(ITEM)&.captures
|
|
190
|
+
text = text.to_s.gsub(LINK, '\1')
|
|
191
|
+
"#{marker} #{text[BOLD_LEAD] || TextWithin.new(text, at_most: ITEM_CHARACTERS).by_words}"
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
|
+
module Models
|
|
7
|
+
# A carried member's kept assessment with the facts beside it that may mean the agent should judge it again
|
|
8
|
+
# (D49), and whether any fires, which decides whether a full audit's request prints the member whole or
|
|
9
|
+
# compactly (D93). Whether to judge it again stays the agent's.
|
|
10
|
+
class CarriedMember
|
|
11
|
+
# kept is the assessment carried forward as the request shows it, with evidence_changed;
|
|
12
|
+
# file_changed_outside_member says, in git, whether its file changed since the last full audit outside it, nil
|
|
13
|
+
# outside git; open_elsewhere, whether another principle leaves a finding open on a member sharing its lines
|
|
14
|
+
# (D62); open_here, the ids of the findings this principle leaves open on it.
|
|
15
|
+
#: (Hash[String, untyped], file_changed_outside_member: bool?, open_elsewhere: bool, open_here: Array[String])
|
|
16
|
+
#| -> void
|
|
17
|
+
def initialize(kept, file_changed_outside_member:, open_elsewhere:, open_here:)
|
|
18
|
+
@kept = kept
|
|
19
|
+
@file_changed_outside_member = file_changed_outside_member
|
|
20
|
+
@open_elsewhere = open_elsewhere
|
|
21
|
+
@open_here = open_here
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# What the request lists of the member: its carried assessment with the git fact beside it, the findings this
|
|
26
|
+
# principle leaves open on it, if any, and whether a flag fires.
|
|
27
|
+
#: () -> Hash[String, untyped]
|
|
28
|
+
def shown
|
|
29
|
+
{ "carried_forward" => @kept.merge({ "file_changed_outside_member" => @file_changed_outside_member }.compact),
|
|
30
|
+
**(@open_here.empty? ? {} : { "open_finding_ids" => @open_here }), "flagged" => fired? }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Whether any flag fires: evidence the assessment cited changed, its file changed outside it, or a finding is
|
|
34
|
+
# open on its lines elsewhere (review F1) or here.
|
|
35
|
+
#: () -> bool
|
|
36
|
+
def fired?
|
|
37
|
+
@kept.fetch("evidence_changed") == true || @file_changed_outside_member == true || @open_elsewhere ||
|
|
38
|
+
@open_here.any?
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -34,19 +34,32 @@ module Principles
|
|
|
34
34
|
# changed_in may then name a later commit than the one that set the check: the review is still asked for.
|
|
35
35
|
#: (Member, String) -> Hash[String, untyped]
|
|
36
36
|
def of(member, check)
|
|
37
|
-
|
|
37
|
+
status = status_of(member.key, check)
|
|
38
38
|
review = review_of(member.key)
|
|
39
|
-
return { "status" => "unchanged", **review } if
|
|
39
|
+
return { "status" => "unchanged", **review } if status == :unchanged
|
|
40
40
|
|
|
41
41
|
changed_in = commit_that_set(member.key, check)
|
|
42
|
-
return { "status" => "new", "changed_in" => changed_in }
|
|
42
|
+
return { "status" => "new", "changed_in" => changed_in } if %i[new not_run].include?(status)
|
|
43
43
|
|
|
44
|
+
ran = @record&.check_run_for(member.key)
|
|
44
45
|
last_run_review = review.slice("review_basis").transform_keys { "last_run_review_basis" }
|
|
45
46
|
{ "status" => "changed", "last_run" => ran, **last_run_review, "changed_in" => changed_in }
|
|
46
47
|
end
|
|
47
48
|
|
|
49
|
+
# The member's check and how it stands to the last audit's, as a request lists them beside the member; nothing
|
|
50
|
+
# for a member without a check.
|
|
51
|
+
#: (Member) -> Hash[String, untyped]
|
|
52
|
+
def entry(member)
|
|
53
|
+
check = member.check or return {}
|
|
54
|
+
{ "check" => check, "check_since_last_audit" => of(member, check) }
|
|
55
|
+
end
|
|
56
|
+
|
|
48
57
|
private
|
|
49
58
|
|
|
59
|
+
# How check stands to the one the last audit ran, as its record says; new when there is no record.
|
|
60
|
+
#: (String, String) -> Symbol
|
|
61
|
+
def status_of(key, check) = @record ? @record.members.check_since(key, check) : :new
|
|
62
|
+
|
|
50
63
|
# The line the last audit's record keeps for what the review of its run rested on, and since when (D63).
|
|
51
64
|
#: (String) -> Hash[String, untyped]
|
|
52
65
|
def review_of(key) = @record&.check_review_for(key) || {}
|
|
@@ -133,6 +133,9 @@ module Principles
|
|
|
133
133
|
# The named options it takes, without their dashes, besides --project and --help.
|
|
134
134
|
#: Array[String]
|
|
135
135
|
attr_reader :options
|
|
136
|
+
# The named options it cannot run without, which the command line refuses together with any missing argument.
|
|
137
|
+
#: Array[String]
|
|
138
|
+
attr_reader :requires
|
|
136
139
|
#: String
|
|
137
140
|
attr_reader :summary
|
|
138
141
|
#: String
|
|
@@ -146,6 +149,7 @@ module Principles
|
|
|
146
149
|
@usage = data.fetch("usage") #: String
|
|
147
150
|
@group = data.fetch("group") #: String
|
|
148
151
|
@options = data.fetch("options").freeze #: Array[String]
|
|
152
|
+
@requires = data.fetch("requires", []).freeze #: Array[String]
|
|
149
153
|
@summary = data.fetch("summary") #: String
|
|
150
154
|
@help = data.fetch("help") #: String
|
|
151
155
|
@steps = steps.freeze #: Array[Step]
|
|
@@ -162,6 +166,17 @@ module Principles
|
|
|
162
166
|
following ? [following] : []
|
|
163
167
|
end
|
|
164
168
|
|
|
169
|
+
# The first rule of its own entry the command breaks, or nil when it keeps them all.
|
|
170
|
+
#: () -> String?
|
|
171
|
+
def fault
|
|
172
|
+
ids = @steps.map(&:id)
|
|
173
|
+
return "#{@name} repeats a step id" unless ids.uniq == ids
|
|
174
|
+
|
|
175
|
+
# The command line refuses an option a command does not take, so it could never be given.
|
|
176
|
+
untaken = @requires - @options
|
|
177
|
+
"#{@name} requires #{untaken.join(", ")}, which it does not take" if untaken.any?
|
|
178
|
+
end
|
|
179
|
+
|
|
165
180
|
#: (String) -> Step
|
|
166
181
|
def find(id)
|
|
167
182
|
@steps.find { |step| step.id == id } || raise(KeyError, "#{@name} has no step #{id}")
|
|
@@ -244,8 +259,9 @@ module Principles
|
|
|
244
259
|
#: (Command, Array[String]) -> void
|
|
245
260
|
def check_command(command, names)
|
|
246
261
|
writes(command)
|
|
262
|
+
fault = command.fault
|
|
263
|
+
refuse(fault) if fault
|
|
247
264
|
ids = command.steps.map(&:id)
|
|
248
|
-
refuse("#{command.name} repeats a step id") unless ids.uniq == ids
|
|
249
265
|
command.steps.each { |step| check_step("#{command.name}/#{step.id}", step, names, ids) }
|
|
250
266
|
end
|
|
251
267
|
|
|
@@ -79,11 +79,11 @@ module Principles
|
|
|
79
79
|
@entries.map { |id| changed_fields(id, moved.member(id), current.member(id)) }
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
# The map file, when
|
|
83
|
-
# agent commits it too (T69).
|
|
82
|
+
# The map file, when the correction moved a member in it, even under its own id (#1100), a fix changed a
|
|
83
|
+
# member's role or check in it, or the correction added members to it, so the agent commits it too (T69).
|
|
84
84
|
#: (String, ?added: Array[String]) -> Array[String]
|
|
85
85
|
def files_to_commit(map_file, added: [])
|
|
86
|
-
|
|
86
|
+
empty? && added.empty? ? [] : [map_file]
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
private
|
|
@@ -146,7 +146,8 @@ module Principles
|
|
|
146
146
|
def stale_map(principle_id, map_file)
|
|
147
147
|
Error.new("stale_map", "The map of #{principle_id} changed during this audit",
|
|
148
148
|
"If you moved a member to fix a finding, declare it in the answer's moved_members as " \
|
|
149
|
-
"{\"from\": OLD_ID, \"to\": NEW_ID}
|
|
149
|
+
"{\"from\": OLD_ID, \"to\": NEW_ID}, and a move that kept its id, as narrowing or widening a " \
|
|
150
|
+
"passage, as {\"from\": ID, \"to\": ID}; if a fix changed a member's role or check, list the " \
|
|
150
151
|
"member's id in that fixed disposition's changed_map_entries. In git, a member you added with " \
|
|
151
152
|
"add-member needs no declaration, as long as nothing else changed.\n" \
|
|
152
153
|
"Otherwise, start a fresh audit: #{Error::EXECUTABLE} start-audit #{principle_id}", map_file)
|
|
@@ -59,6 +59,15 @@ module Principles
|
|
|
59
59
|
raise unless e.payload.fetch("code") == "field_not_found"
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
# The index of the --- that closes the frontmatter, or nil when the text opens with none; the
|
|
63
|
+
# file's body starts after it.
|
|
64
|
+
#: () -> Integer?
|
|
65
|
+
def closing_line
|
|
66
|
+
return nil unless @lines.first&.chomp == "---"
|
|
67
|
+
|
|
68
|
+
(1...@lines.length).find { |i| @lines.fetch(i).chomp == "---" }
|
|
69
|
+
end
|
|
70
|
+
|
|
62
71
|
private
|
|
63
72
|
|
|
64
73
|
# Each top-level field's name and line range, in order; refused on a line this tool would misread.
|
|
@@ -71,14 +80,6 @@ module Principles
|
|
|
71
80
|
end
|
|
72
81
|
end
|
|
73
82
|
|
|
74
|
-
# The index of the --- that closes the frontmatter, or nil when the text opens with none.
|
|
75
|
-
#: () -> Integer?
|
|
76
|
-
def closing_line
|
|
77
|
-
return nil unless @lines.first&.chomp == "---"
|
|
78
|
-
|
|
79
|
-
(1...@lines.length).find { |i| @lines.fetch(i).chomp == "---" }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
83
|
# The last line from start to last that is not blank, so trailing blank lines stay out of a field.
|
|
83
84
|
#: (Integer, Integer) -> Integer
|
|
84
85
|
def last_filled(start, last)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../prose_list"
|
|
6
|
+
|
|
7
|
+
module Principles
|
|
8
|
+
# The domain of principles and their maps: each model owns its rules and loads and saves itself through data/.
|
|
9
|
+
module Models
|
|
10
|
+
# The instruction field start-audit --instruction names, read whole from the request a full audit asks (D81 step
|
|
11
|
+
# 2, #983). Only a field the request prints an instruction under can be read: the others explain fields it does
|
|
12
|
+
# not hold.
|
|
13
|
+
class InstructionNamed
|
|
14
|
+
#: (String, principle_id: String, printed: Array[String]) -> void
|
|
15
|
+
def initialize(field, principle_id:, printed:)
|
|
16
|
+
@field = field
|
|
17
|
+
@id = principle_id
|
|
18
|
+
@printed = printed
|
|
19
|
+
freeze
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# The field, refused unless the request prints an instruction under it.
|
|
23
|
+
#: () -> String
|
|
24
|
+
def field
|
|
25
|
+
return @field if @printed.include?(@field)
|
|
26
|
+
|
|
27
|
+
refusal = Error.new("unknown_instruction",
|
|
28
|
+
"This request prints no instruction named #{@field}. It prints #{ProseList.new(@printed)}.",
|
|
29
|
+
"")
|
|
30
|
+
raise refusal.ending_with([Error::RepairCommand.new(purpose: "To print one whole", command: "start-audit",
|
|
31
|
+
values: [@id], usage: "--instruction FIELD")])
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|