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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee677395361bfbec2ef7c0e1718505576d79d282eb0d81e9c9760e3ec3e02387
4
- data.tar.gz: 81b1148137ce71cc9ae851c904e8fa37c0b3ccb96dc286a716890d7115496497
3
+ metadata.gz: dc9eb3a41733a35a59cf92549d903b5ca30cf42b084dfb54246290b869305581
4
+ data.tar.gz: 38c90caf956f52edf5c81b88840c476c94e21cf2ee710ea042bded8665578992
5
5
  SHA512:
6
- metadata.gz: 8e18c7e780f59f4097b67a4e38d16f106543ed0094c9e1bb2dd7d0025bdfae7607929e43268d7fad55d0e5717936c02a52311b6a7a71205f3a3caaafa6b248a0
7
- data.tar.gz: bed41a26755dedd06be1813dc36bb5eeffc63d319b6005cca2506a1e44ce00ed6d646d2c488849400ebcadc4d43d021e5fb13719762923361bc123f6d6d83d4b
6
+ metadata.gz: 9a02354af85a5b704dc73ebae2b2ddd5e82ca61a81ad1bd0c16d496c7ab0dd488b7852302be074c507734361f46bcf80bdff2336f7c430de921c1e2a419d5431
7
+ data.tar.gz: 75e515013dd56a892e2fdbdac2d612455933b7d5800efbb3c8122388d962afa57f3caa3474b3bc0f732f42aba1443f03c722ce01e81633e557eacbaaccaf1aa8
data/CHANGELOG.md CHANGED
@@ -8,11 +8,41 @@ Write each entry for the person deciding whether to upgrade: whoever runs agents
8
8
  2. Then say how they get it, naming the command or option they or their agent will use.
9
9
  3. Give the measured effect as a plain comparison, such as "about a tenth of the bytes" or "one answer instead of one per principle", where the change or its commits measure it.
10
10
 
11
- The agent's mechanics are the means, never the lead: do not open with "An agent no longer…". Leave refusal codes, field names and JSON shapes to the help text unless the reader must act on one; mark a breaking change "**Breaking:**", before or after the lead, and say what to change. Word a change with no user-visible effect for contributors. Claim only value the change or its commits show; never invent it. At release, use the actual version and `YYYY-MM-DD` date; never infer publication from a version bump. Preserve released history.
11
+ The agent's mechanics are the means, never the lead: do not open with "An agent no longer…". Leave refusal codes, field names and JSON shapes to the help text unless the reader must act on one; mark a breaking change "**Breaking:**", before or after the lead, and say what to change. Word a change with no user-visible effect for contributors. Claim only value the change or its commits show; never invent it. At release, use the actual version and `YYYY-MM-DD` date; never infer publication from a version bump. At the cut, each lead maps to a passed claim in the release file, `releases/<version>.md`, which is not published, or the lead is cut. Preserve released history.
12
12
  -->
13
13
 
14
14
  ## Unreleased
15
15
 
16
+ ## [0.1.5] - 2026-11-30
17
+
18
+ **0.1.5: know which of your principles actually reach your agent.** Until now, a rule your agent merely opened looked exactly like one Claude Code loads into every turn, so a principle could look covered when it never reached the agent. 0.1.5 tells the two apart, shows what each turn's context is spent on, and asks every place a principle lives why it is there.
19
+
20
+ ### Added
21
+
22
+ - **See whether a principle's text was loaded by Claude Code or only read by your agent.** `principles show-members-in-logged-requests` counts how each place's text arrived, such as `system 1, reminder 40, tool_result 3`: `system` and `reminder` mean Claude Code loaded it, `tool_result` means your agent read it. It lists places in the order their requests were sent, and labels each request a turn's first, a mid-turn request, a side request such as the summary while you're away, or unclassified, so a principle absent from a side request no longer reads as one that failed to load. While your requests are logged, a full audit names each place your agent only read and asks whether Claude Code really loads it. A mid-turn request is logged with only what it added, so a principle absent there tells you nothing, and a `system` count can include text your agent quoted from another agent's report.
23
+
24
+ - **See where your context goes before your agent does any work.** `principles show-context-budget` splits the first request of each turn into the system prompt, tool definitions, reminders and conversation, and shows how much of it your principles take; `--short` gives one line a session. It reads your whole request log, so it is slow on a big one: about 45 seconds on our log of 13,077 files.
25
+
26
+ - **Turn request logging on once, in your own settings, instead of with a flag on every launch.** `principles turn-on-request-logging --for-user` prints the lines to add to your own Claude Code settings, once your agent has asked you, and never writes them itself; other projects' requests are deleted when a session next starts in a project that uses `principles`. We have not yet checked it from the Desktop app or a signed-in launch, and an install without the plugin's hooks keeps no sessions.
27
+
28
+ - **Once an audit has shown it's worth it, your agent offers to keep your principles checked between audits.** A completed full audit asks your agent to put the question to you, with the reason: where no `principles` hook is wired, nothing notices an edit to a file a principle depends on until the next audit. Until you set it up, each new session adds one line of under 200 bytes while the plugin's hooks run; a gem-only install, or a project with nothing mapped, gets no such line.
29
+
30
+ - **Your agent reads how to write a kind of file before it first edits one.** The plugin's new hook stops your agent's first edit of a `CLAUDE.md`, rule, skill, subagent or hook once for each of those kinds in a session, with a short reason pointing at `principles show-carrier-practices KIND`, then lets the retry through. `principles show-hook-setup` gives the same hook to a project without the plugin. We saw this by running the hook directly, not yet in a live Claude Code session.
31
+
32
+ - **Every place a principle lives is now asked why it is there.** `principles add-member` refuses a new member without a short `--name` and a `--reason`: when that file puts the principle in front of your agent, and what would prove that wrong. Each full audit asks whether every reason still holds and every place earns its bytes; we have not yet seen one catch a wrong reason. **Breaking:** scripts that call `add-member` must pass both, and 0.1.4 or earlier refuses a map that carries a name or reason, asking you to upgrade, so upgrade every copy that reads it first.
33
+
34
+ ### Changed
35
+
36
+ - **`principles list-member-problems --short` says what each row needs.** Before its commands, it prints a line for each kind of row it shows, saying which to acknowledge and which to audit again.
37
+
38
+ - **The plugin's skill no longer sends your agent to a file kind the command refuses.** Its checklist named a `hook` kind that `show-carrier-practices` rejects; it now names `hook_configuration` and `hook_script`, and its always-loaded description drops a word the reader could not unpack.
39
+
40
+ - **A teammate without `principles` is no longer told to run it.** The passage `principles show-meta-principle-passage` proposes for your `CLAUDE.md` asks for its checks only where `principles` can run and none of its hooks is wired, a checkout included.
41
+
42
+ ### Fixed
43
+
44
+ - **Commands `principles` prints work when pasted, even under Bundler.** Run from a checkout with `bundle exec`, the commands it prints now start with `BUNDLE_GEMFILE=… bundle exec`, so a fresh shell runs them as you did.
45
+
16
46
  ## [0.1.4] - 2026-11-28
17
47
 
18
48
  ### Added
data/exe/principles CHANGED
@@ -27,4 +27,4 @@ if ARGV == ["report-after-commit"]
27
27
  end
28
28
 
29
29
  require_relative "../lib/principles"
30
- exit Principles::CLI.run(ARGV)
30
+ exit Principles::CLI.run(ARGV, launch: Principles::Launch.of_this_process)
@@ -20,20 +20,19 @@ module Principles
20
20
 
21
21
  # Runs one invocation and returns its exit status: 0 for a result, 1 for a refusal, 2 for a usage error, and 3
22
22
  # when list-member-problems --short finds a member an audit assessed changed, or 4 when it finds only edits to
23
- # members no audit has assessed. executable is the command every printed command
24
- # names: the entry point says how it is run.
25
- #: (Array[String], ?IO, ?IO, ?IO, ?executable: String) -> Integer
26
- def self.run(argv, stdout = $stdout, stderr = $stderr, stdin = $stdin,
27
- executable: Controllers::Command::INVOCATION)
28
- new(stdout, stderr, stdin, executable: executable).run(argv)
23
+ # members no audit has assessed. launch is how the entry point launched this run: the command every printed
24
+ # command names, and the Gemfile bundler runs it under, if any.
25
+ #: (Array[String], ?IO, ?IO, ?IO, ?launch: Launch) -> Integer
26
+ def self.run(argv, stdout = $stdout, stderr = $stderr, stdin = $stdin, launch: Launch.new)
27
+ new(stdout, stderr, stdin, launch:).run(argv)
29
28
  end
30
29
 
31
- #: (IO, IO, IO, executable: String) -> void
32
- def initialize(stdout, stderr, stdin, executable:)
30
+ #: (IO, IO, IO, launch: Launch) -> void
31
+ def initialize(stdout, stderr, stdin, launch:)
33
32
  @stdout = stdout
34
33
  @stderr = stderr
35
34
  @stdin = stdin
36
- @executable = executable
35
+ @launch = launch
37
36
  end
38
37
 
39
38
  #: (Array[String]) -> Integer
@@ -152,7 +151,7 @@ module Principles
152
151
 
153
152
  # This run of the tool, as its entry point launched it.
154
153
  #: () -> Controllers::RunningTool
155
- def running_tool = Launch.new(@executable).running_tool
154
+ def running_tool = @launch.running_tool
156
155
 
157
156
  # The version of this tool that is running, as --version prints it.
158
157
  #: () -> String
@@ -15,9 +15,11 @@ require_relative "controllers/open_correction"
15
15
  require_relative "controllers/first_audit_brief"
16
16
  require_relative "controllers/session_start_report"
17
17
  require_relative "controllers/after_commit_report"
18
+ require_relative "controllers/carrier_edit_report"
18
19
  require_relative "controllers/hook_setup"
19
20
  require_relative "controllers/request_logging"
20
21
  require_relative "controllers/members_in_logged_requests"
22
+ require_relative "controllers/context_budget"
21
23
  require_relative "controllers/carrier_practices"
22
24
 
23
25
  module Principles
@@ -63,6 +65,8 @@ module Principles
63
65
  "add-member" => Route.new(Controllers::MemberEntries, %w[id path]),
64
66
  "move-member" => Route.new(Controllers::MemberEntries, %w[id member]),
65
67
  "change-member-role" => Route.new(Controllers::MemberEntries, %w[id member]),
68
+ "change-member-name" => Route.new(Controllers::MemberEntries, %w[id member]),
69
+ "change-member-reason" => Route.new(Controllers::MemberEntries, %w[id member]),
66
70
  "change-member-check" => Route.new(Controllers::MemberEntries, %w[id member]),
67
71
  "remove-member-check" => Route.new(Controllers::MemberEntries, %w[id member]),
68
72
  "remove-member" => Route.new(Controllers::MemberEntries, %w[id member]),
@@ -74,12 +78,14 @@ module Principles
74
78
  "show-hook-setup" => Route.new(Controllers::HookSetup, []),
75
79
  "turn-on-request-logging" => Route.new(Controllers::RequestLogging, []),
76
80
  "show-members-in-logged-requests" => Route.new(Controllers::MembersInLoggedRequests, []),
81
+ "show-context-budget" => Route.new(Controllers::ContextBudget, []),
77
82
  "turn-off-request-logging" => Route.new(Controllers::RequestLogging, []),
78
83
  "show-logged-requests" => Route.new(Controllers::RequestLogging, []),
79
84
  "remove-logged-requests" => Route.new(Controllers::RequestLogging, []),
80
85
  "show-carrier-practices" => Route.new(Controllers::CarrierPractices, %w[kind]),
81
86
  "report-at-session-start" => Route.new(Controllers::SessionStartReport, [], reads_hook_input: true),
82
- "report-after-commit" => Route.new(Controllers::AfterCommitReport, [], reads_hook_input: true)
87
+ "report-after-commit" => Route.new(Controllers::AfterCommitReport, [], reads_hook_input: true),
88
+ "report-before-carrier-edit" => Route.new(Controllers::CarrierEditReport, [], reads_hook_input: true)
83
89
  }.freeze #: Hash[String, Route]
84
90
 
85
91
  # Each command's positional arguments, in order, as CommandLine takes them.
@@ -0,0 +1,40 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/carrier_edit_input"
6
+ require_relative "../models/carrier_pages_shown"
7
+ require_relative "../views/carrier_edit_denial"
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
+ # report-before-carrier-edit, which a PreToolUse hook on Edit and Write runs: the first edit of each carrier kind
14
+ # in a session is denied once, its reason naming that kind's practices page, and every other call goes through
15
+ # with nothing printed. It exits 0 whatever it reads.
16
+ class CarrierEditReport < Command
17
+ #: (String, String?, Hash[String, untyped]) -> untyped
18
+ def call(command, _id, options)
19
+ naming_the_executable do
20
+ unknown(command) unless command == "report-before-carrier-edit"
21
+
22
+ reported(Models::CarrierEditInput.new(options["stdin"].to_s, @project))
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ #: (Models::CarrierEditInput) -> Views::Lines
29
+ def reported(input)
30
+ view = Views::CarrierEditDenial.new(invocation.without_project)
31
+ kind = input.kind
32
+ session = input.session
33
+ return Views::CarrierEditDenial::NOTHING unless kind && session
34
+
35
+ shown = Models::CarrierPagesShown.new(@tool.temp_directory)
36
+ shown.point_now?(session, kind) ? view.denied(kind) : Views::CarrierEditDenial::NOTHING
37
+ end
38
+ end
39
+ end
40
+ end
@@ -6,6 +6,7 @@ require_relative "../error"
6
6
  require_relative "../models/answer_text"
7
7
  require_relative "../models/audit"
8
8
  require_relative "../models/carried_assessments"
9
+ require_relative "../models/map_format_raise"
9
10
  require_relative "../models/member"
10
11
  require_relative "../models/member_grounds"
11
12
  require_relative "../models/principle_history"
@@ -16,6 +17,7 @@ require_relative "../models/record_judged_against"
16
17
  require_relative "../views/audit_result"
17
18
  require_relative "../views/invocation"
18
19
  require_relative "../views/lines_shared_with_member"
20
+ require_relative "../views/map_format_raised"
19
21
  require_relative "../views/carrier_checks"
20
22
  require_relative "../views/map_result"
21
23
  require_relative "../views/record_waiting_on_an_upgrade"
@@ -60,11 +62,13 @@ module Principles
60
62
  @project.principle_history(principle_id)
61
63
  end
62
64
 
63
- # Saves the map, and nothing else, then prints the result the block builds from the map as written.
65
+ # Saves the map, and nothing else, then prints the result the block builds from the map as written, saying
66
+ # when the write raised the map to a format some earlier release cannot read.
64
67
  #: (Models::Principle) { (Views::PrintedPrinciple) -> Hash[String, untyped] } -> untyped
65
68
  def write_map(map, &)
69
+ raised = Views::MapFormatRaised.new(map.id, **Models::MapFormatRaise.new(@principles, map).to_h)
66
70
  wrote = @principles.save(map)
67
- yield(printed_principle(map)).merge("wrote" => [wrote])
71
+ yield(printed_principle(map)).merge("wrote" => [wrote]).merge(raised.to_h)
68
72
  end
69
73
 
70
74
  # Runs the block, putting the running executable into any refusal a model raised, followed by this project,
@@ -168,7 +172,7 @@ module Principles
168
172
  # When each of the map's members loads, by id, which a full audit's request lists against the activation and
169
173
  # show-principle prints, from the project's hooks as hooks read them.
170
174
  #: (Models::Principle, ?Models::HookCommands) -> Hash[String, Models::MemberLoads]
171
- def member_loads(map, hooks = @project.hook_commands) = @project.member_loads(map.members, hooks)
175
+ def member_loads(map, hooks = @project.harness.hook_commands) = @project.harness.member_loads(map.members, hooks)
172
176
 
173
177
  # The check for each carrier kind the map's members are in, or only those ids names, in the order given, once
174
178
  # each, for a request where the agent judges or edits them.
@@ -0,0 +1,61 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+ require_relative "../models/members_in_logged_requests"
6
+ require_relative "../models/members_by_part"
7
+ require_relative "../models/session_trend"
8
+ require_relative "../views/context_budget_result"
9
+
10
+ module Principles
11
+ # Each runs one command: reads models, applies their rules and prints through a view.
12
+ # controllers/CLAUDE.md owns the boundary.
13
+ module Controllers
14
+ # show-context-budget: for each turn the agent opened, as the host captured its request under
15
+ # .principles/request-logging/requests/, how much of the context the host loaded before the work started, in
16
+ # bytes beside the host's own token count. It writes nothing.
17
+ class ContextBudget < Command
18
+ # CommandRoutes routes only show-context-budget here.
19
+ #: (String, String?, Hash[String, untyped]) -> untyped
20
+ def call(command, _id, options)
21
+ naming_the_executable do
22
+ @tool.feature(command).refuse_while_off
23
+ session = options["session"]
24
+ sessions = measured(only(turn_openings, session), listing: !session.nil?)
25
+ view = Views::ContextBudgetResult.new
26
+ options["short"] ? view.short(sessions) : view.result(sessions)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # Each captured turn opening, by session, with the bytes of mapped members' text each sent.
33
+ #: () -> Array[[String?, Array[Models::TurnOpening]]]
34
+ def turn_openings = @project.request_logging.turn_openings(Models::MembersInLoggedRequests.mapped_in(@project))
35
+
36
+ # Each session as plain values: its id, its trend, its last turn opening with the members it sent, the members
37
+ # its turn openings sent all told, and, when listing, each turn opening with the members it sent.
38
+ #: (Array[[String?, Array[Models::TurnOpening]]], listing: bool) -> Array[Views::ContextBudgetResult::session]
39
+ def measured(openings, listing:)
40
+ openings.map do |session, opened|
41
+ [session, Models::SessionTrend.new(opened).to_h, opened.fetch(-1).with_members,
42
+ Models::MembersByPart.together(opened.map(&:members)).to_a, (opened.map(&:with_members) if listing)]
43
+ end
44
+ end
45
+
46
+ # openings, by session, only session's where one is named; refused as unknown_session, naming the sessions
47
+ # there are, where none is that session, since an empty list would read as a session with no turns.
48
+ #: (Array[[String?, Array[Models::TurnOpening]]], String?) -> Array[[String?, Array[Models::TurnOpening]]]
49
+ def only(openings, session)
50
+ return openings unless session
51
+
52
+ held = openings.select { |id, _| id == session }
53
+ return held unless held.empty?
54
+
55
+ refusal = Error.new("unknown_session", "No logged turn opening was sent in session #{session}",
56
+ "Give --session one of the sessions listed, or leave it out to show every session.")
57
+ raise refusal.including("sessions" => openings.filter_map(&:first))
58
+ end
59
+ end
60
+ end
61
+ end
@@ -70,11 +70,12 @@ module Principles
70
70
  # they load and the hook settings not read; without, its next_action names --loads.
71
71
  #: (Models::Principle, Models::AuditRecord?, loads: bool?) -> Hash[String, untyped]
72
72
  def principle_shown(principle, audit, loads:)
73
- hooks = @project.hook_commands
73
+ harness = @project.harness
74
+ hooks = harness.hook_commands
74
75
  members = shown_members(principle, audit, hooks)
75
76
  if loads
76
77
  return members_listed(principle, members, hook_settings_not_read: hooks.not_read,
77
- loaded_files: @project.loaded_files(principle.members, hooks).to_h)
78
+ loaded_files: harness.loaded_files(principle.members, hooks).to_h)
78
79
  end
79
80
 
80
81
  read_result.without_loads(members_listed(principle, members.map { it.except("loads") }), principle.id)
@@ -56,7 +56,7 @@ module Principles
56
56
  joined = @joined.with_completeness_question(
57
57
  asks: added_to.members.asks_about_completeness?(no_completed_audit: no_completed)
58
58
  )
59
- scopes = Models::MemberLoadingScopes.new(@project.member_loads(added_to.members))
59
+ scopes = Models::MemberLoadingScopes.new(@project.harness.member_loads(added_to.members))
60
60
  joined.with_loading_scope(Views::NewLoadingScope.new(scopes.introduced_by(@member.id)))
61
61
  end
62
62
 
@@ -3,8 +3,10 @@
3
3
 
4
4
  require_relative "command"
5
5
  require_relative "member_addition"
6
+ require_relative "member_entry_changes"
6
7
  require_relative "plugin_member_addition"
7
8
  require_relative "../models/authored_locator"
9
+ require_relative "../models/member_justification"
8
10
 
9
11
  module Principles
10
12
  # Each runs one command: reads models, applies their rules and prints through a view.
@@ -17,24 +19,36 @@ module Principles
17
19
  # Each command and the method that runs it.
18
20
  COMMANDS = {
19
21
  "add-member" => :add_member, "move-member" => :move_member,
20
- "change-member-role" => :change_member_role, "change-member-check" => :change_member_check,
21
- "remove-member-check" => :remove_member_check, "remove-member" => :remove_member
22
+ "remove-member" => :remove_member
22
23
  }.freeze #: Hash[String, Symbol]
23
24
 
24
25
  # Each location option and the name the agent typed it as.
25
26
  LOCATION_OPTIONS = { "section" => "--section", "starting_at" => "--starting-at",
26
27
  "ending_at" => "--ending-at", "query" => "--query" }.freeze #: Hash[String, String]
27
28
 
29
+ # The options beside --role that justify a new member, stored when given, in the order the map holds them.
30
+ JUSTIFYING_OPTIONS = %w[name reason].freeze #: Array[String]
31
+
28
32
  #: (String, String?, Hash[String, untyped]) -> untyped
29
33
  def call(command, id, options)
30
34
  naming_the_executable(rerun: ->(member) { rerun(command, id.to_s, member, options) }) do
31
- method = COMMANDS[command] or unknown(command)
32
- send(method, required_id(id), options)
35
+ run(command, id, options)
33
36
  end
34
37
  end
35
38
 
36
39
  private
37
40
 
41
+ # Runs command on principle id: a change to what a member's entry says of it in MemberEntryChanges, any other
42
+ # here.
43
+ #: (String, String?, Hash[String, untyped]) -> untyped
44
+ def run(command, id, options)
45
+ changes = MemberEntryChanges::COMMANDS.key?(command)
46
+ return handed(MemberEntryChanges).call(command, required_id(id), options) if changes
47
+
48
+ method = COMMANDS[command] or unknown(command)
49
+ send(method, required_id(id), options)
50
+ end
51
+
38
52
  # command as the agent ran it on principle id, with member in place of the member id it gave, and its options
39
53
  # as given, each quoted for a shell and named as the agent typed it: a location by LOCATION_OPTIONS, any other,
40
54
  # such as --path or --role, by its own one-word name.
@@ -48,7 +62,7 @@ module Principles
48
62
 
49
63
  #: (String, Hash[String, untyped]) -> untyped
50
64
  def add_member(id, options)
51
- return handed(PluginMemberAddition).add(id, options) if options.key?("plugin")
65
+ return handed(PluginMemberAddition).add(id, options, justified(options)) if options.key?("plugin")
52
66
 
53
67
  add_project_member(id, options)
54
68
  end
@@ -76,10 +90,19 @@ module Principles
76
90
  (opening ? member.merge("starting_at" => opening) : member).merge(played(options))
77
91
  end
78
92
 
79
- # The part a new member plays, and the check that enforces it when one is named.
93
+ # The part a new member plays, with the name and reason that justify it, each when given, as a plugin member
94
+ # stores them too.
95
+ #: (Hash[String, untyped]) -> Hash[String, untyped]
96
+ def justified(options)
97
+ Models::MemberJustification.new(options.slice("name", "reason")).check
98
+ given = JUSTIFYING_OPTIONS.select { |field| options[field] }
99
+ { "role" => text(options["role"], "--role"), **given.to_h { [it, text(options[it], "--#{it}")] } }
100
+ end
101
+
102
+ # The part a project member plays, as justified, and the check that enforces it when one is named.
80
103
  #: (Hash[String, untyped]) -> Hash[String, untyped]
81
104
  def played(options)
82
- role = { "role" => text(options["role"], "--role") }
105
+ role = justified(options)
83
106
  options["check"] ? role.merge("check" => text(options["check"], "--check")) : role
84
107
  end
85
108
 
@@ -110,37 +133,6 @@ module Principles
110
133
  options["path"] ? text(options["path"], "--path") : old.fetch("path")
111
134
  end
112
135
 
113
- #: (String, Hash[String, untyped]) -> untyped
114
- def change_member_role(id, options)
115
- map = @principles.find(id)
116
- target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
117
- role = text(options["role"], "--role")
118
- write_map(map.changing_role(target, role)) do |printed|
119
- map_result.role_changed(printed, member: target, role: role)
120
- end
121
- end
122
-
123
- # Names the command that enforces a member, which the audit asks the agent to run.
124
- #: (String, Hash[String, untyped]) -> untyped
125
- def change_member_check(id, options)
126
- map = @principles.find(id)
127
- target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
128
- check = text(options["check"], "--check")
129
- changed = map.changing_check(target, check)
130
- hidden = Models::Member.new(changed.member(target)).check_hidden_characters
131
- write_map(changed) { |printed| map_result.check_changed(printed, member: target, hidden: hidden) }
132
- end
133
-
134
- #: (String, Hash[String, untyped]) -> untyped
135
- def remove_member_check(id, options)
136
- map = @principles.find(id)
137
- target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
138
- write_map(map.removing_check(target)) do |printed|
139
- map_result.member_replaced(printed, done: "Removed the check of #{target}; the audit no longer asks for " \
140
- "its result.")
141
- end
142
- end
143
-
144
136
  #: (String, Hash[String, untyped]) -> untyped
145
137
  def remove_member(id, options)
146
138
  map = @principles.find(id)
@@ -0,0 +1,71 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "command"
5
+
6
+ module Principles
7
+ # Each runs one command: reads models, applies their rules and prints through a view.
8
+ # controllers/CLAUDE.md owns the boundary.
9
+ module Controllers
10
+ # The writes that change what an existing member's entry in the committed member map says of it, apart from where
11
+ # it is: the part it plays and the check that enforces it. MemberEntries runs each command and hands it here, so a
12
+ # near-miss member id is repaired as for every member command.
13
+ class MemberEntryChanges < Command
14
+ # Each command and the method that runs it.
15
+ COMMANDS = {
16
+ "change-member-role" => :change_member_role, "change-member-name" => :change_member_name,
17
+ "change-member-reason" => :change_member_reason,
18
+ "change-member-check" => :change_member_check,
19
+ "remove-member-check" => :remove_member_check
20
+ }.freeze #: Hash[String, Symbol]
21
+
22
+ #: (String, String, Hash[String, untyped]) -> untyped
23
+ def call(command, id, options) = send(COMMANDS.fetch(command), id, options)
24
+
25
+ private
26
+
27
+ #: (String, Hash[String, untyped]) -> untyped
28
+ def change_member_role(id, options) = change_field(id, options, "role")
29
+
30
+ # Renames a member for display; its id and key stay, since commands never find a member by its name.
31
+ #: (String, Hash[String, untyped]) -> untyped
32
+ def change_member_name(id, options) = change_field(id, options, "name")
33
+
34
+ # Rewrites why a member's carrier puts its principle in context, as an audit that shows the reason false asks.
35
+ #: (String, Hash[String, untyped]) -> untyped
36
+ def change_member_reason(id, options) = change_field(id, options, "reason")
37
+
38
+ # Replaces what the member's entry says in field with the value its option of that name gives.
39
+ #: (String, Hash[String, untyped], String) -> untyped
40
+ def change_field(id, options, field)
41
+ map = @principles.find(id)
42
+ target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
43
+ value = text(options[field], "--#{field}")
44
+ write_map(map.saying(target, field, value)) do |printed|
45
+ map_result.entry_changed(printed, member: target, field: field, value: value)
46
+ end
47
+ end
48
+
49
+ # Names the command that enforces a member, which the audit asks the agent to run.
50
+ #: (String, Hash[String, untyped]) -> untyped
51
+ def change_member_check(id, options)
52
+ map = @principles.find(id)
53
+ target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
54
+ check = text(options["check"], "--check")
55
+ changed = map.changing_check(target, check)
56
+ hidden = Models::Member.new(changed.member(target)).check_hidden_characters
57
+ write_map(changed) { |printed| map_result.check_changed(printed, member: target, hidden: hidden) }
58
+ end
59
+
60
+ #: (String, Hash[String, untyped]) -> untyped
61
+ def remove_member_check(id, options)
62
+ map = @principles.find(id)
63
+ target = Models::Member.new(map.member(text(options["member"], "MEMBER"))).id
64
+ write_map(map.removing_check(target)) do |printed|
65
+ map_result.member_replaced(printed, done: "Removed the check of #{target}; the audit no longer asks for " \
66
+ "its result.")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -81,7 +81,7 @@ module Principles
81
81
  never_assessed: problems.never_assessed, names_a_command:)
82
82
  return view.at_session_start(lines, changed: problems.assessed_changes) if session_start
83
83
 
84
- view.saying_nothing_changed(lines, members: report.fetch("counts").values.sum)
84
+ view.saying_nothing_changed(view.explaining_rows(lines, report), members: report.fetch("counts").values.sum)
85
85
  end
86
86
 
87
87
  # list-member-problems' JSON result for map id, or every map, without the files it wrote.
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative "command"
5
5
  require_relative "../models/members_in_logged_requests"
6
+ require_relative "../models/request_kind"
6
7
  require_relative "../views/members_in_logged_requests_result"
7
8
 
8
9
  module Principles
@@ -22,7 +23,9 @@ module Principles
22
23
  @tool.feature(command).refuse_while_off
23
24
  view = Views::MembersInLoggedRequestsResult.new
24
25
  report = report_for(options)
25
- options["short"] ? view.short(report) : view.result(report)
26
+ next view.short(report) if options["short"]
27
+
28
+ view.result(report, side_call_sources: Models::RequestKind::SIDE_CALL_SOURCES)
26
29
  end
27
30
  end
28
31
 
@@ -30,10 +33,7 @@ module Principles
30
33
 
31
34
  # The scan's report in the form options ask for: every place each member --member names was seen, or each
32
35
  # member's, or each member's reach.
33
- #: (Hash[String, untyped])
34
- #| -> { members_by_status: Hash[String, Integer], members: Array[Hash[String, untyped]], orphans: Integer,
35
- #| quoting_requests: Array[String], unreadable: Array[Hash[String, String]],
36
- #| completeness: Hash[String, untyped] }
36
+ #: (Hash[String, untyped]) -> Models::RequestLogging::report
37
37
  def report_for(options)
38
38
  named = options["member"]
39
39
  return logging.members_seen(mapped.only(named)) if named
@@ -54,7 +54,10 @@ module Principles
54
54
  map = audit.map
55
55
  carried = carried_assessments(audit)
56
56
  elsewhere = elsewhere(map, current)
57
- members = map.members_shown.map { |fields| member_listed(fields, carried, elsewhere, current) }
57
+ kinds = member_loads(map).transform_values { it.carrier_kind.name }
58
+ members = map.members_shown.map do |fields|
59
+ justified(fields, kinds).merge(member_listed(fields, carried, elsewhere, current))
60
+ end
58
61
  Listing.new(members: members, open_findings_elsewhere: elsewhere_listed(elsewhere, current))
59
62
  end
60
63
 
@@ -72,6 +75,13 @@ module Principles
72
75
  changed_since(fields, judged, current), shared_lines(member, elsewhere))
73
76
  end
74
77
 
78
+ # What a member's entry says justifies it, led by its name, which output shows first, and its reason, null
79
+ # when it has none, for the audit to ask for, beside the kind of carrier its file is, the fact it is judged on.
80
+ #: (Hash[String, untyped], Hash[String, String]) -> Hash[String, untyped]
81
+ def justified(fields, kinds)
82
+ { **fields.slice("name"), "reason" => fields["reason"], "carrier" => kinds.fetch(fields.fetch("id")) }
83
+ end
84
+
75
85
  # Each finding elsewhere names, once, with each evidence item's lines beside this audit's members, where current
76
86
  # locates them; the project locates each item now.
77
87
  #: (Models::OpenFindingsElsewhere, Models::MemberSnapshots) -> Array[Hash[String, untyped]]
@@ -58,10 +58,18 @@ module Principles
58
58
  runs_from = @tool.runs_from
59
59
  Views::MetaPrincipleResult::Placement.new(
60
60
  runs_from: runs_from.to_s, session_start_hook_in_this_session: runs_from.session_start_hook_in_this_session?,
61
- entry_files: @project.entry_files.to_a, passage: passage(view)
61
+ entry_files: @project.entry_files.to_a, passage: passage(view),
62
+ enabled_in_project_settings: enabling_line
62
63
  )
63
64
  end
64
65
 
66
+ # The project settings line enabling the plugin, by its path and literal opening, or nil.
67
+ #: () -> Hash[String, String]?
68
+ def enabling_line
69
+ line = @project.harness.plugin_enabled_in_project_settings or return nil
70
+ { "path" => line.path, "starting_at" => line.starting_at }
71
+ end
72
+
65
73
  # The view of show-meta-principle-passage's result, with how its printed commands map the passage.
66
74
  #: () -> Views::MetaPrincipleResult
67
75
  def meta_principle_result
@@ -69,7 +77,7 @@ module Principles
69
77
  end
70
78
 
71
79
  # The passage member's heading and role, the role of a passage the project has that carries one of its steps,
72
- # and the role of any other place that keeps the principles held.
80
+ # and the role of any other place that has the principles checked.
73
81
  #: () -> Views::MetaPrincipleResult::PassageMapping
74
82
  def passage_mapping
75
83
  Views::MetaPrincipleResult::PassageMapping.new(heading: Models::MetaPrinciple::PASSAGE_HEADING,
@@ -5,6 +5,7 @@ require_relative "command"
5
5
  require_relative "../models/evidence_lines_since"
6
6
  require_relative "../models/feature"
7
7
  require_relative "../models/members_in_logged_requests"
8
+ require_relative "../models/turn_position"
8
9
  require_relative "../models/loading_decision"
9
10
  require_relative "../models/other_principles"
10
11
  require_relative "../models/prior_decision_fields"
@@ -133,7 +134,7 @@ module Principles
133
134
  # where a member's part asks, its text now.
134
135
  #: (Models::Principle) -> Array[String]
135
136
  def package_parts_mapped(map)
136
- hooks = @project.hook_commands(Models::HookCommands::ON_EVERY_HOST)
137
+ hooks = @project.harness.hook_commands(Models::HookCommands::ON_EVERY_HOST)
137
138
  map.members.package_parts(hooks) { |member| @project.member_text(member.locator) }
138
139
  end
139
140
 
@@ -11,13 +11,13 @@ module Principles
11
11
  # add-member --plugin: a member read from a plugin Claude Code installed, which the project maps but never edits.
12
12
  class PluginMemberAddition < Command
13
13
  # Maps the file options name in an installed plugin whole, pinning the version installed and the hash of its
14
- # text, in principle id's map, which it starts when there is none.
15
- #: (String, Hash[String, untyped]) -> untyped
16
- def add(id, options)
14
+ # text, in principle id's map, which it starts when there is none, playing the part played gives.
15
+ #: (String, Hash[String, untyped], Hash[String, untyped]) -> untyped
16
+ def add(id, options, played)
17
17
  refuse_location(options)
18
18
  found = installed(options)
19
19
  started = !@principles.mapped?(id)
20
- write_map(@principles.addable(id).adding(found.member(text(options["role"], "--role")))) do |printed|
20
+ write_map(@principles.addable(id).adding(found.member(played))) do |printed|
21
21
  added = map_result.plugin_member_added(printed, added: found.added)
22
22
  started ? added.merge(map_result.map_created(printed)) : added
23
23
  end