principles 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/exe/principles +1 -1
  4. data/lib/principles/cli.rb +9 -10
  5. data/lib/principles/command_routes.rb +7 -1
  6. data/lib/principles/controllers/carrier_edit_report.rb +40 -0
  7. data/lib/principles/controllers/command.rb +7 -3
  8. data/lib/principles/controllers/context_budget.rb +61 -0
  9. data/lib/principles/controllers/inventory.rb +3 -2
  10. data/lib/principles/controllers/member_addition.rb +1 -1
  11. data/lib/principles/controllers/member_entries.rb +30 -38
  12. data/lib/principles/controllers/member_entry_changes.rb +71 -0
  13. data/lib/principles/controllers/member_problems_report.rb +1 -1
  14. data/lib/principles/controllers/members_in_logged_requests.rb +5 -5
  15. data/lib/principles/controllers/members_to_assess.rb +11 -1
  16. data/lib/principles/controllers/meta_principle_setup.rb +10 -2
  17. data/lib/principles/controllers/parts_to_read.rb +2 -1
  18. data/lib/principles/controllers/plugin_member_addition.rb +4 -4
  19. data/lib/principles/controllers/request_logging.rb +17 -4
  20. data/lib/principles/controllers/running_tool.rb +19 -5
  21. data/lib/principles/controllers/session_start_report.rb +26 -2
  22. data/lib/principles/data/captured_requests.rb +118 -0
  23. data/lib/principles/data/carrier_page_markers.rb +38 -0
  24. data/lib/principles/data/claude_code_home.rb +17 -0
  25. data/lib/principles/data/command-steps.json +59 -19
  26. data/lib/principles/data/kept_line.rb +14 -7
  27. data/lib/principles/data/logged_request_matches.rb +23 -17
  28. data/lib/principles/data/logged_request_scan.rb +79 -11
  29. data/lib/principles/data/map_files.rb +1 -1
  30. data/lib/principles/data/project_files.rb +15 -0
  31. data/lib/principles/data/request_logging_folder.rb +42 -74
  32. data/lib/principles/data/request_shape.rb +33 -0
  33. data/lib/principles/data/running_version.rb +1 -1
  34. data/lib/principles/data/schemas/command-steps.schema.json +1 -1
  35. data/lib/principles/data/schemas/member-map.schema.json +2 -0
  36. data/lib/principles/data/settings_env_keys.rb +26 -0
  37. data/lib/principles/data/user_request_logging_folder.rb +73 -0
  38. data/lib/principles/invocation_options.rb +4 -4
  39. data/lib/principles/launch.rb +15 -6
  40. data/lib/principles/models/captured_sessions.rb +53 -15
  41. data/lib/principles/models/carrier_edit_input.rb +56 -0
  42. data/lib/principles/models/carrier_pages_shown.rb +28 -0
  43. data/lib/principles/models/carved_message_bytes.rb +115 -0
  44. data/lib/principles/models/context_parts.rb +59 -0
  45. data/lib/principles/models/declared_map_changes.rb +22 -13
  46. data/lib/principles/models/dropped_thinking.rb +73 -0
  47. data/lib/principles/models/feature.rb +2 -1
  48. data/lib/principles/models/installed_component.rb +3 -3
  49. data/lib/principles/models/logged_request_reach.rb +19 -11
  50. data/lib/principles/models/map_format_raise.rb +28 -0
  51. data/lib/principles/models/mapped_principles.rb +2 -1
  52. data/lib/principles/models/member.rb +6 -1
  53. data/lib/principles/models/member_justification.rb +52 -0
  54. data/lib/principles/models/member_problems.rb +2 -1
  55. data/lib/principles/models/member_reach.rb +28 -5
  56. data/lib/principles/models/member_snapshots.rb +11 -0
  57. data/lib/principles/models/members_by_part.rb +67 -0
  58. data/lib/principles/models/members_in_logged_requests.rb +56 -17
  59. data/lib/principles/models/meta_principle.rb +4 -4
  60. data/lib/principles/models/part_token_estimates.rb +60 -0
  61. data/lib/principles/models/plugin_enabled_in_project_settings.rb +61 -0
  62. data/lib/principles/models/principle.rb +7 -4
  63. data/lib/principles/models/principle_members.rb +7 -0
  64. data/lib/principles/models/project.rb +20 -31
  65. data/lib/principles/models/project_harness.rb +48 -0
  66. data/lib/principles/models/report_hooks.rb +9 -4
  67. data/lib/principles/models/request_channel.rb +62 -0
  68. data/lib/principles/models/request_kind.rb +62 -0
  69. data/lib/principles/models/request_logging.rb +107 -72
  70. data/lib/principles/models/request_logging_guard.rb +84 -0
  71. data/lib/principles/models/request_time.rb +46 -0
  72. data/lib/principles/models/session_registry.rb +61 -0
  73. data/lib/principles/models/session_start_input.rb +11 -2
  74. data/lib/principles/models/session_trend.rb +36 -0
  75. data/lib/principles/models/turn_opening.rb +83 -0
  76. data/lib/principles/models/turn_position.rb +43 -0
  77. data/lib/principles/models/user_logged_requests.rb +90 -0
  78. data/lib/principles/models/user_settings_entries.rb +49 -0
  79. data/lib/principles/version.rb +2 -2
  80. data/lib/principles/views/assessed_members.rb +4 -4
  81. data/lib/principles/views/assessment_request.rb +6 -3
  82. data/lib/principles/views/audit_result.rb +13 -6
  83. data/lib/principles/views/candidate_files_result.rb +1 -1
  84. data/lib/principles/views/carrier_edit_denial.rb +36 -0
  85. data/lib/principles/views/context_budget_result.rb +99 -0
  86. data/lib/principles/views/correction_request.rb +11 -1
  87. data/lib/principles/views/hook_setup_result.rb +3 -1
  88. data/lib/principles/views/logged_requests_evidence.rb +18 -3
  89. data/lib/principles/views/map_format_raised.rb +28 -0
  90. data/lib/principles/views/map_result.rb +7 -6
  91. data/lib/principles/views/maps_needing_members_or_audit.rb +1 -1
  92. data/lib/principles/views/members_in_logged_requests_result.rb +75 -20
  93. data/lib/principles/views/meta_principle_result.rb +38 -13
  94. data/lib/principles/views/problem_lines.rb +22 -0
  95. data/lib/principles/views/prompts/assess-every-member/ask-whether-a-member-seen-only-as-read-is-loaded.md +3 -0
  96. data/lib/principles/views/prompts/assess-every-member/ask-whether-each-reason-holds.md +2 -0
  97. data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-against-the-other-principles.md +2 -0
  98. data/lib/principles/views/prompts/assess-every-member/weigh-what-reached-the-context.md +2 -2
  99. data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
  100. data/lib/principles/views/prompts/dispose-of-each-finding/fix-or-record-each-finding.md +1 -1
  101. data/lib/principles/views/prompts/dispose-of-each-finding/read-the-carrier-page-before-fixing.md +1 -0
  102. data/lib/principles/views/prompts/edit-a-carrier/read-the-page-before-the-first-edit.md +2 -0
  103. data/lib/principles/views/prompts/learn-what-a-command-does/add-member.md +19 -20
  104. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-name.md +12 -0
  105. data/lib/principles/views/prompts/learn-what-a-command-does/change-member-reason.md +12 -0
  106. data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -1
  107. data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +4 -4
  108. data/lib/principles/views/prompts/learn-what-a-command-does/remove-logged-requests.md +7 -1
  109. data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +7 -3
  110. data/lib/principles/views/prompts/learn-what-a-command-does/report-before-carrier-edit.md +13 -0
  111. data/lib/principles/views/prompts/learn-what-a-command-does/show-context-budget.md +69 -0
  112. data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +4 -4
  113. data/lib/principles/views/prompts/learn-what-a-command-does/show-logged-requests.md +4 -2
  114. data/lib/principles/views/prompts/learn-what-a-command-does/show-members-in-logged-requests.md +21 -7
  115. data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +13 -10
  116. data/lib/principles/views/prompts/learn-what-a-command-does/show-principle.md +5 -5
  117. data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +7 -7
  118. data/lib/principles/views/prompts/learn-what-a-command-does/turn-off-request-logging.md +8 -0
  119. data/lib/principles/views/prompts/learn-what-a-command-does/turn-on-request-logging.md +12 -0
  120. data/lib/principles/views/prompts/read-what-reached-the-context/explain-user-request-logging-to-the-user.md +10 -0
  121. data/lib/principles/views/prompts/read-what-reached-the-context/what-a-thread-continuation-holds.md +3 -0
  122. data/lib/principles/views/prompts/read-what-reached-the-context/what-each-context-budget-line-says.md +4 -0
  123. data/lib/principles/views/prompts/read-what-reached-the-context/what-each-member-line-says.md +2 -0
  124. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-audit-asks-to-acknowledge-or-audit-again.md +1 -0
  125. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-mapping-commit-asks-for-an-audit.md +1 -0
  126. data/lib/principles/views/prompts/report-after-a-commit/a-row-ending-pinned-asks-for-an-audit.md +1 -0
  127. data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +1 -0
  128. data/lib/principles/views/prompts/set-principles-up/ask-to-set-principles-up-after-an-audit.md +1 -0
  129. data/lib/principles/views/prompts/set-principles-up/entry-file-passage.md +1 -1
  130. data/lib/principles/views/prompts/set-principles-up/map-the-enabling-line-at-no-edit.md +3 -0
  131. data/lib/principles/views/prompts/set-principles-up/name-the-step-each-member-lacks.md +2 -2
  132. data/lib/principles/views/prompts/set-principles-up/place-the-passage-with-the-user.md +4 -2
  133. data/lib/principles/views/prompts/set-principles-up/what-the-passage-presumes.md +1 -1
  134. data/lib/principles/views/prompts/set-principles-up/why-set-principles-up.md +1 -0
  135. data/lib/principles/views/prompts/start-a-session/ask-to-set-principles-up.md +2 -0
  136. data/lib/principles/views/prompts/start-a-session/name-the-principles-nothing-checks.md +1 -0
  137. data/lib/principles/views/request_logging_result.rb +48 -2
  138. data/lib/principles/views/set_up_offer_line.rb +43 -0
  139. metadata +55 -3
  140. data/lib/principles/views/prompts/set-principles-up/keep-them-held-between-audits.md +0 -2
@@ -0,0 +1,99 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "problem_lines"
5
+ require_relative "prompts"
6
+
7
+ module Principles
8
+ # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
9
+ module Views
10
+ # Each session's turn openings, each with its context's bytes and the host's count of its input tokens, its
11
+ # trend, and the files the read wrote: none; or, with --short, a line a session.
12
+ class ContextBudgetResult
13
+ # How many principles a --short line names by their members' bytes, the largest first.
14
+ LARGEST = 3 #: Integer
15
+
16
+ # Each session as plain values: its id, its trend, its last turn opening with the members it sent, the members
17
+ # its turn openings sent all told, and, under --session, each turn opening.
18
+ #: type session = [String?, Hash[String, untyped], Hash[String, untyped], Array[Hash[String, untyped]],
19
+ #| Array[Hash[String, untyped]]?]
20
+
21
+ # The bare command's form, bounded by sessions rather than turns, or with the session's turn openings listed.
22
+ #: (Array[session]) -> Hash[String, untyped]
23
+ def result(sessions)
24
+ listed = sessions.map do |id, trend, last, members, openings|
25
+ { "session_id" => id, "trend" => trend, "last_turn_opening" => last,
26
+ "members_across_turn_openings" => members,
27
+ **({ "turn_openings" => openings } if openings) }
28
+ end
29
+ { "status" => "context_budget_shown", "sessions" => listed, "wrote" => [] }
30
+ end
31
+
32
+ # The same facts as a line a session, with a line first saying what each line holds.
33
+ #: (Array[session]) -> Lines
34
+ def short(sessions)
35
+ lines = [Prompts.text("read-what-reached-the-context/what-each-context-budget-line-says"),
36
+ *sessions.map { |id, trend, last, _, _| session_line(id, trend, last) }]
37
+ Lines.new(stdout: lines.map { "#{it}\n" }.join, stderr: "", status: 0)
38
+ end
39
+
40
+ private
41
+
42
+ #: (String?, Hash[String, untyped], Hash[String, untyped]) -> String
43
+ def session_line(id, trend, last)
44
+ count = trend.fetch("turn_openings")
45
+ openings = "#{count} turn opening#{"s" unless count == 1}"
46
+ members = "members by principle: #{by_principle(last.fetch("members"))}"
47
+ return "#{unindexed(openings)}; one of them by part: #{by_part(last)}; #{members}" unless id
48
+
49
+ "#{id}: #{openings}, #{trend.fetch("from")} to #{trend.fetch("to")}; " \
50
+ "bytes #{moved(trend.fetch("bytes"))}; input tokens #{moved(trend.fetch("input_tokens"))}; " \
51
+ "last by part: #{by_part(last)}; #{members}"
52
+ end
53
+
54
+ # The turn openings no index line names: with no index line they have no session, send time or response, so
55
+ # no order or tokens. "no session" holds a space, which no session id does, so it is never taken for one.
56
+ #: (String) -> String
57
+ def unindexed(openings)
58
+ "no session: #{openings} that no index line names, so with no send time, order or input tokens"
59
+ end
60
+
61
+ # A count's first and last, and its change, signed.
62
+ #: (Hash[String, Integer?]) -> String
63
+ def moved(counts)
64
+ change = counts["change"]
65
+ signed = change&.positive? ? "+#{change}" : shown(change)
66
+ "#{shown(counts["first"])} -> #{shown(counts["last"])} (#{signed})"
67
+ end
68
+
69
+ # opening's bytes by part, a part's kinds together, in the order its parts are listed.
70
+ #: (Hash[String, untyped]) -> String
71
+ def by_part(opening)
72
+ parts = opening.fetch("parts").group_by { it.fetch("part") }
73
+ parts.map { |part, kinds| "#{part} #{kinds.sum { it.fetch("bytes") }}" }.join(", ")
74
+ end
75
+
76
+ # The bytes of mapped members' text sent, by principle, the largest first, and how many more.
77
+ #: (Array[Hash[String, untyped]]) -> String
78
+ def by_principle(members)
79
+ totals = principle_totals(members)
80
+ return "none" if totals.empty?
81
+
82
+ named = totals.first(LARGEST)
83
+ more = totals.size - named.size
84
+ [*named.map { |principle, bytes| "#{principle} #{bytes}" }, *("#{more} more" if more.positive?)].join(", ")
85
+ end
86
+
87
+ # Each principle among members, with their bytes, the largest first and a tie by id.
88
+ #: (Array[Hash[String, untyped]]) -> Array[[String, Integer]]
89
+ def principle_totals(members)
90
+ totals = members.group_by { it.fetch("principle") }
91
+ .map { |principle, parts| [principle, parts.sum { it.fetch("bytes") }] }
92
+ totals.sort_by { |principle, bytes| [-bytes, principle] }
93
+ end
94
+
95
+ #: (untyped) -> String
96
+ def shown(value) = value.nil? ? "null" : value.to_s
97
+ end
98
+ end
99
+ end
@@ -38,10 +38,20 @@ module Principles
38
38
  def context
39
39
  { "principle_id" => @principle_id, "findings" => @findings,
40
40
  **({ "carrier_checks" => @carrier_checks } unless @carrier_checks.empty?),
41
- "question" => Prompts.text("dispose-of-each-finding/fix-or-record-each-finding"),
41
+ "question" => question,
42
42
  "answer_guide" => self.class.answer_guide(@disposition.reason) }
43
43
  end
44
44
 
45
+ # What the correction asks, and, when it carries carrier checks, to read a kind's page before fixing a member
46
+ # there, since a page command printed beside the members was skipped (019 F4).
47
+ #: () -> String
48
+ def question
49
+ fix = Prompts.text("dispose-of-each-finding/fix-or-record-each-finding")
50
+ return fix if @carrier_checks.empty?
51
+
52
+ "#{fix}\n#{Prompts.text("dispose-of-each-finding/read-the-carrier-page-before-fixing")}"
53
+ end
54
+
45
55
  # The guide to every disposition's shape, whose deferred sample's reason is reason_placeholder, the template's,
46
56
  # its slot filled for no one finding, as the guide speaks of any.
47
57
  #: (String) -> Hash[String, untyped]
@@ -76,9 +76,11 @@ module Principles
76
76
 
77
77
  # command, followed by the echo that runs when it exits other than 0, which it never does once started: plain
78
78
  # text at session start, and after a call the hook's JSON, since the agent never reads such a hook's plain
79
- # stdout.
79
+ # stdout. Before an edit it says nothing and lets the edit through, since the other hooks already say so.
80
80
  #: (String, String) -> String
81
81
  def guarded(event, command)
82
+ return "#{EXECUTABLE} #{command} || true" if event == "PreToolUse"
83
+
82
84
  said = if event == "SessionStart"
83
85
  FAILED
84
86
  else
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "invocation"
5
5
  require_relative "logged_request_status_meanings"
6
+ require_relative "members_in_logged_requests_result"
6
7
  require_relative "prompts"
7
8
  require_relative "request_part"
8
9
 
@@ -32,17 +33,31 @@ module Principles
32
33
  end
33
34
 
34
35
  # The request's part saying how far each judged member's text reached the captured requests, as reach gives it,
35
- # with the command that shows where in the requests one member was seen, its key as KEY, what each status
36
- # means, and the question that asks the agent to weigh it.
36
+ # with how its model turns' positions were told and what a continuation holds, the command that shows where in
37
+ # the requests one member was seen, its key as KEY, what each status means, and the question that asks the agent
38
+ # to weigh it.
37
39
  #: (Hash[String, untyped]) -> RequestPart
38
40
  def reached(reach)
39
41
  detail = @invocation.in_project("show-members-in-logged-requests", options: ["--member", "KEY"])
40
42
  weigh = Prompts.text("assess-every-member/weigh-what-reached-the-context")
41
- shown = reach.merge("detail_with" => detail, "status_meanings" => LoggedRequestStatusMeanings.new.to_h,
43
+ shown = reach.merge(asked_about(reach.fetch("seen_only_as_read", [])))
44
+ shown = shown.merge("position_heuristic" => MembersInLoggedRequestsResult::POSITION_HEURISTIC,
45
+ "what_a_continuation_holds" => MembersInLoggedRequestsResult.what_a_continuation_holds,
46
+ "detail_with" => detail, "status_meanings" => LoggedRequestStatusMeanings.new.to_h,
42
47
  "weigh" => weigh)
43
48
  RequestPart.new(shown: { PART => shown }, slots: {})
44
49
  end
45
50
 
51
+ # The member keys in read, each seen only where the agent read, sent or quoted it, under the one question whether
52
+ # the host loads them; nothing while there is none.
53
+ #: (Array[String]) -> Hash[String, untyped]
54
+ def asked_about(read)
55
+ return {} if read.empty?
56
+
57
+ question = Prompts.text("assess-every-member/ask-whether-a-member-seen-only-as-read-is-loaded")
58
+ { "seen_only_as_read" => { "members" => read, "question" => question } }
59
+ end
60
+
46
61
  # The request's part, by its name alone, for a read of the request that prints none of it, so the captured
47
62
  # requests go unscanned, with why the index gives no bytes for it; it adds no slot to the answer.
48
63
  #: () -> RequestPart
@@ -0,0 +1,28 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Principles
5
+ module Views
6
+ # One line, where a map write raised its map from one format to another that releases of principles before
7
+ # release cannot read, so the agent knows before committing it that those copies will refuse it.
8
+ # A write leaving the format as it was, or raising it to one every release reads, prints nothing.
9
+ class MapFormatRaised
10
+ #: (String, from: Integer, to: Integer, release: String?) -> void
11
+ def initialize(id, from:, to:, release:)
12
+ @id = id
13
+ @from = from
14
+ @to = to
15
+ @release = release
16
+ freeze
17
+ end
18
+
19
+ #: () -> Hash[String, String]
20
+ def to_h
21
+ return {} unless @release
22
+
23
+ { "format_raised" => "This raised #{@id}'s map from format #{@from} to #{@to}; principles before " \
24
+ "#{@release} can no longer read it." }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -20,7 +20,7 @@ module Principles
20
20
  # The placeholders each printed command leaves for the agent to fill.
21
21
  ADD_MEMBER_USAGE = "PATH [--section \"Exact heading text\"] [--starting-at \"text that occurs once\" " \
22
22
  "[--ending-at \"text occurring once after the opening\"]] [--query '$.description'] " \
23
- "--role \"The part it plays\""
23
+ "--role \"The part it plays\" --name NAME --reason REASON"
24
24
 
25
25
  CREATED = "Which files or Markdown sections reinforce this principle? Add each one with the part it plays, " \
26
26
  "for example: states the principle, lists the checks, records settled terms, reminds on a timer, " \
@@ -145,11 +145,12 @@ module Principles
145
145
  start_audit(principle.id), shown: shown)
146
146
  end
147
147
 
148
- # change-member-role: the member's id and its new role, the one part that changed, never the whole map, which
149
- # cost 7.9 KB on a 17-member principle.
150
- #: (PrintedPrinciple, member: String, role: String) -> Hash[String, untyped]
151
- def role_changed(principle, member:, role:)
152
- member_replaced(principle, done: "Changed its role.", shown: { "member" => { "id" => member, "role" => role } })
148
+ # change-member-role, -name or -reason: the member's id, which commands still take, and the field it
149
+ # changed, the one part that changed, never the whole map, which cost 7.9 KB on a 17-member principle.
150
+ #: (PrintedPrinciple, member: String, field: String, value: String) -> Hash[String, untyped]
151
+ def entry_changed(principle, member:, field:, value:)
152
+ member_replaced(principle, done: "Changed its #{field}.",
153
+ shown: { "member" => { "id" => member, field => value } })
153
154
  end
154
155
 
155
156
  # remove-member: the id removed and how many members are left, never the whole map left, which cost 7.9 KB on
@@ -34,7 +34,7 @@ module Principles
34
34
  #: (String) -> String
35
35
  def empty_map(id)
36
36
  "#{id} has no members. Add its first member: " \
37
- "#{@invocation.in_project("add-member", id, usage: "PATH --role ROLE")}"
37
+ "#{@invocation.in_project("add-member", id, usage: "PATH --role ROLE --name NAME --reason REASON")}"
38
38
  end
39
39
 
40
40
  #: (String) -> String
@@ -3,6 +3,8 @@
3
3
 
4
4
  require_relative "logged_request_status_meanings"
5
5
  require_relative "problem_lines"
6
+ require_relative "prompts"
7
+ require_relative "../prose_list"
6
8
 
7
9
  module Principles
8
10
  # What this tool prints, from plain values a controller hands it. views/CLAUDE.md owns the boundary.
@@ -12,51 +14,104 @@ module Principles
12
14
  # query_source, which requests quote a logged request's path, which the scan could not read through, how complete
13
15
  # the scan was, and the files the scan wrote: none.
14
16
  class MembersInLoggedRequestsResult
15
- # The result from seen, the scan's report, as the request logging gives it.
16
- #: ({ members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
17
- #| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
18
- #| completeness: Hash[String, untyped] }) -> Hash[String, untyped]
19
- def result(seen)
17
+ # The scan's report this prints, as plain values.
18
+ #: type seen = { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]],
19
+ #| orphans: Integer, quoting_requests: Array[String], requests_by_kind: Hash[String, Integer],
20
+ #| model_turns_by_position: Hash[String, Integer],
21
+ #| model_turns_by_query_source: Hash[String, Hash[String, Integer]],
22
+ #| unreadable: Array[Hash[String, String]], completeness: Hash[String, untyped] }
23
+
24
+ # How each model turn's position was told, since the host does not say.
25
+ POSITION_HEURISTIC = "Not said by the host: a model turn that continues a thread is mid_turn; any other is " \
26
+ "told by how its last message ends: turn_opening is user or system text with no tool " \
27
+ "result, mid_turn ends with a tool result, and unclassified is neither, so outside a " \
28
+ "thread, text the host adds mid-turn reads as turn_opening." #: String
29
+
30
+ # What a request continuing a thread holds, so the agent reads a member's presence there as text added then.
31
+ #: () -> String
32
+ def self.what_a_continuation_holds
33
+ Prompts.text("read-what-reached-the-context/what-a-thread-continuation-holds")
34
+ end
35
+
36
+ # The result from seen, the scan's report, as the request logging gives it, saying how a request's kind was
37
+ # told from side_call_sources, the query_sources whose requests that continue no thread are side calls.
38
+ #: (seen, side_call_sources: Array[String]) -> Hash[String, untyped]
39
+ def result(seen, side_call_sources:)
20
40
  { "members_by_status" => seen[:members_by_status], "status_meanings" => LoggedRequestStatusMeanings.new.to_h,
21
41
  "members" => seen[:members], "orphans" => seen[:orphans],
42
+ "requests_by_kind" => seen[:requests_by_kind],
43
+ "kind_heuristic" => kind_heuristic(side_call_sources),
44
+ "model_turns_by_position" => seen[:model_turns_by_position],
45
+ "model_turns_by_query_source" => seen[:model_turns_by_query_source],
46
+ "position_heuristic" => POSITION_HEURISTIC,
47
+ "what_a_continuation_holds" => self.class.what_a_continuation_holds,
22
48
  "quoting_requests" => seen[:quoting_requests], "unreadable" => seen[:unreadable],
23
49
  "completeness" => seen[:completeness], "wrote" => [] }
24
50
  end
25
51
 
26
52
  # --short: the count of members with each status, with how many requests the scan read, whether it read every
27
53
  # one through, since an absence holds only then, how many it could not read, and how many quote a logged
28
- # request, where a presence may be a quote; then one tab-separated line a member: its status, principle, member
29
- # key, with its id where it is now once moved, and the segments it was seen in, or - for none.
30
- #: ({ members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
31
- #| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
32
- #| completeness: Hash[String, untyped] }) -> Lines
54
+ # request, where a presence may be a quote; then what a continuation holds; then what each member line says; then
55
+ # one tab-separated line a member: its status, principle, member key, with its id where it is now once moved, the
56
+ # segments it was seen in, and its requests by channel, each or - for none.
57
+ #: (seen) -> Lines
33
58
  def short(seen)
34
- lines = [counts(seen), *seen[:members].map { member_line(it) }]
59
+ legend = Prompts.text("read-what-reached-the-context/what-each-member-line-says")
60
+ lines = [counts(seen), self.class.what_a_continuation_holds, legend, *seen[:members].map { member_line(it) }]
35
61
  Lines.new(stdout: lines.map { "#{it}\n" }.join, stderr: "", status: 0)
36
62
  end
37
63
 
38
64
  private
39
65
 
40
- # The counts by status, then what the scan read, as short prints it.
41
- #: ({ members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
42
- #| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
43
- #| completeness: Hash[String, untyped] }) -> String
66
+ # How each request's kind was told, since the host does not say either, with side_call_sources, the
67
+ # query_sources whose requests that continue no thread are side calls, by name.
68
+ #: (Array[String]) -> String
69
+ def kind_heuristic(side_call_sources)
70
+ "Not said by the host: a request that continues a thread, naming the message before it, is a model_turn. " \
71
+ "A request under #{ProseList.new(side_call_sources)} that does not continue a thread is a side_call, a " \
72
+ "label-based exception from one log, observed 2026-11-28, so such a request from a side-call source not " \
73
+ "listed counts as a model turn. Any other request is told by its shape: model_turn lists " \
74
+ "tools, side_call lists none and holds one or two messages, and unclassified is neither."
75
+ end
76
+
77
+ # The counts by status, then what the scan read, then the requests by kind and the model turns by position, as
78
+ # short prints it.
79
+ #: (seen) -> String
44
80
  def counts(seen)
45
81
  completeness = seen[:completeness]
46
82
  whole = completeness.fetch("complete") ? "complete" : "not complete"
47
83
  read = "#{completeness.fetch("captured")} captured, #{whole}, #{seen[:unreadable].size} unreadable, " \
48
84
  "#{seen[:quoting_requests].size} quoting a logged request"
49
- "#{seen[:members_by_status].map { |status, count| "#{status} #{count}" }.join(", ")}; #{read}"
85
+ "#{counted(seen[:members_by_status])}; #{read}; requests by kind: #{counted(seen[:requests_by_kind])}; " \
86
+ "model turns by position: #{counted(seen[:model_turns_by_position])}; " \
87
+ "model turns by query_source (turn_opening/mid_turn/unclassified): #{by_source(seen)}"
88
+ end
89
+
90
+ # Each query_source's model turns at each position, as source opening/mid/unclassified, joined by commas, or -
91
+ # for none; each source's counts come in that order, as the report gives every position.
92
+ #: (seen) -> String
93
+ def by_source(seen)
94
+ sources = seen[:model_turns_by_query_source].map { |source, counts| "#{source} #{counts.values.join("/")}" }
95
+ listed(sources)
50
96
  end
51
97
 
52
- # One member's line: status, principle, member key, with its id where it is now once moved, and the distinct
53
- # segments it was seen in.
98
+ # Each of counts as its name and count, joined by commas.
99
+ #: (Hash[String, Integer]) -> String
100
+ def counted(counts) = counts.map { |name, count| "#{name} #{count}" }.join(", ")
101
+
102
+ # One member's line: status, principle, member key, with its id where it is now once moved, the distinct
103
+ # segments it was seen in, and how many requests held it by each channel, as channel:count.
54
104
  #: (Hash[String, untyped]) -> String
55
105
  def member_line(member)
56
- segments = member.fetch("segments")
57
- [*member.values_at("status", "principle"), named(member), segments.empty? ? "-" : segments.join(",")].join("\t")
106
+ channels = member.fetch("channels").map { |channel, count| "#{channel}:#{count}" }
107
+ [*member.values_at("status", "principle"), named(member), listed(member.fetch("segments")), listed(channels)]
108
+ .join("\t")
58
109
  end
59
110
 
111
+ # items joined by commas, or - for none.
112
+ #: (Array[String]) -> String
113
+ def listed(items) = items.empty? ? "-" : items.join(",")
114
+
60
115
  # member's key, followed by its id once a move has left the key naming where it was.
61
116
  #: (Hash[String, untyped]) -> String
62
117
  def named(member)
@@ -14,10 +14,13 @@ module Principles
14
14
  # files, the one passage any of them would take, and the commands that map the passage once the agent has placed
15
15
  # it with the user.
16
16
  class MetaPrincipleResult
17
+ # The placeholders each printed add-member leaves for the name and reason that justify its member.
18
+ JUSTIFYING = "--name NAME --reason REASON" #: String
19
+
17
20
  # How the printed add-member commands map the passage: heading is the passage's heading, which they name as
18
21
  # its member's section, beside role, the role they give that member; step_role is the role they give a
19
22
  # passage the project has that carries one of the passage's steps, and place_role the one they give any other
20
- # place that keeps the principles held, such as a timer or a settings line.
23
+ # place that has the principles checked, such as a timer or a settings line.
21
24
  class PassageMapping
22
25
  #: String
23
26
  attr_reader :heading, :role, :step_role, :place_role
@@ -76,12 +79,15 @@ module Principles
76
79
  # Where the passage can go, as the agent places it from: how this run was started and whether the plugin's
77
80
  # session-start hook runs in this session, each root entry file's facts, and the passage.
78
81
  class Placement
82
+ # enabled_in_project_settings is the project settings line that enables the plugin, by path and starting_at.
79
83
  #: (runs_from: String, session_start_hook_in_this_session: bool, entry_files: Array[Hash[String, untyped]],
80
- #| passage: Passage) -> void
81
- def initialize(runs_from:, session_start_hook_in_this_session:, entry_files:, passage:)
84
+ #| passage: Passage, ?enabled_in_project_settings: Hash[String, String]?) -> void
85
+ def initialize(runs_from:, session_start_hook_in_this_session:, entry_files:, passage:,
86
+ enabled_in_project_settings: nil)
82
87
  @fields = { "runs_from" => runs_from,
83
88
  "session_start_hook_in_this_session" => session_start_hook_in_this_session,
84
- "entry_files" => entry_files, "passage" => passage.to_h }.freeze #: Hash[String, untyped]
89
+ "entry_files" => entry_files, "passage" => passage.to_h,
90
+ "enabled_in_project_settings" => enabled_in_project_settings }.freeze #: Hash[String, untyped]
85
91
  @passage = passage
86
92
  freeze
87
93
  end
@@ -93,6 +99,10 @@ module Principles
93
99
  #: () -> Integer
94
100
  def estimated_tokens = @passage.estimated_tokens
95
101
 
102
+ # The project settings line that enables the plugin, or nil.
103
+ #: () -> Hash[String, String]?
104
+ def enabling_line = @fields.fetch("enabled_in_project_settings")
105
+
96
106
  # Whether the plugin's hooks report in this session, so its hook entries need no offer.
97
107
  #: () -> bool
98
108
  def hooks_run? = @fields.fetch("session_start_hook_in_this_session")
@@ -129,7 +139,7 @@ module Principles
129
139
  "map" => principle.map, **map_in_project.to_h, **placement.to_h,
130
140
  **hook_setup(placement, mapped: map_in_project.already_mapped || existing_principles.any?),
131
141
  "existing_principles" => existing_principles,
132
- "question" => map_in_project.set_up ? steps_lacking(principle, placement) : question(principle.id),
142
+ "question" => map_in_project.set_up ? steps_lacking(principle, placement) : question(principle.id, placement),
133
143
  "answer_with" => add_member(principle.id), "next_action" => next_action(principle.id, existing_principles) }
134
144
  end
135
145
 
@@ -146,10 +156,23 @@ module Principles
146
156
 
147
157
  # What to agree with the user and place, with the command that maps a passage the project has in a step's
148
158
  # place, and the one that maps the passage once it is placed.
149
- #: (String) -> String
150
- def question(id)
151
- Prompts.text("set-principles-up/place-the-passage-with-the-user",
152
- command: add_member(id), existing: add_existing(id), any_place: add_place(id))
159
+ #: (String, Placement) -> String
160
+ def question(id, placement)
161
+ place = Prompts.text("set-principles-up/place-the-passage-with-the-user",
162
+ command: add_member(id), existing: add_existing(id), any_place: add_place(id),
163
+ why: Prompts.text("set-principles-up/why-set-principles-up"))
164
+ line = placement.enabling_line or return place
165
+
166
+ "#{Prompts.text("set-principles-up/map-the-enabling-line-at-no-edit",
167
+ path: line.fetch("path"), command: add_enabling_line(id, line))}\n\n#{place}"
168
+ end
169
+
170
+ # The add-member that maps the project settings line enabling the plugin, located by its literal opening.
171
+ #: (String, Hash[String, String]) -> String
172
+ def add_enabling_line(id, line)
173
+ @invocation.in_project("add-member", id, line.fetch("path"),
174
+ options: ["--starting-at", line.fetch("starting_at"), "--role", @mapping.place_role,
175
+ *JUSTIFYING.split])
153
176
  end
154
177
 
155
178
  # Each mapped member's place and role, and which keeping step each lacks, with the passage as one way to add a
@@ -162,23 +185,25 @@ module Principles
162
185
  estimated_tokens: placement.estimated_tokens.to_s)
163
186
  end
164
187
 
165
- # The add-member that maps any other place that keeps the principles held, by its path and a role naming the
188
+ # The add-member that maps any other place that has the principles checked, by its path and a role naming the
166
189
  # step it runs and what starts it.
167
190
  #: (String) -> String
168
191
  def add_place(id)
169
- @invocation.in_project("add-member", id, usage: "PATH --role \"#{@mapping.place_role}\"")
192
+ @invocation.in_project("add-member", id, usage: "PATH --role \"#{@mapping.place_role}\" #{JUSTIFYING}")
170
193
  end
171
194
 
172
195
  # The add-member that maps a passage the project already has, which carries one of the passage's steps.
173
196
  #: (String) -> String
174
197
  def add_existing(id)
175
- @invocation.in_project("add-member", id, usage: "PATH --section \"HEADING\" --role \"#{@mapping.step_role}\"")
198
+ @invocation.in_project("add-member", id,
199
+ usage: "PATH --section \"HEADING\" --role \"#{@mapping.step_role}\" #{JUSTIFYING}")
176
200
  end
177
201
 
178
202
  #: (String) -> String
179
203
  def add_member(id)
180
204
  @invocation.in_project("add-member", id,
181
- usage: "ENTRY_FILE --section \"#{@mapping.heading}\" --role \"#{@mapping.role}\"")
205
+ usage: "ENTRY_FILE --section \"#{@mapping.heading}\" --role \"#{@mapping.role}\" " \
206
+ "#{JUSTIFYING}")
182
207
  end
183
208
 
184
209
  # What follows placing the passage: committing it, which outside git is not the member's baseline, and the
@@ -52,6 +52,18 @@ module Principles
52
52
  status: short.status)
53
53
  end
54
54
 
55
+ # short's lines with one stderr line first saying what each last field its changed members' rows end with asks
56
+ # for, so an agent can tell an acknowledgement from an audit; unchanged when no row does. A row waiting
57
+ # on an upgrade asks nothing yet, as stderr's update sentence says.
58
+ #: (Lines, Hash[String, untyped]) -> Lines
59
+ def explaining_rows(short, report)
60
+ ending = report.fetch("members").reject { it["waiting_on_an_upgrade"] }.map { it.dig("since", "baseline") }
61
+ asks = ending.uniq.filter_map { row_asks(it) }
62
+ return short if asks.empty?
63
+
64
+ Lines.new(stdout: short.stdout, stderr: "#{asks.join(" ")}\n#{short.stderr}", status: short.status)
65
+ end
66
+
55
67
  # short's lines for a session-start hook: on stdout, one line for each principle with a changed member an
56
68
  # audit or acknowledgement assessed, as session_start_lines says, from changed, in place of the rows and
57
69
  # never-assessed counts, which an always-loaded carrier cannot afford; stderr and the status kept.
@@ -93,6 +105,16 @@ module Principles
93
105
  .map { VisibleText.new(it).to_s }.join("\t")
94
106
  end
95
107
 
108
+ # What a row whose last field names baseline asks for, in the order the rows give.
109
+ #: (String) -> String?
110
+ def row_asks(baseline)
111
+ case baseline
112
+ when "audit" then Prompts.text("report-after-a-commit/a-row-ending-audit-asks-to-acknowledge-or-audit-again")
113
+ when "mapping_commit" then Prompts.text("report-after-a-commit/a-row-ending-mapping-commit-asks-for-an-audit")
114
+ when "pinned" then Prompts.text("report-after-a-commit/a-row-ending-pinned-asks-for-an-audit")
115
+ end
116
+ end
117
+
96
118
  # The session-start line on principle id's count of changed audited members.
97
119
  #: (String, Integer) -> String
98
120
  def changed_line(id, count)
@@ -0,0 +1,3 @@
1
+ Each of these members was seen only where the agent read, sent or quoted it, never in the system prompt, a system
2
+ message, a tool definition or a reminder the host added: does the host load it at all, or does it reach the agent
3
+ only when the agent looks?
@@ -0,0 +1,2 @@
1
+ Does each member's reason hold against its carrier, loads and what was observed, and does it earn its bytes? Where its
2
+ reason is null, propose one in a finding, to set with change-member-reason.
@@ -5,3 +5,5 @@ last judged them. This principle's members are what is meant to bring such chang
5
5
  listed change against them: where one has waited with nothing in the project carrying the step that would have
6
6
  caught it, raise a finding on the member that should carry it. Each listed principle's own audit judges its
7
7
  change; this one does not.
8
+ Weigh, too, whether each member here is in context when its work is in hand and out of it otherwise, so usable
9
+ context stays as large as it can.
@@ -1,7 +1,7 @@
1
1
  Weigh what reached the context. `members` lists every member this request lists, those marked `carried_forward`
2
2
  too, whose text has not changed since the last audit but may still never reach the agent. `seen_in` counts the
3
3
  captured requests that held a member's lines, of the `requests` beside `members`, every captured request the scan
4
- read through, and `most_bytes` is the most of them one request held; `unreadable`, when printed, counts requests that
5
- could not be read. `detail_with` shows where one member was seen, given its `member` as KEY. Did a member seen in no request carry its principle to the agent at all? Is a member seen in every
4
+ read through, `channels` counts them by the channel it came by, and `most_bytes` is the most of them one request held; `unreadable`, when printed, counts requests that
5
+ could not be read. `detail_with` shows where one member was seen, given its `member` as KEY. Did a member seen in no request carry its principle to the agent at all? `seen_only_as_read`, when printed, lists the members seen in no channel the host loads by, under one question. Is a member seen in every
6
6
  request worth its bytes in every session? Say so in the member's assessment where it changes your judgement, and for
7
7
  a carried member in `collective_assessment`.
@@ -4,7 +4,7 @@
4
4
  "action": "fixed",
5
5
  "reason": "What you changed, in one line",
6
6
  "changed_members": ["the id of each member the fix changed"],
7
- "changed_map_entries": ["the id of each member whose role or check the fix changed"],
7
+ "changed_map_entries": ["the id of each member whose role, check, name or reason the fix changed"],
8
8
  "removed_members": ["the id of each member the fix removed from the map"],
9
9
  "evidence": [{ "path": "a project file", "starting_at": "text that occurs once in the fixed passage" }],
10
10
  "reassessment": "How the changed member reads now, and any check you ran on it",
@@ -21,7 +21,7 @@ or wider, move the member with `move-member`, then list the move in the answer a
21
21
  `"moved_members": [{"from": OLD_ID, "to": NEW_ID}]`, or `[{"from": ID, "to": ID}]` when the move kept its id, and
22
22
  name the id after the move in the finding's `changed_members`. In git, the move is checked against the map
23
23
  the audit began from.
24
- If the fix is to a member's role or check in the map, make it with `change-member-role` or `change-member-check`
24
+ If the fix is to a member's role, check, name or reason in the map, make it with that field's `change-member-` command
25
25
  and list the member's id in the finding's `changed_map_entries`. In git, the change is checked against the map the
26
26
  audit began from.
27
27
  If the fix is to map a member the finding says is missing, add it with `add-member` and name its id in the finding's
@@ -0,0 +1 @@
1
+ Before you fix a member, read its carrier kind's page with `carrier_checks.page_command`, its last word that kind, and follow it.
@@ -0,0 +1,2 @@
1
+ principles: before this %{kind} edit, run %{command}, read the page and follow it, then retry the same
2
+ edit. Asked once per kind each session.